As a developer make development environment like a pro, set up and use different versions of Node.js simultaneously on Windows, macOS and Linux (Ubuntu).
What is the need for multiple versions and why use a tool to install and set up?
As a developer, you might be working on and maintaining several frontend/server-side projects which require different Node.js runtime versions or build dependencies.
One way is to use
docker and have a complete development environment containerized, which comes with its advantages and disadvantages. Another way is to simply use a tool that can help you easily install and switch different versions of node.js.
How to do it?
There are several ways to install Node.js on your development machine. I am going to share the ways to set up the top 4 tools.
nvmis a (most famous) version manager for node.js, designed to be installed per user, and invoked per shell.
nvmworks on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
- To install the node version manager, use any of the below commands
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash # or wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
nvmis super easy, to install the latest/stable version of Node.js. You can find the current latest or stable version from here or simply use the below command.
nvm install --lts
- Using the installed Node.js for the current terminal session:
nvm use --lts
- Setting the latest installed node as the terminal/system default (assuming my default version is 18.14)
nvm alias default stable
Install on Windows is not easy as it is on linux. We need to use coreybutler/nvm-windows, which is not identical to
nvm-sh/nvmbut offers a similar
clifor Windows. Its requires
Administratoraccess for installation and some usage, but even Microsoft suggests to use the same.
To use just download the latest version exe from the releases.
Volta is a new universal node package manager built in Rust and comes with dependency free static binary.
- On most Unix systems including macOS, you can install Volta with a single command:
curl https://get.volta.sh | bash
voltais easy as
nvm. You can install the latest or LTS version of Node.js using the below commands:
# for LTS volta install node # for latest volta install node@latest # for any other version volta install email@example.com
- Similar to
nvmyou can pin
nodeversions by using the below commands:
volta pin firstname.lastname@example.org volta pin email@example.com # check using node --version # 18.14.0 yarn --version # 3.4.1
nis also one of the oldest version managers for node.js. It is written as a BASH script and is relatively simpler than other version managers.
- You can install
nby using the below commands:
# make a cache folder (if missing) and take ownership sudo mkdir -p /usr/local/n sudo chown -R $(whoami) /usr/local/n # make sure the required folders exist (safe to execute even if they already exist) sudo mkdir -p /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share # take ownership of Node.js install destination folders sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share # finally install using the below script curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s lts npm install -g n
For any references, check out the installation guide.
nis similar to other version managers, to install LTS or any specific version run the below commands:
# for lts n lts # for 18.14.0 n 18.14.0 ### MacOS - On macOS with Homebrew you can install the n formula. ```bash brew install n
- Or on macOS with MacPorts you can install the n port:
port install n
- On Linux and macOS, n-install allows installation directly from GitHub; for instance:
curl -L https://bit.ly/n-install | bash
ndoes not work in native shells on Microsoft Windows.
- You can install
fnmis also built in Rust but it's a little bit older than
- To install simply run the below command:
curl -fsSL https://fnm.vercel.app/install | bash
For references, check out this
- To install lts or any specific version run:
fnm install v18.4.0 fnm install --lts
For installing on Windows simply download the latest
fnm-windows.zipfrom releases, extract and install the
- Curl SSL failure: You can install all required certificates or disable SSL verification temporarily. Example as below:
# curl: (60) SSL certificate problem: unable to get local issuer certificate # More details here: https://curl.se/docs/sslcerts.html curl --insecure https://get.volta.sh | bash
- NVM failing to install any version with below error, its due to same ssl error. Disable by add
~/.curlrc. Refer to this.
# nvm install --lts # Version '' (with LTS filter) not found - try `nvm ls-remote --lts` to browse available versions.
- NPM install fails with
npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY. Fix with disabling ssl for
npm. Refer to this.
npm config set strict-ssl false npm config set registry http://registry.npmjs.org/