wave

How to Install Node.js On Ubuntu 20.04.

Hind Naser

Hind Naser

Node.js, a JavaScript-based platform that uses Google Chrome’s JavaScript V8 Engine, is very powerful. It is used to create I/O-intensive web applications such as video streaming sites, single-page applications, and many other web applications. Node.js can be downloaded entirely free of charge and is used by thousands around the globe. It is majorly used to create network programs such as web servers similar to PHP, Java or ASP.NET.

Node.js uses an event-driven architecture. It also has a non-blocking input/output API. This API is intended to optimize an application’s throughput and scalability for real-time Web applications. Node.js also has a standard library that contains JavaScript packages. This may provide an interface for low-level APIs. It uses multiple threads to perform non-JavaScript low-level time-taking operations.

The speed of Node.js is mainly due to two factors: its V8 engine and its non-blocking feature. Node.js makes use of Google Chrome’s super-fast V8 execution engine. It is highly optimized and performs what we call JIT (Just in Time) compilation. It converts JavaScript code quickly into machine language. It can easily handle a large number of concurrent connections at high throughput. This translates into high scalability. Nodejs requires less context switching for a frontend developer working with JS. A Nodejs server makes it much easier to start and gain experience as a full-stack developer.

This tutorial will guide you on how to install Node.js or npm on Ubuntu 20.04.

  • You can use the standard Ubuntu repositories. This is the easiest method to install Node.js or npm on Ubuntu. It should be sufficient for most uses. Ubuntu repositories include version 10.19.0.
  • You can access the NodeSource repository. This repository can be used to install a different Node.js release than what is available in the Ubuntu repositories. NodeSource currently supports Node.js versions v14.x to v13.x and v12.x.
  • Using nvm (Node Version Manager). You can have multiple Node.js versions installed on one machine with this tool. This is the best way to install Node.js if you are a Node.js Developer.

Select the suitable installation method for your environment and install node.js.

 

Install Node.js & NPM from Ubuntu Repository

Ubuntu 20.04 includes a version of Node.js in the default repositories. It can be used to provide a consistent user experience across multiple systems. The current version is 10.19 at the time of writing. Although it will not be the most recent version, it should be sufficient to allow for rapid experimentation with the language.

You can use the apt package manager to obtain this version. Firsty, update Ubuntu.

osboxes@osboxes:~$ sudo apt update

 

To install Node.js, run the following command.

osboxes@osboxes:~$ sudo apt install nodejs

 

You can verify the success of the installation and also find the version by using the below command.

osboxes@osboxes:~$ node -v

 

You can use the packages in the repositories to suit your needs. However, you will most likely need to install npm. This is the Node.js package manager.

Node Package Manager is a command-line tool that installs, updates and uninstalls the Node.js package in your application. It also serves as an online repository for the open-source Node.js package packages. In addition, this repository hosts useful modules created by the node community from around the globe.

If you get the issue of libraries  libssl1.1 and libuv1 are missing, install them using below commands.

osboxes@osboxes:~$ sudo apt-get install libssl1.1=”1.1.1f-1ubuntu2″

 

osboxes@osboxes:~$ sudo apt-get install libuv1=”1.34.2-1ubuntu1.3″

 

Now, the following command will install node packages manager on your system.

osboxes@osboxes:~$ sudo apt install npm

 

You have now successfully installed Node.js, npm using Ubuntu’s default software repositories.

 

Installing Node.js with Apt Using a NodeSource PPA

A PPA (personal package archive), maintained by NodeSource, can be used to install a different version. These PPAs contain more Node.js versions than the official Ubuntu repositories.

You will need curl. If you don’t have it, run the below command to install it.

osboxes@osboxes:~$ sudo apt install curl

 

To access the packages, we first need to install the PPA. Use curl to access the installation script for your preferred version from your home directory. This will be done for version 14.

osboxes@osboxes:~$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –

 

Your configuration will now include the PPA. The local package cache will also be updated automatically. Now you can install Node.js.

osboxes@osboxes:~$ sudo apt install nodejs -y

 

We can check the nodejs version right now. It should be 14.

osboxes@osboxes:~$ node -v

 

 

Installing Node Using the Node Version Manager

We have seen through the Ubuntu repository that only the most recent Node.js package can be installed. You can download the exact version of Node.js for a specific system by using nvm, which is an abbreviation of “Node Version Manager”. It is the bash script that contains all Node.js versions. This allows users to install and test any Node.js variant as they need.

Visit the project’s GitHub page to install NVM on Ubuntu 20.04. Copy the curl command found in the README file. This will give you the latest version of the installation script.

The install script is required to install or update nvm. You can either manually download the script and run it, or you can use the wget or curl commands.

osboxes@osboxes:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh

 

Now, install the NVM with bash in the curl command.

osboxes@osboxes:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

 

This will install the nvm script to your user account. To use it, you must first source your .bashrc file.

osboxes@osboxes:~$ source ~/.bashrc

You can now ask NVM what versions of Node are currently available.

osboxes@osboxes:~$ nvm list-remote

 

It is quite a long list. To install Node, you can type any release version. To get version 18.0.0, type the command below.

osboxes@osboxes:~$ nvm install v18.0.0

 

You can see the different versions you have installed by typing the command below.

osboxes@osboxes:~$ nvm list

 

This first line shows the current active version (-> v18.0.0), followed closely by some named aliases, and the versions they point to.

With nvm, you can switch between the installed versions.

osboxes@osboxes:~$ nvm use v17.0.0

 

Below command can be used to verify that the installation was successful.

osboxes@osboxes:~$ node -v

 

 

Conclusion

We have shown you three ways to install Node.js or npm on Ubuntu 20.04.. The method you choose depends on your requirements and preferences. Although installing the Ubuntu or NodeSource packaged version is simpler, the nvm method allows you to add and remove different Node.js versions per-user. So, go ahead, choose your node.js installation method and install node.js on Ubuntu 20.04.

Share on Social Media:

OpenStack

Cluster API driver for OpenStack Magnum

Hind Naser

Public Cloud

9000 MTUs (jumbo frames) in all Public Cloud Regions

Hind Naser

Uncategorized

OpenInfra Summit Berlin 2022 VEXXHOST Recap

Hind Naser

Go to Top