node.js - NPM 安装错误
问题描述
我正在尝试创建一个新项目并想在我的项目目录中安装 NPM,但它显示了这些错误。我目前拥有 NPM 和 Node.js 的最新版本。
Naomis-Air:~ naomivictoriaobame$ npm -v
7.24.0
Naomis-Air:~ naomivictoriaobame$ npm install npm@latest -g
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/npm',
npm ERR! dest: '/usr/local/lib/node_modules/.npm-i9nnxROI'
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! /Users/naomivictoriaobame/.npm/_logs/2021-10-16T20_55_50_627Z-debug.log
Naomis-Air:~ naomivictoriaobame$ npm cache clean --force
npm WARN using --force Recommended protections disabled.
Naomis-Air:~ naomivictoriaobame$
解决方案
必须进行配置npm
,问题就会消失。
例如:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo export PATH=~/.npm-global/bin:$PATH >> ~/.profile
source ~/.profile
npm install -g @forge/cli
文档。_
它还需要指向node
和的符号链接npm
:
ln -s /usr/local/bin/node /usr/bin/node
ln -s /usr/local/lib/node /usr/lib/node
ln -s /usr/local/bin/npm /usr/bin/npm
ln -s /usr/local/bin/node-waf /usr/bin/node-waf
推荐阅读
- javascript - 如何使用 FANCYBOX 对多个画廊上的图像进行分组?
- python - 在 python 中使用自定义字段名称进行 json 编码
- javascript - 使用单选按钮显示/隐藏表单元素
- powershell - 具有 SamAccountName 值的 PowerShell Get-ACL
- django - Django 错误:/admin/auth/user/1/change/ 处的 OperationalError
- vert.x - Webjars 不适用于 vert.x 应用程序
- java - FreeMarker:需要一个哈希,但这已经评估为一个序列
- javascript - 在 JS 完成执行之前防止 Jasmine 测试 expect() 解析
- ios - 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“FCM 错误:将来不能有最后一次签入时间戳”
- python - 将槽对象复制到非槽中