MAC上安装angular时碰到的一些问题

想在mac上安装angular,中途碰到一些问题,现已解决。特此分享,供参考。

我一开始用如下命令直接安装:

npm install -g @angular/cli

安装过程中碰到如下的报错1:

xxxdeMBP:~ xxx$ npm install -g @angular/cli
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning undefined: network timeout at: https://registry.npmjs.org/@angular-devkit%2fcore
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
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!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yangmuxue/.npm/_logs/2020-05-15T14_23_03_431Z-debug.log

报错1的解决方法:
由于报错显示路径’/usr/local/lib/node_modules’存在权限问题,于是我用以下命令查看了这个文件的拥有者:

xxxxdeMBP:_logs xxxx$ ls -la /usr/local/lib/node_modules
total 0
drwxr-xr-x   3 root  wheel   96  5 15 22:18 .
drwxr-xr-x   5 root  wheel  160  5 15 22:18 ..
drwxr-xr-x  24 root  wheel  768  4 28 19:15 npm

这个文件的拥有者是root,所以我当前的身份不能进行修改。于是我修改了这些文件的拥有者。

sudo chown -R xxxx(新的拥有者): /usr/local/lib/node_modules

再次查看文件权限:

xxxxdeMBP:_logs xxxx$ ls -la /usr/local/lib/node_modules
total 0
drwxr-xr-x   3 xxxx  wheel   96  5 15 22:18 .
drwxr-xr-x   5 root       wheel  160  5 15 22:18 ..
drwxr-xr-x  24 xxxx  wheel  768  4 28 19:15 npm

虽然仍然有一个文件的拥有者是root,当我始终改不掉。于是尝试性地重新安装,可又遇到了报错2:

xxxxdeMBP:~ xxxx$ npm install -g @angular/cli
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/@angular/cli/bin/ng
npm ERR! dest /usr/local/bin/ng
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'symlink',
npm ERR!     path: '../lib/node_modules/@angular/cli/bin/ng',
npm ERR!     dest: '/usr/local/bin/ng'
npm ERR!   },
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/@angular/cli/bin/ng',
npm ERR!   dest: '/usr/local/bin/ng'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yangmuxue/.npm/_logs/2020-05-15T14_44_36_347Z-debug.log

报错2的解决方法:用如下命令重新安装:

sudo npm install -g @angular/cli

我的安装到此就成功了。以上分享供小伙伴们参考!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值