Manage multiple versions of Node.js.
Posted
Updated
Europe’s developer-focused job platform
Let companies apply to you
Developer-focused, salary and tech stack upfront.
Just one profile, no job applications!
This article is based on Node v16.14.0.
Using the Node.js Version manager (nvm) makes installing and managing multiple versions of Node.js on a single local environment easy.
I can only recommend using nvm
, even if you only need one single version of Node.js, there is a high chance it won't stay like this and switching between different versions is easy.
💰 The Pragmatic Programmer: journey to mastery. 💰 One of the best books in software development, sold over 200,000 times.
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. It is the preferred way to manage Node.js locally. In a production environment use the operating system package manager, or a server tooling to install and lock your specific version of Node.js.
nvm
works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
To install or update nvm, run the install script. You can also download it and then run it, but cUrl
or Wget
with bash
pipe are very convenient commands.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Running either of the above commands downloads a script and runs it.
This script clones the nvm repository into ~/.nvm
and updates your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to source the nvm.sh it contains.
After this restart your terminal or manually source your ~/.profile, like source ~/.bash_profile
.
Then verify that it worked, with the command:
command -v nvm
The command should return nvm
. Normally we could use which
, but nvm
is a shell script and not an application.
Some common trouble shooting tips can be found in the official documentation of nvm.
After successful installation, we can type in nvm
to get a list of available commands. We start with installing the latest LTS version of Node.js.
nvm install --lts
The output should look similar like this:
The last line says now using node v14.7.0
, which means that nvm is set to use Node.js version 14.7.0. We can verify by typing node --version
.
If you want to install a different Node.js version, just use nvm ls-remote
to list all versions and install it nvm install <VERSION>
, nvm use <VERSION>
. Verify with node -v
.
nvm install <VERSION>
nvm use <VERSION>
Thanks for reading and if you have any questions, use the comment function or send me a message @mariokandut.
If you want to know more about Node, have a look at these Node Tutorials.
Never miss an article.