Having just created a new Ubuntu 18.04 VM in Azure, I wanted to start using Node.js and NPM directly. However I believe the version that comes with apt-get by default is quite old, so I needed to install using another PPA (personal package archive).

Here are the steps to do that. I have used as a starting point the DigitalOcean tutorial but they have some steps that I don't find useful and so I am only including the essential steps to quickly get started with Node.js and NPM on Ubuntu 18.04.

1. Add the NodeSource PPA

From your home directory, use curl to retrieve the installation script for your preferred Node.js version. To install a different version, replace 10.x with your preferred version string:

cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh

2. Update the apt-get source

Then run the script under sudo. This will populate the apt-get cache, add the NodeSource signing key to your keyring, and add the apt sources list.

sudo bash nodesource_setup.sh

When finished, the update should look like this:

## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     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

3. Install Node.js

Last step is to install the nodejs package:

sudo apt-get install -y nodejs

It is advised to install build-essential as well as you might need to build native addons, depending on what NPM packages you will need. To do that, run:

sudo apt install build-essential

Finally, verify successful installation with:

node -v


npm -v