mac安装npm|mac安装npm install -g @vue/cli报错解决

下午在mac上安装Vue Cli官网给的命令npm install -g @vue/cli时报错,如下:

yanxudeMacBook-Pro:vue3 dove$ npm install -g @vue/cli npm WARN deprecated fsevents@1.2.9: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size 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).npm ERR! A complete log of this run can be found in: npm ERR!/Users/dove/.npm/_logs/2019-11-14T07_30_27_188Z-debug.log

网上搜的用sudo chown -R $USER /usr/local解决,但是出现下面的报错:
chown: /usr/local: Operation not permitted

查了下原因是因为这种方法对于高版本的OS来说,是解决不了的,在评论中发现大佬回复解决问题,解决代码如下:
sudo chown -R $(whoami) /usr/local/*


【mac安装npm|mac安装npm install -g @vue/cli报错解决】
附大佬截图 mac安装npm|mac安装npm install -g @vue/cli报错解决
文章图片
image.png

    推荐阅读