mac下nodejs 更新到最新版本的最新方法
前提條件
* mac上安裝了npm
第一步:使用npm安裝n模塊
n模塊是專門用來管理nodejs版本的
sudo npm install -g n
提示 : 如果不使用sudo作爲前綴,很可能出現權限訪問異常導致安裝失敗
第二步:升級nodejs
升級nodejs是有兩種方法:
第一種是升級到最新版本
sudo n latest
第二種是升級到穩定版本
sudo n stable
提示 : 建議是穩定版本
更多n模塊管理請搜索【nodejs n模塊使用說明】
權限相關的異常:
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/Cellar/node/6.4.0/bin/node" "/usr/local/bin/npm" "update" "-g"
npm ERR! node v6.4.0
npm ERR! npm v4.1.2
npm ERR! path /usr/local/lib/node_modules/cnpm/node_modules/agentkeepalive
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/cnpm/node_modules/agentkeepalive'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/cnpm/node_modules/agentkeepalive'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/cnpm/node_modules/agentkeepalive' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/
admin/Projects/CoPilot/npm-debug.log
提示 : 解決方案是在命令前加sudo