Installing Node.js on Ubuntu 16.04

Complete guide to setting up and managing Node.js versions.

Logo

Node.js is a runtime that lets you run JavaScript outside the browser — perfect for building servers, CLI tools, APIs, file processing, network apps, and even desktop applications (via Electron).
It's one of the most popular choices for backend development on VPS or dedicated servers.

Ubuntu 16.04 (Xenial) is from 2016, so its default repositories ship a very old Node.js version (4.2.6).
We'll cover three practical ways to get modern, supported versions installed.

Option 1: From Ubuntu Repositories (quick but outdated)

This method installs Node.js 4.2.6 — fine only for legacy compatibility.

  1. Update package index:

    sudo apt-get update
    
  2. Install Node.js:

    sudo apt-get install nodejs
    
  3. Install npm (package manager):

    sudo apt-get install npm
    

Check versions:

nodejs -v   # → v4.2.6
npm -v      # → ~3.x

Note: The binary is called nodejs (not node) to avoid conflict with another package. For convenience, create a symlink:

sudo ln -s /usr/bin/nodejs /usr/bin/node

Avoid this method for new projects — version 4 is long unsupported.

Option 2: Via NodeSource PPA (recommended for Ubuntu 16.04)

NodeSource maintains up-to-date Node.js packages for Ubuntu.

  1. Install curl if missing:

    sudo apt-get install curl
    
  2. Add the NodeSource repository for your desired version (replace 10.x with 12.x, 14.x, etc.):

    curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    

    Common choices:

    • v12.x: setup_12.x
    • v14.x: setup_14.x
    • v16.x: setup_16.x(latest supported on 16.04)
  3. Install Node.js:

    sudo apt-get install -y nodejs
    

Check:

node -v     # например v10.24.1
npm -v      # например 6.14.12

For native module compilation (needed for some packages):

sudo apt-get install -y build-essential

Option 3: Using nvm (Node Version Manager) — most flexible

nvm lets you install and switch between any Node.js versions without root privileges or conflicts.

  1. Install build tools:

    sudo apt-get update
    sudo apt-get install -y build-essential libssl-dev
    
  2. Install nvm (latest version as of 2026):

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    

    or

    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
  3. Load nvm into the current shell:

    source ~/.bashrc
    # или перезапустите терминал
    
  4. List available versions:

    nvm ls-remote
    
  5. Install the version you want (e.g. latest LTS):

    nvm install 18
    nvm install 20
    
  6. Switch to a version:

    nvm use 18
    
  7. Set a default version (loads automatically in new sessions):

    nvm alias default 18
    

Check:

node -v
npm -v

Benefits of nvm:

  • Run multiple Node versions side-by-side
  • Switch instantly per project
  • No sudo needed for installation
  • npm updates automatically with Node

Useful Commands & Tips

  • Update npm to the latest:
npm install -g npm@latest
  • Install global tools (pm2, yarn, nodemon, etc.):
npm install -g pm2 yarn nodemon
  • Avoid EACCES errors with global installs — set a user-owned directory:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
source ~/.profile
  • Quick version info in any project:
node -p "process.versions"

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Updated at:
Need help?Our engineers will help you free of charge with any question in minutesContact us