使用 nvm 安裝 node.js
NVM - Node Version Manager,是一個非常好用的 Node.js 版本管理工具。我們也可以使用 nvm 來下載 Node.js。nvm 的下載和常用命令如下:
安裝 nvm
使用 curl 工具進行安裝:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
或者使用 wget 工具進行安裝:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
示例(使用 wget 工具):
tony@ubuntu:~$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
=> Downloading nvm as script to '/home/tony/.nvm'
=> Appending nvm source string to /home/tony/.bashrc
=> Appending bash_completion source string to /home/tony/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
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
檢查 nvm 是否安裝成功
使用 command -v nvm
命令來檢查 nvm 是否安裝成功。
示例:
# 安裝成功會顯示 nvm,如果不顯示可以先注銷當前用戶再嘗試
tony@ubuntu:~$ command -v nvm
nvm
常用命令
下載,編譯並安裝最新版的 Node.js:
nvm install node
安裝指定版本的 Node.js:
# 10.15.3 即為指定的安裝版本
nvm install 10.15.3
查看可安裝的 Node.js 版本:
nvm ls-remote
查看本地上已安裝的 Node.js 版本:
nvm ls
卸載指定版本的 Node.js:
nvm uninstall 10.15.3