How to Install Node.js and NPM on Ubuntu 18.04
Download Complete Linux Commands Cheat Sheet
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.
Simply put, Node.js is a server-side execution environment that allows JavaScript to run without the client. Node.js is open source and cross-platform, which makes it ideal for different projects – from education to business.
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.
ssh username@server_ip_address
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:
nodejs -v
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:
source ~/.profile
Now, you can use NVM to show all the versions of Node.js available to install.
nvm ls-remote
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:
node -v
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.
nvm deactivate
Then, uninstall Node.js.
nvm uninstall v10.15.1
Conclusion
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.
Learn What Else Your Ubuntu Can Do
How to Install LAMP Stack on Ubuntu
How to Install Git on Ubuntu
How to Setup Mail Server on Ubuntu
How to Install Maven on Ubuntu
How to Install WordPress on Ubuntu
How to Setup an FTP Server for Ubuntu
How to Install Anaconda on Ubuntu
Comments
May 05 2019
it helps me clarify a lot thanks.
June 28 2019
merci beaucoup pour ce tutoriel sa ma beaucoup aider
March 10 2020
So helpful! Thanks!
April 13 2021
we have starter startup cloud hosting of hostinger. can we install node.js ?
May 19 2021
Hiya harshk, Node.js is not supported on Shared and Cloud hosting packages. If you want to use Node.js, you can install this useful feature on our VPS plans
August 31 2021
I have installed node js in vps, but when executed the command node --version or npm --version, I am getting error as "cannot execute binary file"
September 20 2021
Hi Alana, it looks like there might be some misconfiguration inside of your VPS. I would suggest to check with our Customer Success team if they can find anything off with your server.