在 Linux 系统中,可以使用多种工具来管理 Node.js 的不同版本。以下是一些流行的 Node.js 版本管理工具及其使用方法:
简介: nvm 是最常用的 Node.js 版本管理工具,适用于 macOS、Linux 和 Windows(通过 nvm-windows 分支)。它提供了一套完整的命令行工具来安装、切换和管理多个 Node.js 版本。
安装步骤:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
或者wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm --version
常用命令:
nvm list available
nvm install <version>
nvm use <version>
nvm alias default <version>
nvm uninstall <version>
nvm current
简介: n 是一个专注于提供快速、简洁体验的 Node.js 版本管理工具,没有子shell、配置文件或复杂的 API。
安装步骤:
npm install -g n
n --version
常用命令:
n ls
n <version> 或 n latest
n use <version> 或 n latest
n current
简介: nodenv 是一个类似于 Ruby 的 rbenv 的 Node.js 版本管理工具,通过修改 PATH 环境变量来切换 Node.js 版本。
安装步骤:
git clone https://github.com/nodenv/nodenv.git ~/.nodenv
echo 'export PATH="$HOME/.nodenv/bin:$PATH"' >> ~/.bash_profile
exec $SHELL
git clone https://github.com/nodenv/node-build.git $(nodenv root)/plugins/node-build
常用命令:
nodenv install <version>
nodenv global <version> 或 nodenv local <version>
nodenv versions
简介: asdf 是一个插件扩展的 Node.js 版本管理工具,支持全语言版本管理。
安装步骤:
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/asdf-vm/asdf/master/install.sh | bash
~/.bashrc
或 ~/.zshrc
):. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
source ~/.bashrc
常用命令:
asdf install nodejs <version>
asdf local nodejs <version>
asdf list nodejs
通过这些工具,你可以在 Linux 系统上轻松管理 Node.js 的不同版本,以满足不同项目的需求。