3 ways to install Nodejs & NPM on Ubuntu 22.04 LTS Jammy

Learn the steps use to install Node.js Javascript and NPM on Ubuntu 22.04 Jammy JellyFish using the command terminal for developing applications.

Node.js is a platform for developing standalone JavaScript programs that run independently of host applications such as web browsers. Among other things, it can be used to program server-side scripts, network tools, and WebApps. Node.js is based on Google’s JavaScript engine V8, which is also used in the Chrome web browser. V8 is a process-based virtual machine that uses a JIT compiler to translate the JavaScript code into the machine language of the underlying hardware at run time.

It is mainly used for server programs and network tools, the platform is not limited to this. In addition to network-oriented command-line tools, general tools for system administration are also possible. Even classically structured desktop applications that do not follow the WebApp architecture are possible with Node.js. The NodeGUI module can be used to program graphical user interfaces based on the Qt5 GUI framework.

The Node Package Manager, npm for short of Nodejs can search, install, remove, compile, and update modules and dependencies of the modules you want to use to extend the capabilities of Node.js

It was developed in 2009 by programmer Ryan Dahl because he was unhappy with the inefficient way apache and PHP-based web applications handle many concurrent connections. Hence, he decided to use JavaScript for server-side programming because he liked the language’s asynchronous event system.

 

Steps to install Node.js and NPM on Ubuntu 22.04 LTS Linux

The steps are given here can be used for other Ubuntu versions including Linux Mint, Debian, POP_OS, and other similar OS.

#Method 1:

1. Update Ubuntu 22.04

The first thing we start this tutorial with is updating our system. This will ensure all the latest security updates are installed on our system and also our APT package index cache is up to date.

sudo apt update && sudo apt upgrade

 

 

2. Install NodeJS using the standard Ubuntu repo

Well, we can install the long-term version of the Node.js on Ubuntu 22.04 LTS using its default system repository, however, the version will not be the latest one.

While doing this article the version of Nodejs available to install using the standard repo was version 12. So, if you want this one then simply run:

sudo apt install nodejs

Install NodeJS using standard Ubuntu repo

 

#Method 2 using Nodejs Repo

—————————-For latest or desired version————————————–

4. Install Node.js using the repository

If you want the current version of the Nodejs, run the given command. This will add the repository only to obtain the latest version.

First, install curl:

sudo apt install curl
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

Install Nodejs and NPM:

sudo apt-get install nodejs

 

Whereas those who are looking for some specific version of Nodejs can add the repository as per the version.

For Node.js v18.x:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install nodejs

 

For Node.js v17.x:

curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install nodejs

 

For Node.js LTS (v16.x):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install nodejs

 

For Node.js v14.x:

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install nodejs

 

5. Check the installed Node and NPM version on Ubuntu

To check the Node version on Ubuntu, the command is:

node --version

To check the NPM version, the command is:

npm --version

 

6. How to update NPM and Node (optional)

If you want to install the latest updates available for Node and NPM, then we can use NPM itself, here are the commands for that.

First, update npm,

sudo npm update
npm install -g [email protected]

Then update the node to the next version,

npm install -g [email protected]  
or
npm install -g [email protected]

 

#3rd Method using NVM

7. Install Nodejs on Ubuntu 22.04 using NVM

If you don’t want to use the above two methods to install Nodejs and its NPM package manager then we can use NVM – Node Version manager. It is a project available on Github that we can use to install and manage all the versions of Nodejs.

However, just like Nodejs, NVM is also not available to use on Ubuntu by default, we have to install it manually. Here is the script for that:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

Reload your bash shell session:

source ~/.bashrc

Now, use the NVM and list all the available versions of Nodejs that you can install using this version manager.

nvm list-remote

Finally, if you are confirmed which version you need, then use the following syntax:

nvm install version-number

Replace the version number with the Nodejs version you want to install.

Install NodeJS using NVM

 

8. Uninstall or Remove

According to the method you used to install, go for the one to uninstall Nodejs and NPM completely from your system.

For standard or Nodejs repo using APT

sudo apt autoremove --purge nodejs

Those who use NVM

nvm deactivate version-number
nvm uninstall version-number

NVM uninstall Nodejs

To remove NVM from your system:

rm -rf "$NVM_DIR"

 

 Other Articles:

Install AngularJS in Ubuntu 22.04 | 20.04 Linux
How to install Signal Messenger on Ubuntu 22.04 LTS…
How to Install PlayOnLinux on Ubuntu 22.04…
How to use Google Two-Factor Authentication with Ubuntu 22.04

 

One Response

  1. Troy T Collinsworth May 30, 2022

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.