How to install Node.js on Ubuntu 16.04

How to install Node.js on Ubuntu 16.04

As you know, Node.js is an open-source JavaScript platform based on the Google V8 JavaScript engine and can be used to create a variety of server-side applications. This platform can be run on various operating systems such as Linux, OSX and Windows. In this article, we will try to describe how to install Node.js on the Ubuntu 16.04 virtual Linux server. Installing Node.js on Ubuntu can be done in a number of ways. Here we gonna explain Node.js installation step by step with APT(Ubuntu default package manager), PPA(Personal Package Manager), and also NVM(Node Version Manager).

Install Node.js on Ubuntu using APT

  1. Log in to your virtual server via SSH as a root user and make sure it is updated/upgraded.
    Connect Linux VPS with SSH

    apt-get update && apt-get upgrade
  2. With the following command, you can easily install Node.js through Ubuntu default repositories
    apt-get install nodejs
  3. You also need to install NPM to easily manage Node.js packages
    apt-get install npm
  4. Check the installed Node.js and NPM version
    nodejs -v
    
    v4.2.7
    npm -v
    
    3.5.2

Install Node.js on Ubuntu using PPA

  1. If you need a new version of Node.js, you can install it from the available repositories in the official Ubuntu PPA. Here we want to download Node.js using curl directly, If the curl is not installed, then install it first.
    apt-get install curl
    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

    Note: This will add PPA and package upgrades.

  2. To install Node.js, run the following command
    apt-get install nodejs
  3. Install the necessary packages(build-essential package)
    apt-get install build-essential
  4. Finally, See the installed Node.js version
    nodejs -v
    
    v8.9.6

Install Node.js on Ubuntu using NVM

You can also install Node.js with the help of NVM (Node.js version manager). With this tool, you can install multiple versions of Node.js on Ubuntu.

  1. Install some dependencies and library
    apt-get install build-essential libssl-dev
  2. Download the NVM installation version using the following command
    curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install.sh
  3. Now run the installation file with bash
    bash install.sh
  4. In this case, anything inside the .nvm directory will be installed in the Home directory too. To apply the changes in .profile file, make it the source
    source ~/.profile
  5. Now you can run the following command and check all available Node.js versions
    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
  6. To install a specific version of Node.js, you can use the following command and add the desired version to the end
    nvm install v9.3.0

List all versions of node.js installed

If you have installed multiple versions of this platform on your Ubuntu VPS, you can use the following command to list them out

nvm ls

Uninstall and Remove the Node.js completely

  1. Run the following code in the Linux terminal

    sudo apt-get remove nodejs 
    sudo apt-get remove npm 
    sudo apt-get purge --auto-remove nodejs
  2. Navigate to the path where you saved the Nodejs file and then delete the file from that path.
    sudo rm -rf /usr/local/lib/node*

 

 

 

Was this post helpful?

About the Author

Leave a Reply

four × 5 =