Introduction:
In this tutorial, we will explore three different ways of installing Node.js and npm on Ubuntu 20.04:
If you don't already have a server. You can start off by ordering a Linux VPS
Step 1:
The installation is pretty straightforward. Run the following commands to update the package index and install Node.js and npm:
sudo apt update
sudo apt install nodejs npm
The command above will install a number of packages, including the tools necessary to compile and install native addons from npm.
Once done, verify the installation by running:
nodejs --version
Installing Node.js and npm from NodeSource:
NodeSource is a company focused on providing enterprise-grade Node support. It maintains an APT repository containing multiple Node.js versions. Use this repository if your application requires a specific version of Node.js.
At the time of writing, NodeSource repository provides the following versions:
- v14.x - The latest stable version.
- v13.x
- v12.x - The latest LTS version.
- v10.x - The previous LTS version.
We’ll install Node.js version 14.x:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Once the NodeSource repository is enabled, install Node.js and npm:
sudo apt install nodejs
The nodejs package contains both the node
and npm
binaries.
Verify that the Node.js and npm were successfully installed by printing their versions:
node --version
To be able to compile native addons from npm you’ll need to install the development tools:
sudo apt install build-essential