使用 nvm 可以方便的進行 nodejs 的安裝和版本管理。
其實最開始使用的是 n 命令,命令簡潔到極致了,無奈總是安裝不成功,往往下載一部分就報 curl 錯誤。
然后又找到這個 nvm,配合淘寶源,簡單快捷~
1.到 nvm github(https://github.com/creationix/nvm)查看 nvm 安裝命令,例如:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
2.以上命令執行后通常需要重新開啟終端,然后查看nodejs最新版本
nvm ls-remote...v8.8.0v8.8.1v8.9.0 (LTS: Carbon)v8.9.1 (LTS: Carbon)v8.9.2 (LTS: Carbon)v8.9.3 (LTS: Carbon)v8.9.4 (Latest LTS: Carbon)v9.0.0v9.1.0v9.2.0v9.2.1v9.3.0v9.4.0
3.然后使用淘寶源進行安裝(如安裝最新LTS版本)
NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/dist
nvm install v8.9.4
4.為 npm 配置淘寶源,編輯 ~/.npmrc
文件
# 注冊模塊鏡像
registry=https://registry.npm.taobao.org# node-gyp 編譯依賴的 node 源碼鏡像
disturl=https://npm.taobao.org/dist# chromedriver 二進制包鏡像
chromedriver_cdnurl=https://cdn.npm.taobao.org/dist/chromedriver# operadriver 二進制包鏡像
operadriver_cdnurl=https://cdn.npm.taobao.org/dist/operadriver# phantomjs 二進制包鏡像
phantomjs_cdnurl=https://cdn.npm.taobao.org/dist/phantomjs# node-sass 二進制包鏡像
sass_binary_site=https://cdn.npm.taobao.org/dist/node-sass# electron 二進制包鏡像
electron_mirror=https://cdn.npm.taobao.org/dist/electron
轉載于:https://blog.51cto.com/liukang/2066571