Node Version Manager (NVM) allows you to install and switch between different versions of Node.JS using the command line. This article explains how to install Node Version Manager and Node.JS on Ubuntu 20.04.
To complete this guide, make sure you have a fully-updated Vultr Ubuntu 20.04 server.
SSH to the server.
Install NVM.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
SSH to the server.
Install NVM. The following command installs the latest version of NVM into $HOME/.nvm
.
$ export NVM_DIR="$HOME/.nvm" && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
Edit your ~/.bashrc
file:
$ nano ~/.bashrc
Add the following lines at the end of the file:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Save and exit the file.
Reload your ~/.bashrc
to activate NVM.
$ source ~/.bashrc
Verify NVM is installed with the -v
parameter. It should return the version number as shown.
$ nvm -v
0.38.0
SSH to the server, and re-run the automatic script.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
SSH to the server, then run the following to update from GitHub.
$ (
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
To install a specific version of Node.JS, specify the desired version number.
$ nvm install 6.14.4
To install the latest release of node, use node
, which is an alias for the latest version.
$ nvm install node
Test your node installation.
$ node -v
To learn more about how to use NVM, see the project documentation.