尝试安装vue / cli时权限被拒绝

时间:2019-10-07 12:50:54

标签: javascript macos vue.js

我正在尝试在项目中安装vue cli,但出现错误, 我是MacOs的新用户。 希望您能帮助我修复它并在我的项目中安装vue cli。

Circus-MBP:TodoApp circus4$ npm i  @vue/cli -g

npm ERR! path ../lib/node_modules/@vue/cli/bin/vue.js
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'
npm ERR!  { [Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'symlink',
npm ERR!      path: '../lib/node_modules/@vue/cli/bin/vue.js',
npm ERR!      dest: '/usr/local/bin/vue' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, symlink \'../lib/node_modules/@vue/cli/bin/vue.js\' -> \'/usr/local/bin/vue\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/@vue/cli/bin/vue.js',
npm ERR!   dest: '/usr/local/bin/vue' }
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/Circus4/.npm/_logs/2019-10-07T12_38_25_842Z-debug.log

5 个答案:

答案 0 :(得分:6)

您似乎没有全局安装所需的特权。您可以尝试使用sudo进行安装,也可以(建议)将NPM的默认目录移动到您具有以下读取/写入权限的目录:

  1. 在主目录中创建目录,例如~/.npm-global

  2. 运行npm config set prefix '~/.npm-global'

  3. 更新您的PATHexport PATH=~/.npm-global/bin:$PATH

https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

请注意,尽管您可能只使用sudo,但强烈建议不要这样做。甚至在您发布的错误输出中也是如此:

  

npm错误!文件及其包含目录的权限,或尝试运行

     

npm错误!再次以root /管理员身份执行命令(尽管不建议这样做)。

答案 1 :(得分:0)

试试看:


以管理员身份登录

sudo su

然后运行

yarn global add @vue/cli

答案 2 :(得分:0)

另一个选项是通过运行以下命令向您的用户授予允许在 /usr/local 上进行全局安装的权限:

sudo chown -R $(whoami) /usr/local/lib /usr/local/bin

答案 3 :(得分:-1)

您没有足够的权限。尝试使用sudo

sudo npm i -g @vue/cli

答案 4 :(得分:-1)

您需要通过在命令的第一行写sudo来获得许可

sudo npm i  @vue/cli -g