Install Node.js using Nvm (Node.js Version Manager) on Ubuntu
We will be using the Node Version Manager (Nvm) to install Node.js. And compared to other Node.js installation methods, it has the easiest ways to have multiple versions of Node.js without adding much extra complexity. There will be times when an application needs different versions of Node.js to work, so having the flexibility to change that is important and will save you a lot of time.
Once completed, you will be ready to start building Node.js applications!
Install/Verify System Packages
Before going through these steps, open a new terminal (
T) and navigate to the home directory of your machine:
$ cd ~
First, let's update the system packages on your machine:
$ apt-get update
When that finishes, run the following command to install the
build-essentialpackage if you don't already have it:
$ apt-get install build-essential
Install Nvm (Node Version Manager)
Now we are ready to install the
nvmpackage. Use one of the two (
wget) commands below to run the
At the time of publication,
NVM v0.34.0was the most recent version available. Make sure you check the NVM Github project page to get the latest version and replace the yellow text in the commands below.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Or use the
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
bashscript clones the
~/.nvmand adds the source line to your profile (
Reload the Shell
After running the above command, you will receive an output message similar to the following in your terminal:
=> Close and reopen your terminal to start using nvm or run the following to use it now:
You can reload the shell by running:
$ source ~/.bashrc
Or simply open a new Terminal window/tab.
Verify the Installation
To verify that
nvmwas installed correctly, use this command:
$ nvm --version
You should see an output with the version of
Now let's install the latest Node.js stable release (replace the yellow text with the version you wish to install):
$ nvm install v10.16.0
You now have Node.js installed!
Some Useful Nvm Commands
For the last part of this, we will quickly go over a few useful commands you can use with
Look What Versions are Installed
To see what versions of Node.js have been installed in the past, use this command:
$ nvm ls
Install Specific Version of Node.js
To install a specific version of Node.js, use this command (replace the yellow text with the version you want to install):
$ nvm install v10.16.0
Change The Default Node.js Version To Use
If you want to change the default Node.js version later, you can run this command to adjust it (replace the yellow text with the version you want to use):
nvm alias default v10.16.0
You can also select what Node.js version is used on a per-project basis. This can be done by running
nvm use v10.16.0in the directory where your project resides.
Delete Node.js Versions
To delete any version of Node.js you have downloaded with
nvm, use this command (replace the yellow text with the version you wish to delete):
$ nvm uninstall v10.15.3
Congrats! You now have Node.js installed and it's ready for you to use!
Go build something cool!