簡單說明
NVM
全稱為Node Version Manager
铆遭,是一個存放在github上的工具缘缚,用于管理Node.js
版本煤痕,如果要使用Node.js
則建議先安裝NVM虽惭。在github上有對nvm
詳細的描述橡类。github地址:https://github.com/creationix/nvm。
安裝NVM(依賴GIT芽唇,請確保已安裝GIT)
一顾画、運行命令
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
或者
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
建議使用curl
的方式取劫,安裝后將創(chuàng)建目錄~/.nvm
并將內(nèi)容存放在這里。
命令執(zhí)行時注意查看日志研侣,如下圖說明缺少環(huán)境變量配置
- 第一處提示在
~/.bashrc
,~/.bash_profile
,~/.zshrc
,~/.profile
都沒有找到所需要的配置信息谱邪。 - 第二處提示我們可以將
export NVM_DIR...
這兩句句命令添加到恰當(dāng)?shù)奈募校簿褪巧厦媪谐龅乃膫€文件中的一個庶诡。 - 第三處的意思就是如果現(xiàn)在需要使用nvm惦银,可以直接執(zhí)行如下命令,然后就可以使用nvm了(這種方式在重新啟動Terminal以后無法繼續(xù)使用nvm)末誓。
為了方便扯俱,我把這幾句命令提取出來如下:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
二、經(jīng)過第一步的分析喇澡,需要將以上代碼添加至~/.bash_profile
或者~/.profile
文件中
為了能夠在重啟(在Mac上則為重啟Terminal)以后還能繼續(xù)使用NVM蘸吓,我們可以把這段配置信息添加到~/.bash_profile
或者~/.profile
文件中,經(jīng)過實踐測試添加到~/.bashrc
或~/.zshrc
文件中均無法在重啟Terminal后使用NVM
撩幽。
具體操作如下:
$ cd ~
$ vim .bash_profile
## 將export NVM_DIR ... 粘貼到文件中
## ESC -> 鍵入":" -> 鍵入"wq" -> 回車保存
## 讓配置文件里面生效
$ source .bash_profile
完成后運行nvm測試库继,如輸出如下說明已安裝成功
$ nvm
Node Version Manager
Note: <version> refers to any version-like string nvm understands. This includes:
- full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
- default (built-in) aliases: node, stable, unstable, iojs, system
- custom aliases you define with `nvm alias foo`
Any options that produce colorized output should respect the `--no-colors` option.
Usage:
nvm --help Show this message
nvm --version Print out the latest released version of nvm
nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available
--reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>
--lts When installing, only select from LTS (long-term support) versions
--lts=<LTS name> When installing, only select from versions for a specific LTS line
nvm uninstall <version> Uninstall a version
nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.
nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
--lts=<LTS name> Uses automatic alias for provided LTS line, if available.
nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
--lts=<LTS name> Uses automatic alias for provided LTS line, if available.
nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
--lts=<LTS name> Uses automatic alias for provided LTS line, if available.
nvm current Display currently activated version
nvm ls List installed versions
nvm ls <version> List versions matching a given <version>
nvm ls-remote List remote versions available for install
--lts When listing, only show LTS (long-term support) versions
nvm ls-remote <version> List remote versions available for install, matching a given <version>
--lts When listing, only show LTS (long-term support) versions
--lts=<LTS name> When listing, only show versions for a specific LTS line
nvm version <version> Resolve the given description to a single local version
nvm version-remote <version> Resolve the given description to a single remote version
--lts When listing, only select from LTS (long-term support) versions
--lts=<LTS name> When listing, only select from versions for a specific LTS line
nvm deactivate Undo effects of `nvm` on current shell
nvm alias [<pattern>] Show all aliases beginning with <pattern>
nvm alias <name> <version> Set an alias named <name> pointing to <version>
nvm unalias <name> Deletes the alias named <name>
nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version
nvm unload Unload `nvm` from shell
nvm which [<version>] Display path to installed node version. Uses .nvmrc if available
nvm cache dir Display path to the cache directory for nvm
nvm cache clear Empty cache directory for nvm
Example:
nvm install v0.10.32 Install a specific version number
nvm use 0.10 Use the latest available 0.10.x release
nvm run 0.10.32 app.js Run app.js using node v0.10.32
nvm exec 0.10.32 node app.js Run `node app.js` with the PATH pointing to node v0.10.32
nvm alias default 0.10.32 Set default node version on a shell
Note:
to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
卸載NVM
執(zhí)行下面的命令移除nvm
內(nèi)容
cd ~
rm -rf .nvm
移除掉~/.profile
, ~/.bash_profile
, ~/.zshrc
, ~/.bashrc
文件中關(guān)于nvm
的配置