VPS

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.

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

Node.js installed version check terminal output

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

List of available Node.js versions for Ubuntu

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

Checking Installed Node.js version

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

Uninstalling node.js using terminal on ubuntu

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.

About the author

Edward S.

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!