What is Node.js ?
Initial Set Up
For the installation of Node.js, you will have to install the curl and compiler on your droplet. Before starting the installation, run an apt-get update as given below:
sudo apt-get update
Once the update is completed, you can go ahead and install compiler on your VPS.
sudo apt-get install build-essential
If you don’t have curl on your system, make sure you download it right away, as it’s required to perform the installation.
sudo apt-get install curl
Once you have these two components, curl and compiler, you are all set to install Node.js.
Installation of Node.js and Node Package Manager
According to the official documentation in their website, there are many ways to install Node.js. In this tutorial, I am using a particular method which I found easier and straight forward.
As the first step, change the paths to include the commands from the ~/local/bin directory.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
Follow up by sourcing .bashrc file as shown below:
Now, you have to create two new directories for the installation:
mkdir ~/local mkdir ~/node-latest-install
Navigate to the latest-install folder.
After that, run the curl to get the node.js tarball and untar it.
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
Once it is finished, you can start the installation process for the local user. This ensures that you will not need sudo later.
Now, run the command make install. Make sure that you don’t interrupt as it takes a while to install.
You can finish up by downloading the npm through curl:
curl -L https://npmjs.org/install.sh | sh
Once it’s done, you can quickly verify the version installed on your vps.