[Node] nvm 安裝 node 和 npm
阿新 • • 發佈:2021-11-03
Node JS
安裝
-
安裝 node version manager (nvm)
-
配置 nvm 國內源
編輯 %APPDATA%/nvm/settings.txt
node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
- 安裝 node 和 npm
可以使用 command 或者 git-bash 執行。(注意: nvm use 命令必須要以管理員身份執行)
# 列出可安裝的 node 版本
nvm list available
獲取的結果:
| CURRENT | LTS | OLD STABLE | OLD UNSTABLE | |--------------|--------------|--------------|--------------| | 17.0.1 | 16.13.0 | 0.12.18 | 0.11.16 | | 17.0.0 | 14.18.1 | 0.12.17 | 0.11.15 | | 16.12.0 | 14.18.0 | 0.12.16 | 0.11.14 | | 16.11.1 | 14.17.6 | 0.12.15 | 0.11.13 | | 16.11.0 | 14.17.5 | 0.12.14 | 0.11.12 | | 16.10.0 | 14.17.4 | 0.12.13 | 0.11.11 | | 16.9.1 | 14.17.3 | 0.12.12 | 0.11.10 | | 16.9.0 | 14.17.2 | 0.12.11 | 0.11.9 | | 16.8.0 | 14.17.1 | 0.12.10 | 0.11.8 | | 16.7.0 | 14.17.0 | 0.12.9 | 0.11.7 | | 16.6.2 | 14.16.1 | 0.12.8 | 0.11.6 | | 16.6.1 | 14.16.0 | 0.12.7 | 0.11.5 | | 16.6.0 | 14.15.5 | 0.12.6 | 0.11.4 | | 16.5.0 | 14.15.4 | 0.12.5 | 0.11.3 | | 16.4.2 | 14.15.3 | 0.12.4 | 0.11.2 | | 16.4.1 | 14.15.2 | 0.12.3 | 0.11.1 | | 16.4.0 | 14.15.1 | 0.12.2 | 0.11.0 | | 16.3.0 | 14.15.0 | 0.12.1 | 0.9.12 | | 16.2.0 | 12.22.7 | 0.12.0 | 0.9.11 | | 16.1.0 | 12.22.6 | 0.10.48 | 0.9.10 | This is a partial list. For a complete list, visit https://nodejs.org/download/releases
# 安裝指定的版本,建議使用最新的LTS(長期服務)版本。
nvm install 16.13.0
# 列出安裝的版本
nvm list
# $ * 16.13.0 (Currently using 64-bit executable)
# 使用指定的版本(注意: nvm use 命令必須要以管理員身份執行)
nvm use 16.13.0
# $ Now using node v16.13.0 (64-bit)
配置國內源 Taobao Register
- 方法: nrm
npm install -g nrm
nrm ls
nrm use taobao
- 方法: change the registry
npm config get registry
npm config set registry https://registry.npm.taobao.org
# Test it
npm info underscore
# the original source
# npm config set registry https://registry.npmjs.org/
- 方法: specific the repository in command line
npm --registry https://registry.npm.taobao.org info underscore install xxx
- 方法: change
~/.npmrc
registry = https://registry.npm.taobao.org
- 方法: cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install [name]
常見問題
-
nvm install
失敗
解決方案: 使用國內源 -
nvm use
返回exit status 1: access denied
解決方案: 以管理員身份執行
請“推薦”本文!