javascript - ubunu 中的 Angular CLI 安装错误 - 当我尝试在我的 ubuntu 机器中运行 angular CLI 命令时出现错误

标签 javascript angular ubuntu npm-install ubuntu-18.04

这个错误我得到了。
我已经在我的系统中安装了 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用于安装东西。
你试过吗,manually change npm's default directory ?

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
要测试您的新配置,请在不使用 sudo 的情况下全局安装软件包:
npm install -g @angular/cli

关于javascript - ubunu 中的 Angular CLI 安装错误 - 当我尝试在我的 ubuntu 机器中运行 angular CLI 命令时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64668943/

相关文章:

javascript - 如何修复拖动时数据表中标题的设计

javascript - 从 event.target 获取子元素

python-3.x - 我想解决 ubuntu 服务器中的 django webserver collectstatic 错误

python - 在 Ubuntu 的外部驱动器上尝试 repo init 时出错

javascript - 在 Javascript 中,在删除文件之前提示是/否?

php - 检测当前页面的代码

javascript - 如何设置 cookie 并基于 cookie 是否存在跳过登录屏幕?

javascript - 为什么 Angular 2 需要 node.js

javascript - 使用 HTML 和 JS 的 iPhone 游戏中的性能问题,带有 appMobi

linux - aws cli、crontab 和用户权限之间的交互