In this tutorial, you will learn how to install Node onto Ubuntu 19.04 Disco Dingo. We will cover installation from the default repositories and, for those wanting more recent releases, how to install from the NodeSource repositories.
Installing from Ubuntu
The Ubuntu 19.04 Disco Dingo repository includes NodeJS version 10.15. Like most packages found here, it certainly is not the most recent release; however, if stability is more important than features, it will be your preferred choice.
To install NodeJS, run the following command:
sudo apt install nodejs
The installation oddly does not include NPM. You will likely want to install the node package manager, too, and the version of NPM available from Ubuntu’s repository is 5.8.
To install NPM, run the following command.
sudo apt install npm
The benefit of installing Node and NPM from Ubuntu’s repositories is stability. The two packages will never see a major or minor version bump on Ubuntu 19.04. Instead, only bug fixes and critical flaws will be addressed.
The risk of updating either package and then breaking your application is severely lowered.
Installing from NodeSource
If your preference is to run more recent versions of Node and NPM, or if you require multiple versions to be installed, you should install from NodeSource.
The instructions below will cover a few of the versions available from NodeSource. For those wanting more documentation on NodeSource, you can visit their Github repository.
If you have already installed Node.js from the default Ubuntu repositories, it is strongly recommended you uninstall that package before moving forward. You will also need to uninstall NPM as well.
sudo apt remove nodejs npm
Installing Node.js 12.x
Add the Node.js 12.x repository by running the following command. You will need root privileges for it to be successful.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
To install Node.js 12.x after the script above completes, run the following APT command.
sudo apt-get install -y nodejs
Installing Node.js 11.x
Add the Node.js 11.x repository by running the following command. You will need root privileges for it to complete successfully.
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
Then run the following command to install Node.js 11.x onto Ubuntu via APT.
sudo apt install -y nodejs