Jun 27, 2019
How to Install Node.js and NPM on Ubuntu 18.04
In this article, we will show you how to install Node.js on Ubuntu 18.04. This method works for local Linux machines and virtual private servers. We’ll cover two ways. You will also learn how to remove the feature if you decide it’s not for you.
What is Node.js
Node.js is one of the most popular web technologies today. It is used by many developers to increase the functionality of a web application. Some of the largest companies use it. That should give you an idea of its potential.
At the time of writing, the latest stable version of Node.js is 11.10.0. However, the recommended version for most users is 10.15.1 as it is a long-term supported version.
There are several ways to install Node.js, here we will show you the two simplest and most efficient ones.
Important: Before you start, you must have access to your server and be able to execute commands using sudo. Se tutorial how to access your VPS via ssh. Also, note that you do not have to perform both methods. Choose the one that best suits your needs.
Install Node.js and NPM from Ubuntu official repository
The easiest and fastest way to install Node.js on a server with Ubuntu 18.04 is through the official distribution repository.
First, connect to your server using ssh.
If you are running a system with Ubuntu, just open a terminal emulator from the main menu.
Once you’re connected refresh the APT cache. To do this, execute the following command:
sudo apt update
With this, we make sure that the repositories are synchronized and the system can safely download what is stored in them.
After that, you can install Node.js by running the following command.
sudo apt install nodejs
After entering your password, the installation process will begin.
You can also install NPM, which is the node.js package manager.
sudo apt install npm
Finally, check the installed version. To do so, run the following command:
This is the easiest way to install Node.js onto a Linux machine or Linux based VPS.
To remove Node.js, run this command:
sudo apt remove nodejs
Install a specific version of Node.js using NVM
There is another way to install Node.js on a server with Ubuntu 18.04. Using an NVM (Node Version Manager), we can choose a specific version to install. It’s great if you want to use an LTS version or just the latest version available.
First, download NVM using wget. If you are not sure you have wget, run this command.
sudo apt install wget
Now, run this command:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
The next step is to allow NVM to be used from your user’s bash profile by running this command:
Now, you can use NVM to show all the versions of Node.js available to install.
Feel free to choose the one you want. For stability and support we recommend version 10.15.1. To do it, run this command:
nvm install 10.15.1
You can check if the installation was successful by checking the version of Node.js. To do this execute:
As you can see, everything went well. Node.js is correctly installed and ready to use.
If you want to uninstall Node.js, and installed it with this method, deactivate it first.
Then, uninstall Node.js.
nvm uninstall v10.15.1
Node.js is a very useful technology for developing web applications. Installing it on a server with Ubuntu 18.04 is simple and we have shown you two ways to do it.