Learn the process of installing nodejs on Ubuntu server
For users who opt to use Linux operating system Ubuntu, this article explains how you can install Node.js on the Ubuntu server.
Ubuntu is a linus distribution based on Debian and its an open-source software which is available for free though some paid enterprise feature are available.
Here in this guide, we would show how to install the Node.js on 20.04 server of Ubuntu in two ways.
Firstly by using apt to install the nodejs package from official Ubuntu’s default software repository, and secondly by installing nvm, the Node Version Manager, which enable you to select the latest version of Node.js and manage same.
For most cases, using apt with the default repo is all you need. However, if you are actively developing Node applications and need to switch between node versions frequently, choose the nvm method.
Before we proceed, I assume you already have the latest version of Ubuntu, for this guide we refer to version 20.04.
Now we are going to explain the process for installing Nodejs on Ubuntu official default software repository.
Which are the steps to install them on the Ubuntu official default software?
Lets see the steps to take for this. At the end of this session you should have been able to successfully installed Node.js and npm using apt and the official default Ubuntu software repositories.
- Step 1: Open terminal or press Ctrl + Alt + T and refresh your local package index first by typing:
sudo apt update
- Step 2: Install Node.js by typing the command
sudo apt install nodejs
- Step 3: To confirm the installation status is okay, check the node version by typing the command
node -v or node -version
To install the npm package with apt, type the following command.
sudo apt install npm
As earlier said, Node Version Manager is a tool that allows programmers to seamlessly switch between different versions of Node. Let’s see this option.
Now we are going to explain the process for installing Nodejs on Ubuntu via the Node Version Manager (NVM).
Which are the steps for installing them on Ubuntu via the Node Version Manage (NVM)?
The Node Version Manager allows you to install and maintain different independent versions of Node.js, and their associated Node packages on a single environment. Let’s see how you download and install the nvm shell script and switch between different node versions.
- Step 1: Get the latest version of the installation script from the project GitHub page readme.
- Step 2: Open your terminal and run the curl command of the script to download it.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
- Step 3: Confirm that nvm was successfully installed and running, check by typing the command
This will return the version of nvm installed.
If you are unable to use the nvm command open the existing.bash_profile file and add the following line to it:
- Step 4: Now, you can check which versions of Node are available by typing the command
- Step 5: Install the version of your choice from the list by typing the command
nvm install (version)
Or you can install the very latest by typing
nvm install node
Next, to use the version of Node.js, run the use command:
nvm use node
In the same way that when you were installing Nodejs on Ubuntu server, you can install long-term support (or LTS) releases of Node by typing the command
nvm install --lts
And to use it run the command
nvm use --lts
- Step 6: After Installing them on the Ubuntu server you can see the different versions you have installed by typing:
- Step 7: You can switch between installed versions with nvm use, for example
nvm use v14.10.0
Which is our conclusion?
We have looked at a few ways to get Node.js installed on your Ubuntu machine. You may or may not encounter any issues during the installation process but if you do, do try to check for ways to troubleshoot these from online resources. Also for the option on which method to use, your specific circumstances will help you decide which method is best for your needs. From what we see using the packaged version in Ubuntu’s repository is a more straightforward method, but using nvm gives you more flexibility.
Now you have it you can begin to create wonderful applications with Node.js. The key advantage of Node.js according to the Open JS Foundation is that almost no function in Node.js directly performs I/O, so the process never blocks except when the I/O is performed using synchronous methods of Node.js standard library. Because nothing blocks, scalable systems are very reasonable to develop in Node.js.
We hope this guide to explain the process for installing Nodejs on Ubuntu has been useful for you.