头图

In the previous article " Mastering the Difference Between Node.js Versions in 3 Minutes ", it was introduced that Node.js versions are divided into LTS and Current series. When we need to install both the LTS version and the Current version in the local development environment, we need to install the Node.js version. .js version for version management.

For example, Node.js 8.0.0 and Node.js 17.0.0 need to be installed locally.

In order to manage the version of Node.js, I have compiled three very practical Node.js version management tools, so that everyone can freely switch between different Node.js versions in the local environment.

1. nvm

Github stars: 60K+

nvm is a Node.js version management tool that allows users to quickly install, switch and manage different Node.js versions through the command line.

(Image from: github )

nvm is only a project for macOS and Linux users, if you are a Windows user, you can use nvm-windows , nodist or nvs instead.

Installation method

macOS download method:

 # 方式1 浏览器打开下面链接下载
https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
# 下载完成后,通过命令安装
sh install.sh

# 方式2 推荐
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# 方式3
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

If you encounter some strange problems during the installation process, you can check the nvm supplementary instructions .

Common commands

 nvm ls                # 查看版本安装所有版本
nvm ls-remote         # 查看远程所有的 Node.js 版本
nvm install 17.0.0    # 安装指定的 Node.js 版本
nvm use 17.0.0        # 使用指定的 Node.js 版本
nvm alias default 17.0.0  # 设置默认 Node.js 版本
nvm alias dev 17.0.0  # 设置指定版本的别名,如将 17.0.0 版本别名设置为 dev

2. n

Github stars: 16.7K+

n is an interactive Node.js version management tool, with no subscripts, no configuration files, and no complex APIs. It is very simple to use.

n Applies only to macOS and Linux, not Windows.

Installation method

You can install directly to the global using npm:

 npm install n -g

Common commands

 n          # 显示所有已下载版本
n 10.16.0  # 下载指定版本
n lts      # 查看远程所有 LTS Node.js 版本
n run 10.16.0 # 运行指定的 Node.js 版本

Enter n -h to view the help information, the main commands are as follows:

 n                              Display downloaded Node.js versions and install selection
  n latest                       Install the latest Node.js release (downloading if necessary)
  n lts                          Install the latest LTS Node.js release (downloading if necessary)
  n <version>                    Install Node.js <version> (downloading if necessary)
  n install <version>            Install Node.js <version> (downloading if necessary)
  n run <version> [args ...]     Execute downloaded Node.js <version> with [args ...]
  n which <version>              Output path for downloaded node <version>
  n exec <vers> <cmd> [args...]  Execute command with modified PATH, so downloaded node <version> and npm first
  n rm <version ...>             Remove the given downloaded version(s)
  n prune                        Remove all downloaded versions except the installed version
  n --latest                     Output the latest Node.js version available
  n --lts                        Output the latest LTS Node.js version available
  n ls                           Output downloaded versions
  n ls-remote [version]          Output matching versions available for download
  n uninstall                    Remove the installed Node.js

3. fnm

Github stars: 8.4K+

fnm is a fast and simple 🚀 Node.js version manager built with Rust.

(Image from: freecodecamp )

Key features include:

  • 🌎 Cross-platform support, including: macOS, Windows, Linux;
  • ✨Single file, easy installation, instant start;
  • 🚀 Designed with speed in mind;
  • 📂 For .node-version and .nvmrc files;

Installation method

macOS / Linux environment:

 # bash, zsh and fish shells
curl -fsSL https://fnm.vercel.app/install | bash

Windows environment:

 # 管理员模式打开终端,安装后只能使用管理员模式打开使用

choco install fnm

# 安装完成还需要手动设置环境变量

Linux/macOS/Windows environments can also directly download binary files for installation, download address: https://github.com/Schniz/fnm/releases

Common commands

 fnm -h             # 查看帮助
fnm install 17.0.0 # 安装指定 Node.js 版本
fnm use 17.0.0     # 使用指定 Node.js 版本
fnm default 17.0.0 # 设置默认 Node.js 版本

Summarize

This article recommends 3 very commonly used Node.js version management tools for you, you can choose to use them according to your actual needs.

If you have a better tool, please leave a message to share 😄.

If this article helps you, please like and support it.


pingan8787
3.2k 声望4.1k 粉丝

🌼 前端宝藏小哥哥