Node.js is an open-source and cross-platform Javascript runtime environment built on Google’s V8 Engine. JavaScript is a popular programming language used for building fast, scalable, and highly available web applications. Node.js is a framework for building the backend for web applications. NPM is a package manager for Node.js. It allows developers to download and share JavaScript libraries and packages.
In this tutorial, we will show you how to install Node.JS on Ubuntu 22.04. There are three ways of going about this. You can install NodeJS from Ubuntu repositories, you can install from Nodesource or install NodeJS using NVM.
Option 1: Install Node.js on Ubuntu 22.04 from Official repository
Node.js and npm are available in the default Ubuntu repositories. As such you can easily install them using the APT package Manager. First, update the ubuntu system:
$ sudo apt update
Next, install Node.js and NPM via apt as follows:
$ sudo apt install nodejs npm
This installs Node.js and other required dependencies.
Option 2: Install Node.js from Nodesource
Nodesource is a Node.JS partner that focusses on helping enterprises to run production-ready Node.Js applications with performance, stability and security in mind. This method is suitable if you want to install newer versions on Node.JS and NPM.
NodeSource provides and installation script that updates the repository and adds the Nodesource repository to the sources list. So download and run the script using the curl command as follows:
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Once the script runs successfully, install Node.JS as follows.
$ sudo apt install nodejs
This installs Node.js together with other necessary libraries and dependencies. To confirm Node.js is installed, run:
$ node --version
Option 3: Install Node js and Npm using NVM
NVM, which stands for “Node Version Manager,” is a script that lets you manage several Node.js versions on your system. To install NodeJS and NPM using NVM, first, download and install NVM by running the following script:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
You will be some bunch of output on the terminal as shown.
Next, run the following commands to load nvm:
$ export NVM_DIR="$HOME/.nvm" $ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" $ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Verify the installed nvm version as follows:
$ nvm -v
To list all the available versions of Node.js using NVM, run the command:
$ nvm ls-remote
Next, install the latest available version of Node.js as follows:
$ nvm install node
To install a specific version of Node.js, specify the version. For example, to install NodeJS 18.1.0, run the command:
$ nvm install 18.1.0
Conclusion.
We hope that you can successfully install Node.JS on Ubuntu 22.04 without any hiccups. Happy coding and developing Node.JS applications!