Advance

Tutorial Install Node.js And Npm On Ubuntu 21.04

Tutorial Install Node.js And Npm On Ubuntu 21.04

To run Javascript code on your machine, you need to install Node.js. It is an open-source cross-platform that is available in the Ubuntu repository. Node.js is designed to execute JavaScript code on the server-side and is supported by Node.js Package Manager. Npm is the default package manager for Node.js and the world’s largest software registry. There are three ways to Install Node.js And Npm On Ubuntu. According to the new release of Ubuntu, review the Tutorial Install Node.js And Npm On Ubuntu 21.04. To purchase your own Instant cheap Ubuntu VPS, order what you need on Eldernode.

How To Install Node.js And Npm On Ubuntu 21.04

Node.js is a cross-platform JavaScript runtime environment that is generally used to build back-end applications. It is also popular as a full-stack and front-end solution. Join us with this article to learn what are the different ways of installing Node.js And Npm On Ubuntu 21.04. Let’s see the title of these three ways and then continue to study the instructions:

1- From the Standard Ubuntu Repositories

2- From the NodeSource Repository.

3- Using Node Version Manager (nvm)

At the end of this tutorial, you can use the taught instructions for any Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.

Recommended Article: Tutorial Setup And Configure Nessus On Ubuntu 20.10

Prerequisites to Install Node.js and Npm on Ubuntu 21.04

To let this tutorial work better, please consider the below Prerequisites:

_ A non-root user with Sudo privileges.

_ To seup, follow our Initial server setup on Ubuntu 21.04.

Install Node.js and Npm from Ubuntu Repositories

This is the first and the easiest way to install Node.js and Npm on Ubuntu 21.04. So, you can expect a straightforward installation.

Use the following command to update the package index and install Node.js and Npm:

sudo apt update
sudo apt install nodejs npm

In this way, you will install a number of packages, including the tools necessary to compile and install native addons from Npm. When you are finished, run the command below to verify the installation:

nodejs --version

Install Node.js and Npm from NodeSource

If you want to install a different Node.js version than the one provided in the Ubuntu repositories, you can use this method. Currently, NodeSource supports Node.js v14, v13, v12, and v10.

NodeSource maintains an APT repository containing multiple Node.js versions. If your application requires a specific version of Node.js, use this repository. At the time of writing, the NodeSource repository provides v14, v13, v12, and v10 versions.

Here, you will install Node.js version 14.x. So, use the following command to download and execute the NodeSource installation script:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

In this way, the NodeSource signing key will be added to your system. The script will also create an apt repository file, install all necessary packages, and refresh the apt-cache.

Note: To change the version of Node.js to another considered one (for example 12x,) you just need to change the setup_14.x with setup_12.x.

When the NodeSource repository is enabled, run the command below to install Node.js and Npm:

sudo apt install nodejs

Note: The Node.js package contains both the node and npm binaries.

Then, you can verify if the Node.js and Npm were successfully installed or not. To do this, run:

node --version
npm --version

Use the following command to install the development tools, it allows you to compile native addons from npm:

sudo apt install build-essential

Install Node.js and Npm using NVM 

The third and last way of installing Node.js and Npm is to use Node Version Manager. If you need to have multiple Node.js versions installed on the same machine, this method is what you must use. Also, if you are a Node.js developer, you are recommended to choose this way of installation.

NVM is a bash script. You will use this method to manage multiple Node.js versions on a per-user basis. Also, you will be able to install and uninstall any Node.js version that you wish to use or test.

To download and install the nvm script, go to the nvm GitHub repository page and copy either the curl or wget command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Note: Since Sudo enables nvm for the root user, do not use it.

The script will clone the project’s repository from Github to the ~/.nvm directory.

Note: In the output, you will be asked to close and reopen your terminal or run the commands to add the path to the nvm script to the current shell session. Choose which one is easier for you.

When the script is in your PATH, run the command below to verify that nvm was properly installed:

nvm --version

Use the command below to get a list of all Node.js versions that can be installed with nvm:

nvm list-remote

In this way, it will print a huge list of all available Node.js versions.

Now, run the following command to install the latest available version of Node.js, run:

nvm install node

After a successful installation, run the command below to verify it by printing the Node.js version:

node --version

Conclusion

In this article, you learned How to install Node.js And Npm On Ubuntu 21.04. There are three different ways to reach this purpose and you reviewed all of them. Due to the explanation of each section, you can choose which one is appropriate for your environment. But if you are not sure which Node.js version to install, consult the documentation of the application you’re going to deploy.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day