nodejs相关
安装
在Mac上,默认全局包安装目录是/usr/local
,每次使用npm i -g
都需要sudo
,官网推荐的解决办法是更改全局目录位置,具体如下:
- 新建目录
mkdir ~/.npm-global
- 修改默认安装位置
npm config set prefix '~/.npm-global'
- 修改shell
export PATH=~/.npm-global/bin:$PATH
- 使shell修改生效
source ~/.profile
之后用npm进行全局安装仍然报权限问题,并且提示解决办法:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /Users/usr/.npm/_cacache/index-v5/ca/f8
npm ERR! errno EACCES
npm ERR!
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/usr/.npm”npm ERR! A complete log of this run can be found in: /Users/nascent/.npm/_logs/2023-08-28T05_18_11_009Z-debug-0.log
运行推荐的指令sudo chown -R 501:20 "/Users/usr/.npm"
,再用npm全局安装包,成功。
但使用cnpm全局安装包仍然失败,提示/Users/usr/.npminstall_tarball/manifests/
下面的某个json文件访问被拒绝。照葫芦画瓢,运行sudo chown -R 501:20 "/Users/usr/.npminstall_tarball/manifests/"
,重新尝试安装,成功。