安裝node.js
推薦使用Homebrew
安裝node.js:
brew install node
筆者這里使用官網(wǎng)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
問題排查
筆者因為第一次安裝的時候出現(xiàn)問題缓呛,問題報錯整理如下:
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
目錄的創(chuàng)建者是root
,故沒有權(quán)限操作,安裝失敗,刪除當(dāng)前@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
最終安裝成功