In this post, we will check out three different methods of installing Node.js and Npm on Ubuntu 22.04.
How to Install Node.js and npm using Ubuntu 22.04 Repository
The process of installing Node.js from the official Ubuntu repository is just like installing any other package. It is easy and straightforward and installs the latest stable version available.
Update the repositories:
Now simply use the apt package manager to install Node.js and Npm on Ubuntu 22.04:
apt will install Node.js, Npm, and all of their required dependencies:
Once the process is finished, you can use this command to verify whether Node.js was installed successfully:
How to Install Node.js on Ubuntu 22.04 using Node Version Manager
If you want to install a specific version of Node.js then you should opt for nvm (Node Version Manager) which is a bash script that allows you to install and manage multiple versions of Node.js on the same machine.
First of all, you need to install the nvm script. To install nvm you can use either the curl or wget command (whichever command-line utility, you have installed on your system):
Close and reopen your terminal or run the below-given command to source the bash file:
Now to list all versions of Node.js available with nvm, use this command:
To install a specific version of Node.js on Ubuntu 22.04, utilize the below-given command:
Execute this command to list all of the installed versions of Node.js:
You can use the following command to change the default Node.js version of your system:
To activate a version of Node.js, use this command:
How to Install Node.js on Ubuntu 22.04 Using NodeSource PPA
You can also use NodeSource PPA to install a specific version of Node.js. Use the curl command to download the script to install your preferred Node.js version:
Note: You can replace ‘setup_12.x’ with your preferred version.
Once your package cache is updated and the NodeSource repository is enabled, run the below-given command to install Node.js:
Use this command to verify the installation:
Conclusion
Node.js is an open-source runtime environment that is utilized for executing JavaScript code on the V8 engine and is mostly used for backend/server-side development. This post showed you three different methods of installing Node.js and its package manager on your Ubuntu 22.04 machine. The method you should use for this purpose depends on the flexibility that you need over running different versions of Node.js.