npm install时报sudo chown -R 501:20,如何解决?

在安装Angular4时遇到权限错误,提示cachefolder包含root-owned文件。尝试用sudochown命令修复未成功,但通过在安装命令前添加sudo以管理员权限运行,成功解决了问题并能创建新的Angular4项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在折腾Angular4,结果安装时报错,Angular官网链接
安装命令是

npm install -g @angular/cli

结果如下:

npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/Users/xxxxxx/.npm"

在这里插入图片描述
根据提示输入

sudo chown -R 501:20 "/Users/huxiaodan/.npm"

结果还是不行,于是尝试安装时就使用管理员权限,安装命令前加上sudo

sudo npm install -g @angular/cli

在这里插入图片描述
完美解决!
接下来就可以创建一个Angular4的项目啦!

ng new my-app
npm cache clean --force npm warn using --force Recommended protections disabled. npm error code EACCES npm error syscall rmdir npm error path /Users/lunattian/.npm/_cacache/content-v2 npm error errno -13 npm error npm error Your cache folder contains root-owned files, due to a bug in npm error previous versions of npm which has since been addressed. npm error npm error To permanently fix this problem, please run: npm error sudo chown -R 501:20 "/Users/lunattian/.npm" npm error A complete log of this run can be found in: /Users/lunattian/.npm/_logs/2025-05-28T02_25_59_865Z-debug-0.log lunattian@LUNATTIAN-MC0 ~ % sudo chown -R 501:20 "/Users/lunattian/.npm dquote> dquote> " Password: chown: /Users/lunattian/.npm : No such file or directory lunattian@LUNATTIAN-MC0 ~ % rm -rf node_modules package-lock.json lunattian@LUNATTIAN-MC0 ~ % npm install npm error code ENOENT npm error syscall open npm error path /Users/lunattian/package.json npm error errno -2 npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/Users/lunattian/package.json' npm error enoent This is related to npm not being able to find a file. npm error enoent npm error A complete log of this run can be found in: /Users/lunattian/.npm/_logs/2025-05-28T02_30_27_572Z-debug-0.log lunattian@LUNATTIAN-MC0 ~ % npm cache clean --force npm warn using --force Recommended protections disabled. npm error code EACCES npm error syscall rmdir npm error path /Users/lunattian/.npm/_cacache/content-v2 npm error errno -13 npm error npm error Your cache folder contains root-owned files, due to a bug in npm error previous versions of npm which has since been addressed. npm error npm error To permanently fix this problem, please run: npm error sudo chown -R 501:20 "/Users/lunattian/.npm" npm error A complete log of this run can be found in: /Users/lunattian/.npm/_logs/2025-05-28T02_32_25_315Z-debug-0.log lunattian@LUNATTIAN-MC0 ~ % sudo chown -R 501:20 "/Users/lunattian/.npm" lunattian@LUNATTIAN-MC0 ~ % rm -rf node_modules package-lock.json lunattian@LUNATTIAN-MC0 ~ % sudo npm install npm error code ENOENT npm error syscall open npm error path /Users/lunattian/package.json npm error errno -2 npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/Users/lunattian/package.json' npm error enoent This is related to npm not being able to find a file. npm error enoent npm error A complete log of this run can be found in: /Users/lunattian/.npm/_logs/2025-05-28T02_33_10_247Z-debug-0.log lunattian@LUNATTIAN-MC0 ~ %
最新发布
05-29
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大小小丹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值