首页 > 解决方案 > 如何在 AWS CloudShell 中安装 npm?

问题描述

我正在尝试在新的 AWS CloudShell 中安装一个 npm 包(带有预配置的 Node.js 支持) - 但我遇到了一个EACCESS错误。


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/cloudshell-user/.npm/_logs/2021-01-06T02_18_33_584Z-debug.log

在 AWS CloudShell 中安装 npm 包的最佳方法是什么?

标签: node.jsamazon-web-servicesnpmaws-cloudshell

解决方案


为了解决这个问题,我按照https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally上的说明进行操作:

第一的:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

在您首选的文本编辑器中,打开或创建一个 ~/.profile 文件并添加以下行

export PATH=~/.npm-global/bin:$PATH

然后:

source ~/.profile

推荐阅读