How To Install Node.js on Ubuntu


Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. JavaScript is used primarily for client-side scripting, in which scripts written in JavaScript are embedded in a webpage’s HTML and run client-side by a JavaScript engine in the user’s web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser. Consequently, Node.js represents a “JavaScript everywhere” paradigm,unifying web application development around a single programming language, rather than different languages for server side and client side scripts.

Supported Ubuntu versions:

NodeSource will maintain Ubuntu distributions in active support by Canonical, including LTS and the intermediate releases.

  • Ubuntu 14.04 LTS (Trusty Tahr) – not available for Node.js 10 and later
  • Ubuntu 16.04 LTS (Xenial Xerus)
  • Ubuntu 18.04 LTS (Bionic Beaver)
  • Ubuntu 18.10 (Cosmic Cuttlefish)

Installing Node.js via package manager

Installation instructions

Node.js v11.x:

# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejs

Node.js v10.x:

# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejs

Node.js v8.x:

# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL | bash -
apt-get install -y nodejs

To check which version of Node.js you have installed after these initial steps, type:

nodejs -v

Manual installation

If you’re not a fan of curl <url> | bash -, or are using an unsupported distribution, you can try a manual installation.

These instructions assume sudo is present, however some distributions do not include this command by default, particularly those focused on a minimal environment. In this case, you should install sudo or su to root to run the commands directly.

1. Remove the old PPA if it exists

This step is only required if you previously used Chris Lea’s Node.js PPA.

# add-apt-repository may not be present on some Ubuntu releases:
# sudo apt-get install python-software-properties
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*

2. Add the NodeSource package signing key

curl -sSL | sudo apt-key add -
# wget can also be used:
# wget --quiet -O - | sudo apt-key add -

3. Add the desired NodeSource repository

# Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
DISTRO="$(lsb_release -s -c)"
echo "deb$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

4. Update package lists and install Node.js

sudo apt-get update
sudo apt-get install nodejs

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning! Follow and send tweets me on @harshvardhanrvm

7 thoughts on “How To Install Node.js on Ubuntu

Leave a Reply

%d bloggers like this: