In the previous article "What are the differences between various versions of Node.js?" How to choose the right version? "Introduced in "Node.js version is 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 perform version management on the Node.js version.
For example, Node.js 8.0.0 and Node.js 17.0.0 need to be installed locally.
In order to be able to version manage Node.js versions, I have compiled 3 very practical Node.js version management tools, allowing everyone to freely switch between different Node.js versions in the local environment.
⭐ 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.
Picture from: github
nvm is only suitable for projects for macOS and Linux users. If you are a Windows user, you can use nvm-windows, nodist or nvs instead.
macOS Download method:
# Method 1 Open the following link in the browser to download https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh # After the download is complete, install it through the command sh install.sh # Method 2 recommends curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash # Method 3 wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh |
If you encounter some strange problems during the bash installation process, you can check the nvm supplementary instructions.
nvm ls # View the version and install all versions nvm ls-remote # View all remote Node.js versions nvm install 17.0.0 # Install the specified Node.js version nvm use 17.0.0 # Use the specified Node.js version nvm alias default 17.0.0 # Set the default Node.js version nvm alias dev 17.0.0 # Set the alias of the specified version, such as setting the 17.0.0 version alias to dev
⭐ Github stars: 16.7K+
n is an interactive Node.js version management tool. It has no subscripts, no configuration files, and no complex API. It is very simple to use.
n Only available on macOS and Linux, not Windows.
can be directly installed globally using npm:
npm install n -gCommon
n # Display all downloaded versions n 10.16.0 # Download the specified version n lts # View all remote LTS Node.js versions n run 10.16.0 # Run For the specified Node.js version,
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
⭐ Github stars: 8.4K+
fnm is a fast and simple Node.js version manager built with Rust.
Picture from: freecodecamp
Main features include:
.node-version
and .nvmrc
files;macOS/Linux environment:
# bash, zsh and fish shells curl -fsSL https://fnm.vercel.app/install | bash
Windows environment:
# Open the terminal in administrator mode. After installation, it can only be opened in administrator mode. Use choco install fnm # After the installation is completed, you need to manually set the environment variables.
In Linux/macOS/Windows environment, you can also directly download the binary file for installation. Download address: github.com/Schniz/fnm/…
fnm -h # View help fnm install 17.0.0 # Installation Specify the Node.js version fnm use 17.0.0 # Use the specified Node.js version fnm default 17.0.0 # Set the default Node.js version
This article recommends 3 very commonly used Node.js version management tools. You can follow Choose to use according to your actual needs.
If you have better tools, please leave a message to share.