背景
新公司换了Mac,准备配置一下前端开发环境,vue-cli@3.0发布了,一套行云流水的操作 npm install -g @vue/cli
却时提示:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
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:
npm ERR! '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 (though this is not recommended).
一眼就看到了是权限问题,不能写入,为什么呢,windows上没有这种问题呀。
drwxr-xr-x 3 root wheel 96 8 20 18:27 node_modules
drwxr-xr-x 7 rainbow admin 224 8 9 19:07 pkgconfig
➜ lib pwd
/usr/local/lib
➜ lib
看了一眼是/usr/local/lib/node_module
是root权限啊,就Google了一下,发现是OSX开启了System Intergerity Protection
(系统完整性保护)简称SIP,大概就是禁止了一系列的系统安全权限,其中包括不能向/usr/local/lib/node_module
写入文件。 怎么办?当然是禁用它啊。
禁用SIP方法
- 重启系统,按住 Command + R 进入恢复模式
- 点击顶部菜单栏 实用工具 中的 终端
csrutil disable
- 输出
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
代表成功 - 重启系统
-
csrutil enable
(开启该权限的命令)
其他解决方法
常用:修改安装目录的权限 sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
或者命令前面加sudo
。
之后就可以流畅的npm install了。