安装node.js,npm和无服务器时出错

问题描述

我正在尝试使用发现于here的以下命令在笔记本电脑中安装node.jsnpm

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

这些安装Node.js LTS (v12.x)

此后,我尝试安装here,如图serverless

我愿意:

npm install -g serverless

它会引发以下错误

cortex@cortex-Lenovo-ideapad-720S-15IKB:~$ npm install -g serverless
npm WARN deprecated @types/[email protected]: This is a stub types deFinition for chalk (https://github.com/chalk/chalk). chalk provides its own type deFinitions,so you don't need @types/chalk installed!
npm WARN deprecated [email protected]: request has been deprecated,see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: request-promise-native has been deprecated because it extends the Now deprecated request package,see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/serverless/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied,access '/usr/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied,access '/usr/lib/node_modules'] {
npm ERR!   errno: -13,npm ERR!   code: 'EACCES',npm ERR!   syscall: 'access',npm ERR!   path: '/usr/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue,please double-check the
npm ERR! permissions of the file and its containing directories,or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/cortex/.npm/_logs/2020-08-19T14_04_41_850Z-debug.log

我是node.js的新手,所以有人可以帮我吗?

PS:

node -v

输出为v12.18.3

npm -v

输出为6.14.6

解决方法

在安装全局软件包时使用sudo。

sudo npm install -g serverless