javascript - ubunu 中的 Angular CLI 安装错误 - 当我尝试在我的 ubuntu 机器中运行 angular CLI 命令时出现错误
问题描述
这个错误我得到了。我已经在我的系统中安装了 node js 和 npm。我也删除了 npm 缓存。
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
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/user/.npm/_logs/2020-11-03T18_21_04_293Z-debug.log
~~~
解决方案
不要sudo
用于这个问题。使用sudo
它打算在 Ubuntu 中使用的方式:对于每个需要它的命令,仅此而已。不要sudo
用于运行命令,除非它需要是 root 用户。例如,大多数用户只需要sudo
安装东西。
您是否尝试过手动更改 npm 的默认目录?
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
要测试您的新配置,请在不使用的情况下全局安装一个包sudo
:
npm install -g @angular/cli
推荐阅读
- firebase - 如何创建可以在读取数据库时触发的firebase云功能
- xamarin - MvvmCross CreateBindingSet 的预期用途
- html - CSS Card Flip 在 Apple 设备上不起作用
- go - runtime:unexpected return pc for runtime.gopark 调用 from0x0
- node.js - 无法使用颤振客户端连接到 localHost 上的 nodeJS socket.io 服务器
- python-2.7 - 如何平均来自文本文件的数据?
- swift - 如何仅在 ViewDidLoad 中的另一个方法完成后调用一个方法
- javascript - 具有解除状态和受控依赖关系的 React 表单提交逻辑
- selenium - 硒兼容性
- python - 乌龟:计时器一直在闪烁