Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Install Node.js on Ubuntu 16.04

This guide shows how to install Node.js on an Ubuntu 16.04 server. It needs root access, so it suits a VPS or dedicated server.

Web Hosting2 min read12 steps
Tip: Ubuntu 16.04 is old software and no longer gets standard updates. Newer Ubuntu versions use almost the same steps.

What is Node.js?

Node.js lets you run JavaScript outside a web browser, for example on a server. It comes with npm, a tool that downloads code libraries for your project.

Method 1: Install from the Ubuntu package list

This is the simplest way, but the version is old.

  1. Connect to your server with SSH.
  2. Update the package list:
sudo apt-get update

This refreshes the list of available software.

  1. Install Node.js and npm:
sudo apt-get install -y nodejs npm

This installs both tools.

  1. Ubuntu names the program nodejs. To use the name node, add a link:
sudo ln -s /usr/bin/nodejs /usr/bin/node

This makes a shortcut so both names work.

Method 2: Install a newer version with NodeSource

NodeSource is a group that offers newer Node.js packages. Version 10 is a safe choice for Ubuntu 16.04.

  1. Install curl, a tool that downloads files:
sudo apt-get install -y curl
  1. Add the NodeSource package source:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

This tells Ubuntu where to find the newer packages.

  1. Install Node.js:
sudo apt-get install -y nodejs

This installs Node.js and npm together.

Method 3: Use nvm

nvm is a Node Version Manager. It lets you install many versions and switch between them.

  1. Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  1. Close the terminal and open it again.
  2. Install a version:
nvm install 10

This installs Node.js version 10.

Check the install

node -v
npm -v

These print the version numbers of Node.js and npm.

Try a small test

  1. Create a file:
echo "console.log('Hello Node');" > hello.js
  1. Run it:
node hello.js

If you see "Hello Node", all is well. For help with your server, open a support ticket.

Quick recap

  • Use apt for the easy, older version.
  • Use NodeSource or nvm for a newer version.
  • Check with node -v and npm -v.