node.js - 如何在 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 包的最佳方法是什么?
解决方案
为了解决这个问题,我按照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
推荐阅读
- azure-devops - 如何在高度受限的 Azure DevOps Pipeline 环境中使用与驱动程序相关的 CLI 来创建驱动程序?
- azure-devops - Azure DevOps:审批者无法批准自己的 PR
- javascript - 检测来自 React 应用程序和 React 组件外部的 html 元素的点击
- git - Gitlab 显示 repo 已更新
- unit-testing - 单元测试以在响应数组中查找关键字
- bash - Kerberos klist 未显示票证
- java - 为什么我可以在没有设置 JAVA_HOME 的情况下使用 javac 和 java?
- asp.net-core - .net 5 响应返回文本和数字
- php - 在 PHP 中使用 CURL 发布 JSON 正文
- flutter - 使用图像的 Flutter 圆形进度指示器