Node.js is one of the most popular open source development platform that powers many web applications. With Node, developers can create server-side code; because it’s an asynchronous and event driven environment, you don’t have to worry about blocking your scripts while they’re running on your servers.
Node.JS is a backend Javascript runtime environment based on Google’s V8 engine that is open-source. It’s an asynchronous event-driven Javascript runtime environment designed to help you create fast and scalable network apps and backend API services.
There are three methods for installing Node.JS on Ubuntu, and we’ll go through each one in detail.
Method 1: Use the Ubuntu Repository to install Node.JS and NPM.
Start by modifying the package lists to install Node.JS and NPM from the Ubuntu repository:
sudo apt-get update
Then, as follows, install Node.JS and NPM from the Ubuntu repository using the apt package manager.
$ sudo apt install nodejs npm -y Install NodeJS from Ubuntu Repository
The most recent version of Node.JS available from the default Ubuntu repository is v10.19.0 at the time of writing this article. Run the following command to validate this:
$ nodejs -v OR $ nodejs –version Check NodeJS Version
Method 2: Use the Nodesource Repository to install Node.JS and NPM.
Installing Node.JS and NPM from NodeSource, which is targeted at helping enterprises run mission-critical Node.JS applications with an emphasis on speed and resource efficiency, is an alternative method.
Begin by downloading and running the Script for installing Nodesource as instructed.
curl -sL $$$$$$$ sudo -E bash – https://deb.nodesource.com/setup 14.x
The script adds a Nodesource signing key to the sources list file, establishes a Nodesource repository, and updates the apt cache.
Nodesource Repository may be downloaded.
Additional information on how to continue will be provided in the output.
Script for installing Nodesource
Run the following command to install NodeJS:
apt install nodejs -y $ sudo apt install nodejs -y
Both nodejs and npm binaries are included in the NodeJS package.
NodeJS may be downloaded at Nodesource.
Run the following command to see whether Node.JS is installed:
—version node
Run the following command to install npm:
$ npm –version Confirm NodeJS Version
Method 2: Using NVM, install Node.JS and NPM.
NVM (Node Version Manager) is a shell script that allows users to manage different Node.JS versions on a per-user basis. You may install, remove, and specify a certain Node.JS version as the default version using NVM.
Run the following command to get the NVM script:
$ curl nvm/master/install.sh | bash https://raw.githubusercontent.com/creationix/nvm/master/install.sh
The result will tell you that you need to reopen your terminal to use nvm towards the conclusion. So, to start performing nvm commands, shut your terminal and reopen it.
NVM Script may be downloaded.
You may check the version of nvm that is installed by running the following command:
$ nvm –version Check NVM Version
Run the command to get a list of all the Node.JS versions that may be installed:
$ nvm list-remote List NodeJS Versions
The result lists all of the versions of Node.JS that may be installed, including the LTS versions. At the time of writing, the most recent LTS version is v16.14.2.
Versions of NodeJS with Long-Term Support
Run the following command to install the latest LTS version of Node.JS:
—lts nvm install
Just to be sure you have the most recent LTS version installed, use the command:
—version node Install NodeJS Using NVM
Run the following command to install a particular version of Node.JS, such as 17.7.2:
$ nvm install 17.7.2 Install NodeJS Specific Version
Run the following command to get a list of all the Node.JS versions installed on your system:
$ nvm ls List NodeJS Installed Versions
To switch to a different version of Node.JS, such as 16.14.2, use the command:
$ nvm use 16.14.2 Change NodeJS Version
Run the following command to make Node.JS the default version.
$ alias 16.14.2 nvm
That’s all there is to it. We looked at three different methods for installing Node.JS and npm on your PC. The newest version of Node.JS is not available from the Ubuntu repository.
Installing from Nodesource and NVM is suggested for getting the most recent version. The NVM installation technique also allows you to choose the version of Node.JS to designate as default for your environment and install your favorite version of Node.JS.
Frequently Asked Questions
How do I install Nodejs on Ubuntu?
A: The official site for Nodejs is https://nodejs.org/en/. If you want to install it, go ahead and follow their installation instructions.
Can you install node with NPM?
A: Yes, you can install node with NPM by running the following command in your terminal.
How do I download Nodejs 16?
A: The best way to download Nodejs 16 is by using the terminal. For this, you would need to open up your command prompt or terminal application and type in node . Once it starts downloading from their website, it will be added into your directory where ever you have downloaded/copied Nodejs before.