How to Install Node.js on Ubuntu 22.04
Abstract: //deb.nodesource.com/setup_18.x | sudo -E bash After adding the NodeSource repository to your system//deb.nodesource.com/setup_16.x | sudo -E bash Nod
Node.js is an open-source, cross-platform, backend JavaScript runtime environment mainly used for developing web applications and network tools.
It is built on Chrome’s V8 JavaScript engine, developed Node.js by Ryan Dahl in 2009, and maintained by OpenJS Foundation.
Here, we will see how to install Node.js on Ubuntu 22.04.
Install Node.js On Ubuntu 22.04You can install Node.js from three sources,
- From NodeSource Repository
- Using NVM
- From Ubuntu Repository [Not Recommeded]
NodeSource maintains Node.js binary packages for Ubuntu operating systems. So, set up the NodeSource repository on your system for the Node.js version you want to install.
At the time of writing the post, NodeSource is yet to offer Node.js packages for Ubuntu 22.o4. However, the steps mentioned here will work once they publish packages.Node.js 16.x (LTS)
wget -qO- https://deb.nodesource.com/setup_16.x | sudo -E bash
Node.js 18.x (Current Version)
wget -qO- https://deb.nodesource.com/setup_18.x | sudo -E bash
After adding the NodeSource repository to your system, install the Node.js and NPM using the apt
command.
sudo apt install -y nodejs2. Install Node.js using NVM
NVM (Node Version Manager) is a version manager for Node.js. It helps us in installing Node.js and switching between different versions.
First, use the bash script to install nvm on your system.
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Then, to start using nvm, close and reopen your terminal or run the following command to load the nvm to your current session.
source $HOME/.bashrc
Node.js 16.x (LTS)
nvm install --lts
Node.js 18.x (Current Version)
nvm install node
Apart from installing Node.js with NVM, it also helps you manage Node.js installation.
Validate Node.js InstallationYou can check the version of Node.js using the following command.
node -v
Output:
v16.14.2
Additionally, you can check the version of NPM using the following command.
npm -v
Output:
8.5.0Install Yarn Package Manager (Optional)
Yarn is a package manager and helps to install project dependencies very effectively. To install the Yarn package manager, follow the below link.
READ: How to install Yarn on Ubuntu 22.04
Install Build Tools (Optional)You may install build tools if you plan to compile and install native addons from npm.
sudo apt install -y build-essential curlConclusion
That’s All. You have learned how to install Node.js on Ubuntu 20.04.