How to install Node.js on Ubuntu?
There are several ways to install Node.js on Ubuntu, two of the most commonly used methods are listed below:
Option 1: Install with package manager.
- Open the terminal.
- Run the following command to update the list of software packages:
sudo apt update
- Install Node.js and npm.
sudo apt install nodejs npm
- Verify if the installation was successful.
node -v
npm -v
- If the above command successfully outputs the version numbers of Node.js and npm, it means the installation was successful.
Option 2: Install from the official Node.js source.
- Open the terminal.
- Run the following command to import the GPG key of the official Node.js source:
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
- Run the following command to install Node.js and npm:
sudo apt install nodejs
- Verify the successful installation.
node -v
npm -v
- If the above commands successfully output the versions of Node.js and npm, it means the installation was successful.
Here are two commonly used methods to install Node.js on Ubuntu, you can choose one that suits your needs.