In this guide, we will explain how to install NodeJS & NPM on an Ubuntu 16.04/18.04 server.
Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.
You can also view our guide on Installing NodeJS & NPM on CentOS 7
Step 1: Add Node.js APT Repository
We will add the most recent packages of Node.js which are available on an APT repository. First, update your system and install some dependencies.
sudo apt-get update sudo apt-get -y install curl dirmngr apt-transport-https lsb-release ca-certificates vim
To check the latest release, visit the Node.js Releases page
Add Node.js current repository:
At the time of this guide, the latest version of the NodeJS current repository is 11.14.0. Issue the command below to add the Apt repository for that version:
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
Add Node.js LTS repository
For production purposes, the LTS release is recommended. At the time of this guide, this is Node.js 10.15.3 LTS. Issue the command below to add the Apt repository for that version:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Step 2: Install Node.js
Next, proceed to install
nodejs with the command below:
sudo apt-get -y install nodejs
You can also proceed to install development tools to build native add-ons with the command below:
sudo apt-get install gcc g++ make
After successfully installing, you can confirm versions of nodejs with the command below:
node --version npm --version
Step 3: Install Yarn package manager
This is optional but to install the Yarn package manager, issue the command below:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn
Verify installation with the command below:
To learn more about NodeJS, you can read the official documentation for more information.