Category: Nodejs
nvm
is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. It allows easier use of different versions of Node.js on a single local enviroment and supports switching between them with minimal effort.
The steps outlined here are for NVM on a Mac however they should also work on Linux and Windows (and Windows using Windows Subsystem for Linux).
Specify the version of NVM based on the release versions at https://github.com/nvm-sh/nvm/tags. This TIL will be installing v0.37.2 of NVM.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Close and reopen your terminal to start using nvm.
Verify NVM has installed using the command:
command -v nvm
This should output nvm
to the console if the installation was successful.
List installed Node versions with the following command:
nvm ls
To see what versions are available to install (due to the number of verisons, you may want to pipe the output to less
):
nvm ls-remote
Install the latest LTS (Long Term Support) version with the following command:
nvm install --lts
Output:
Installing latest LTS version.
Downloading and installing node v14.15.5...
Downloading https://nodejs.org/dist/v14.15.5/node-v14.15.5-darwin-x64.tar.xz...
################################################################################################################################# 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v14.15.5 (npm v6.14.11)
Creating default alias: default -> lts/* (-> v14.15.5)
Verify the installation:
node --version
Output:
v14.15.5
Install the latest release of Node 12.
nvm install 12
Verify the installation:
node --version
Output:
v12.20.2
nvm install node
You can switch between Node versions as follows:
nvm use 12.1.2
Or for a specific version of 12:
nvm use 12.4.0
Or the latest LTS version:
nvm use --lts
If a Node version is not available locally when switching, you will be prompted to install it.
Note: NVM is not recommended for production environments. It should only be used during the development phase.
See Node Version Manager on GitHub for more details.