The JavaScript runtime en­vi­ron­ment Node.js has been a fun­da­men­tal tool for de­vel­op­ers for years. Countless websites and ap­pli­ca­tions rely on the platform, the latest versions of which have been down­loaded and used millions of times. We explain step by step how to install Node.js on Ubuntu.

What are the re­quire­ments for in­stalling Node.js on Ubuntu?

Before pro­ceed­ing with the in­stal­la­tion, it’s important that your system meets certain re­quire­ments to ensure suc­cess­ful in­stal­la­tion and smooth operation of the platform. Since Node.js executes JavaScript code, having prior ex­pe­ri­ence with the scripting language is def­i­nite­ly a plus. Being familiar with JavaScript’s basic syntax and functions as well as the typical use cases that it’s used for will make it easier for you to use Node.js in a more targeted manner. Similarly, knowledge of object-oriented pro­gram­ming (OOP) and software design prin­ci­ples puts you at an advantage when working with the runtime en­vi­ron­ment.

Hardware

To install Node.js on Ubuntu, you’ll need suitable hardware. The platform isn’t par­tic­u­lar­ly demanding though and functions on most modern computers. All you need is a memory of at least four gigabytes and a minimum of 256 gigabytes of available storage space on your hard disk. It’s also important to have a stable internet con­nec­tion.

Software

Your operating system and the programs required for in­stalling and running Node.js should be up to date. This helps to ensure com­pli­ca­tions don’t arise when in­stalling Node.js on Ubuntu. You should have an Ubuntu server installed and con­fig­ured as well as a non-root user set up. It’s also a good idea to set up a firewall. You’ll need a browser to use Node.js. The runtime en­vi­ron­ment works with all popular providers.

VPS Hosting
VPS hosting at un­beat­able prices on Dell En­ter­prise Servers
  • 1 Gbit/s bandwidth & unlimited traffic
  • Minimum 99.99% uptime & ISO-certified data centers
  • 24/7 premium support with a personal con­sul­tant

Step-by-step in­struc­tions for in­stalling Node.js on Ubuntu

There are different ways you can install Node.js on Ubuntu. In the following sections, we’ll discuss three different methods.

Direct in­stal­la­tion

To install the stable version of Node.js on Ubuntu, you should first update the terminal. To do this, follow the steps below:

  1. Check for an update for the terminal and install it if necessary. To do this, use the following command:
$ sudo apt update
bash
  1. Now install the runtime en­vi­ron­ment using the following code:
$ sudo apt install nodejs
bash
  1. Node.js uses the package manager npm. You can install it with this code:
$ sudo apt install npm
bash
  1. Finally, check whether your version of Node.js is now up to date:
$ node -v && npm --version
bash

Personal package archive (PPA)

Al­ter­na­tive­ly, you can carry out the in­stal­la­tion with a personal package archive (PPA). To use this method, you’ll need cURL, a tool that you can use to transfer data to and from a server. If you can’t find cURL on your system, you can start by in­stalling it:

  1. Here’s the command for in­stalling cURL:
$ sudo apt install curl
bash
  1. Now add the official Node.js setup page to cURL:
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
bash

If you receive an error message such as “the following sig­na­tures couldn’t be verified because the public key is not available”, retrieve your public key and then copy and paste it into the following code:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key <INSERT YOUR KEY HERE>
bash
  1. Then install Node.js:
$ sudo apt install -y nodejs
bash
  1. Finally, check that the latest version of Node.js has been installed on your Ubuntu system:
node -v && npm --version
bash

Node Version Manager

If you want to be able to choose from different versions of the runtime en­vi­ron­ment, it’s best to install Node.js with the Node Version Manager (NVM). Here’s how to do it:

  1. Install the command line:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
bash
  1. Now use NVM to install Node.js under Ubuntu:
$ nvm install node
bash
  1. Ensure you’ve installed the correct version:
$ node -v
bash

Check whether NVM is up to date:

$ nvm --version
bash

How to test whether the platform works

Before launching projects with Node.js, test the program. To do this, create a simple ap­pli­ca­tion. Here’s how:

  1. Create a new folder:
mkdir new-project
bash
  1. Open the folder:
cd new-project
bash
  1. Launch a new project in Node.js using the following command.
npm init -y
bash

This creates a new file called package.json, which contains the metadata and links of your project.

  1. Create a new file. You can use a text editor such as nano for this:
sudo nano app.js
bash
  1. Enter the following command:
console.log("Here is your sample text.");
bash
  1. Save the file.

  2. Open the terminal and enter the following command:

node app.js
bash
  1. Check that your sample text has been saved. If it has, that means you’ve suc­cess­ful­ly installed Node.js on your Ubuntu system and can now work with the platform. If you’d like to learn how to use the platform, we recommend checking out our tutorial on In­tro­duc­tion to Node.js.
Tip

Explore more useful in­for­ma­tion about Node.js, Ubuntu and JavaScript in our Digital Guide. To get started, check out our summary of the dif­fer­ences between Java and JavaScript.

Go to Main Menu