Categories: Ubuntu

Easy Node Installation on Ubuntu

The globe’s biggest software registry is npm which is the standard package management for Node.js. Programming, on the server side, may be done with the JavaScript runtime Node.js. With JavaScript—a technology that many have become acquainted with via browser-based web development—developers may use it to construct a scalable core functionality. Typically, networking and server-side programs are built considering it, making it fast and robust. We’ll go over a few easy ways to install Node on an Ubuntu system. Select the installation technique that works best for the environment that you are in.

Update the Ubuntu Repositories

Let’s begin with the launch of the Command Terminal on the Ubuntu system. Before moving towards the different methods to install Node on the Ubuntu system, we need to update the repositories of our Ubuntu system using the “apt” package in the “update” instruction.

Sponsored
$ sudo apt update

Check the Node Version

Before installing Node on the Ubuntu system, you should be sure that it’s not already installed at your end. For this, the use of “version” instruction is more than enough. Use the “node” keyword followed by the “-v” option to check the version of the Node. The output displays that it’s not found in the system and you need to install it.

$ node -v

Install Node Using the Apt Default Repository

The first and easiest way to install any program in an Ubuntu system is to use the “Apt” default package in the command shell. The “install” instruction should be executed by the use of the default “Apt” package and the “nodejs” keyword at the end. Make sure to run this query with “sudo” rights to avoid any privilege issues while working. Right after the execution of this query, the installation processing starts.

$ sudo apt install nodejs

While the process of execution of the previous instruction has taken place, it requires the availability of a 30.7MB disk on your Ubuntu machine. Make sure to have that and affirm yes by tapping on the “y” key as depicted in the following:

To confirm the installation and the installed version of Node on the Ubuntu system, run the “version” instruction by utilizing the “-V” option as shown in the following. The installed version is displayed on the terminal screen as follows:

Configure Node.js if the bundle in the repositories that meets your requirements just takes a few minutes. Most of the time, installing npm—the Node.js package manager—is also something that you should do. To accomplish this, use “apt” to set up the npm package in your Ubuntu system as follows:

$ sudo apt install npm

Affirm installing the npm package manager by pressing “y” upon prompt.

Wait until the node package manager “npm” gets installed as depicted in the following image:

After certain processing, the node package manager will be successfully installed.

Install Node Using the Node Source PPA

Users can employ a PPA (personal package archive) that is kept up-to-date by NodeSource to set up an alternative release of Node.js. Compared to the standard Ubuntu repository, these PPAs offer more Node.js releases. First, we must ensure that the system is not affected by the previous installation. So, we update the “apt” packages and repositories via the “update” instruction.

$ sudo apt-get update

After the update, make sure to update the system repositories and packages so that the system can get the effects of the new installations to be made. Therefore, the shell utilizes the “upgrade” instruction via the “apt-get” package.

Sponsored
$ sudo apt-get upgrade

Make sure to affirm that you want to continue this upgrade and wait for a while.

After a successful update and upgrade, you need to use the “cd” instruction to move within the home directory of your Ubuntu machine. After this, we move towards using an instruction to get the Node.js from its source. So, the “curl” utility is utilized in the instruction with the “-sL” option to get the setup of the Node.js version 16 from the source site and make its object file in the “tmp” folder using the “-o” option. This is going to be the downloaded Node script that we can go through.

$ cd ~

$ cd -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh

Now, the built-in “GNU Nano” editor is utilized in the command shell to open the newly created “nodesource_setup.sh” script file in the “tmp” folder to review it.

$ nano /tmp/nodesource_setup.sh

The setup node source Bash file will be opened in the nano editor. You can edit it if you want to and save it untouched if you are satisfied with the contents of this file.

The script of the file is displayed as follows:

It’s time to run the Bash “script” file that we reviewed. Make sure to only run it when you are totally satisfied with its script. The “bash” instruction executes the file using the file path and the sudo rights. The execution may display a warning that the running script might be deprecated, and you should installs another node version via the node source. Follow the instructions after that.

$ sudo bash /tmp/nodesource_setup.sh

After the successful execution of the Bash script, the ppa of the Node will be added to your system configuration successfully. Now, it’s time to install the loaded Node version on our system using the same “install” command with the “apt-get” package. The latest version of Node will be installed successfully at our end.

$ sudo apt install nodejs

Uninstall Node

If you don’t need the feel to use the Node in your Ubuntu Linux environment, you can remove it via the “apt” package followed by the “remove” keyword and the “nodejs” package name.

$ sudo apt remove nodejs

To automatically remove its documentation folders and cached data, make sure to use the “purge” instruction as well.

$ sudo apt purge nodejs

Conclusion

This guide contains all the instructions that you need to install the latest Node version on the Ubuntu system. Within this guide, we discussed two different ways to simply install the Node like using the default “apt” repository and the node source ppa. In the end, we also discussed how to completely remove it from the system.

Ubuntu Server Admin

Recent Posts

Building RAG with enterprise open source AI infrastructure

One of the most critical gaps in traditional Large Language Models (LLMs) is that they…

9 hours ago

Life at Canonical: Victoria Antipova’s perspective as a new joiner in Product Marketing

Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…

1 day ago

What is patching automation?

What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…

2 days ago

A beginner’s tutorial for your first Machine Learning project using Charmed Kubeflow

Wouldn’t it be wonderful to wake up one day with a desire to explore AI…

3 days ago

Ubuntu brings comprehensive support to Azure Cobalt 100 VMs

Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…

3 days ago

Ubuntu Weekly Newsletter Issue 870

Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…

4 days ago