Installing Node.js on Ubuntu 18.04
Node.js is a free backend JavaScript execution environment designed to build scalable, networked applications. At the moment it is used for writing full backend applications, microservices, and website parsers. It is irreplaceable for creating GraphQL APIs or running SSR frontend applications.
Npm is the default package manager for Node.js and the world's largest software registry.
There are several installation options of NodeJS on Ubuntu 18.04 and 20.04. Either install Node.js and npm from the NodeSource repository or from Ubuntu Repository itself.
Install Node.js and npm from NodeSource
It’s 2022 on the calendar so it means At the time of writing this article 17.x is the active LTS version of Node.js. You can always choose the older version if you wish by writing setup_16.x or setup_15.x and so on. Don’t forget to add the PPA to your Ubuntu machine.
Nodejs 17.x LTS version:
curl -sL https://deb.nodesource.com/setup_17.x | sudo -E bash -
After adding PPA from NodeSource, then install Node.js and npm on ubuntu. Npm comes here as well:
sudo apt-get install nodejs
Next check the versions of node.js and npm which were installed.
Node.js and npm version:
nodejs -v
npm -v
How to install Node.js and npm from Ubuntu repository:
As well as from the NodeSource, you can install Node.js and npm from Ubuntu’s default repository. Enter these commands:
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
And check the versions. The same as with NodeSource method:
nodejs -v
npm -v
Conclusion:
Congrats! You have installed a Node.js and npm on your Ubuntu server. Feel free to reach out to us if you have any problems with installation. We are always ready to help!