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
- Log in to your virtual server via SSH as a root user and make sure it is updated/upgraded.
Connect Linux VPS with SSHapt-get update && apt-get upgrade
- With the following command, you can easily install Node.js through Ubuntu default repositories
apt-get install nodejs
- You also need to install NPM to easily manage Node.js packages
apt-get install npm
- 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
- 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.
- To install Node.js, run the following command
apt-get install nodejs
- Install the necessary packages(build-essential package)
apt-get install build-essential
- 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.
- Install some dependencies and library
apt-get install build-essential libssl-dev
- 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
- Now run the installation file with bash
bash install.sh
- 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
- 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
- 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
- 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
- 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*