Angular.js专场macOS前端开发笔记

macOS安装Angular及安装失败问题排查

2019-02-26  本文已影响2人  KidneyBro

安装node.js

推荐使用Homebrew安装node.js:
brew install node

笔者这里使用官网pkg安装出了点问题,卸载时就很麻烦了,卸载pkg安装的node.js参考链接:
How to Uninstall Node.js from Mac OSX

完成安装之后检查是否成功安装:

kidneybro@macbookPro:~$ node -v
v11.10.0
kidneybro@macbookPro:~$ npm -v
6.7.0
kidneybro@macbookPro:~$ which npm
/usr/local/bin/npm
kidneybro@macbookPro:~$ which node
/usr/local/bin/node

安装angular

使用cli命令安装:
npm install -g @angular/cli

问题排查

笔者因为第一次安装的时候出现问题,问题报错整理如下:

kidneybro@macbookPro:~$ npm install -g @angular/cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/@angular/cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/@angular/cli/node_modules
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/@angular
npm ERR! path /usr/local/lib/node_modules/@angular/cli
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli']
npm ERR!   stack:
npm ERR!    "Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules/@angular/cli' }
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/xuhaoshen/.npm/_logs/2019-02-26T02_28_55_578Z-debug.log

定位问题:
cd进入目录/usr/local/lib/node_modules/

kidneybro@macbookPro:~$ ll /usr/local/lib/node_modules
total 0
drwxr-xr-x   4 xuhaoshen  admin  128  2 25 22:16 .
drwxr-xr-x  26 xuhaoshen  admin  832  2 25 22:15 ..
drwxr-xr-x   3 root       admin   96  2 25 22:16 @angular
drwxr-xr-x  25 xuhaoshen  admin  800  2 25 22:13 npm

@angular目录的创建者是root,故没有权限操作,安装失败,删除当前@angular目录即可,之后重新运行安装指令有

kidneybro@macbookPro:~$ npm install -g @angular/cli
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng

> fsevents@1.2.7 install /usr/local/lib/node_modules/@angular/cli/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download
[fsevents] Success: "/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v67-darwin-x64/fse.node" is installed via remote
+ @angular/cli@7.3.3
added 363 packages from 196 contributors in 7.638s

最终安装成功

Angular使用Tutorial

Angualr QuickStart

上一篇 下一篇

猜你喜欢

热点阅读