Vue-Cli 不会安装

Vue-Cli won't install

我有节点 11.2.0

不断收到此错误。

Andrews-MacBook-Pro:vueTutorial aharris$ npm install -g @vue/cli
npm WARN deprecated hoek@5.0.4: This version is no longer maintained. Please upgrade to the latest version.
npm WARN deprecated cross-spawn-async@2.2.5: cross-spawn no longer requires a build toolchain, use it instead
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm WARN @apollographql/apollo-upload-server@5.0.3 requires a peer of graphql@^0.13.1 but none is installed. You must install peer dependencies yourself.

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/aharris/.npm/_logs/2018-11-25T18_43_42_502Z-debug.log

您遇到文件权限问题。

-g参数npm的意思是"globally",会把这些文件安装到系统目录下,特别是在你的电脑上/usr/local/lib/node_modules,其所有者可能是root and with permission rwxr-xr-x, 意味着那些不是 root 的人将没有写权限。

然后,你可以使用sudo来获得这个权限,或者像NPM modules won't install globally without sudo说的那样,将npm前缀设置到你有权限的路径中:

$ npm config set prefix '~/.npm-packages'

您需要做的就是运行相同的命令,前面加上 sudo,

sudo npm install -g @vue/cli

系统会提示您输入管理员密码。