nvm
Source: github.com: Node Version Manager
Manage multiple installations of node.js on these platforms: unix, macOS, and windows WSL.
Installation
Install
cURL(a tool used for downloading content from the internet in the command-line) with:sudo apt-get install curlCheck the most recent release at github.com: Node Version Manager. Adjust the below command to include the newest version:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bashTo verify installation, enter:
command -v nvmthis should return
nvm, if you receivecommand not foundor no response at all, close your current terminal, reopen it, and try again. Learn more in the nvm github repo.List which versions of
nodeare currently installed (should be none at this point):nvm lsInstall two version of
node:Current release of node.js (for testing the newest feature improvements, but more likely to have issues):
nvm install node # "node" is an alias for the latest versionThe latest stable LTS release of node.js (recommended):
nvm install --lts
List what versions of
nodeare installed:nvm lsnow you should see the two versions that you just installed listed.
Verify that
node.jsis installed and the currently default version with:node --versionThen verify that you have npm as well, with:
npm --version(You can also use
which nodeorwhich npmto see the path used for the default versions).
Change Version of Node
To change the version of node.js you would like to use for a project, create a new project directory:
mkdir NodeTest # create the directory
cd NodeTest # enter the directory
nvm use node # swith to the Current version or
nvm use --lts # switch to the LTS version
You can also use the specific number for any additional versions you've installed, like:
nvm use v8.2.1
To list all of the versions of node.js available, use the command:
nvm ls-remote
If you are using nvmto install node.js and npm, you should not need to use the sudo command to install new packages.
Set the Default Node Version
To set a default node version to be used in any new shell, use the alias 'default':
nvm alias default node
# in my case
nvm alias default 12
# and if you don't want restart shell
nvm use 12
Updating
Installing the newer version of nvm using cURL will replace the older one, leaving the version of node you've used nvm to install intact. For example:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
Remember to check the most recent release at github.com: Node Version Manager and adjust the above command to include the newest version.
Auto-switching node version
See nvm per Folder