HOW TO INSTALL NODE.JS ON UBUNTU 16.04

 In Dedicated, Others, VPS, Web

The installation of Node.js on Ubuntu 16.04, can be done using several different methods:

APT: the default Ubuntu package manager
PPA: Personal Package Manager
NVM: Node Version Manager


1. UPDATE THE SYSTEM

Login to your Ubuntu 16.04 via SSH as user root

ssh root@IP_Address -p Port_Number

and make sure all installed packages are updated to the latest available version

apt-get update && apt-get upgrade

2. INSTALL NODE.JS ON UBUNTU 16.04 WITH APT

Node.js can be easily installed from the official Ubuntu 16.04 repositories using the APT package manager

apt-get install nodejs

To check which version of Node.js is installed on your server run the following command

nodejs -v
v4.2.6

In our case it is version 4.2.6

You should also install NPM to easily manage different Node.js packages

apt-get install npm

Once installed, you can check the version

npm -v
3.5.2

3. INSTALL NODE.JS ON UBUNTU 16.04 WITH PPA

If you need a newer version of Node.js than the one available in the official Ubuntu repositories, you can add a PPA (Personal Package Archive) and install Node.js from this archive.

Install curl if it is not already installed

apt-get istall curl

And download the installation script for the version of Node.js you can to install. In this tutorial we will install Node.js version 8.x.x

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

This will add the PPA and update the package cache. To install Node.js run the following command

apt-get install nodejs

check the installed version

nodejs -v
v8.9.4

Finally, install the build-essential package to be able to use some npm packages

apt-get install build-essential

4. INSTALL NODE.JS ON UBUNTU 16.04 WITH NVM

Instead of using apt, you can also install Node.js with NVM (Node.js Version Manager). With this tool you can install multiple different version of Node.js on your Ubuntu 16.04 VPS.

Install some dependencies

apt-get install build-essential libssl-dev

Download NVM’s installation script

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install.sh

and execute it

bash install.sh

Everything will be installed in a ‘.nvm’ directory inside your user’s home directory and add some necessary lines to the ‘.profile’ file.

Source the .profile file for the changes to take effect

source ~/.profile

Now, run the following command to check all Node.js versions available for install

nvm ls-remote

v8.9.0 (LTS: Carbon)
v8.9.1 (LTS: Carbon)
v8.9.2 (LTS: Carbon)
v8.9.3 (LTS: Carbon)
v8.9.4 (Latest LTS: Carbon)
v9.0.0
v9.1.0
v9.2.0
v9.2.1
v9.3.0
v9.4.0
v9.5.0

To install a specific version use ‘nvm install’ and enter the appropriate version. For example

nvm install v9.5.0

5. LIST ALL INSTALLED VERSIONS OF NODE.JS ON UBUNTU 16.04

If you have multiple versions of Node.js installed on your server, you can list them with the following command

nvm ls
Recommended Posts

Start typing and press Enter to search