node.js安装后修改npm全局目录;关于node_global文件的修改
程序员文章站
2022-05-29 16:04:15
...
(1)
在nodejs文件下建立node_global和node_cache文件
(2)
npm root -g 查看npm安装的全局目录在里面
C:\Users\qinqinqin\AppData\Roaming\npm\node_modules
(3)
npm config set prefix "C:\Program Files\nodejs\node_global"
npm config set cache "C:\Program Files\nodejs\node_cache"
(4)
系统环境变量:
Path:%NODE_PATH%;C:\Program Files\nodejs\node_global;
NODE_PATH:C:\Program Files\nodejs\node_global
(5)
用户变量:
将C:\Users\qinqinqin\AppData\Roaming\npm(先查看自己的npm全局位置在哪)修改为
C:\Program Files\nodejs\node_global
(6)
关于修改全局环境之后的后遗症:
下载express依赖包失败
C:\Users\qinqinqin>npm install express -g
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_cache\_cacache
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_cacache'
npm ERR! [OperationalError: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_cacache'] {
npm ERR! cause: [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_cacache'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! stack: "Error: EPERM: operation not permitted, mkdir 'C:\\Program Files\\nodejs\\node_cache\\_cacache'",
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
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.
(7)
解决方案:win+x+a管理员模式下运行
尽量不要删除用户文件下的.npmrc文件,否则配置好的全局环境变量会修改回去
上一篇: 判断一个字符串中是否含有某个字符