If you have VPS web hosting, then you have access to Node.JS (Node), a powerful tool to create and run network applications. Node is the N in the MEAN Stack, one of the most popular web stacks used with VPS hosting.
Along with Node, you’ll get the node package manager (npm), giving you access to the most extensive set of open source libraries in the world.
Special Note: If node.js is a must for you, make sure to find a web host that fully supports it. While most hosting services only support Node.js on their VPS plans, some, like FastComet also offer it in shared plans. You can find this information and more on HostAdvice’s Node.js hosting reviews page.
Section 1 – Install the Long-term Support (LTS) version of Node
While apt-get is a useful package manager, it does not reliably install the latest stable version of Node for Ubuntu. Instead, install from the NodeSource Debian and Ubuntu binary distributions repository (formally known as Launchpad PPA). The LTM of Node is 8.x for Linux and will be until December of 2019.
Step 1 – Update Your VPS
If you’re using an Ubuntu virtual server, update the package index.
$ sudo apt-get update
If you’re using a CentOS virtual server, update your virtual server.
$ sudo yum check-update $ sudo yum upgrade $ sudo yum clean all
Step 2 – Install Node in Your Home Directory
Logged in as the user with which you’re going to use Node, go to your home directory if you’re not already there.
$ cd ~
Verify that you are currently in your home directory.
The print working directory (pwd) command should return a path ending with your username, indicating your current working directory is your home directory.
Step 3 – Install Node
Pipe together these three commands to download and install the latest stable Node version for Ubuntu 16.04, which is 8.x until December of 2019.
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash | sudo apt-get install -y nodejs
Step 4 – Install Build Essential
As the name suggests, Build Essential includes some important packages. It’s likely that you installed it with the process above but to make sure, install Build Essential.
$ sudo apt-get install build-essential
Step 5 – Check the Version Number of Node
You’ll want to check the version number of Node and the nvm to make sure you’ve installed Node.js version 8.x and npm version 5.x.
$ nodejs -v
The version number should return 8.x. The key is that the version starts with an 8 as 8.x is the Long-term Support (LTS) version of Node and will be the LTS until December of 2019.
Then, check the version number of the node package manager (npm).
$ npm -v
It should return 5.x.
You’ve now successfully installed the latest stable release of Node.js and the npm for Ubuntu 16.04. You have now added a powerful tool to your VPS web hosting.
A good next step would be to <Create a Simple Web Server Using Node.js On Your Linux Virtual Server> as a way to understand the basics of how Node.JS works on the backend.
Check out the top 3 Node.js hosting services:
- Learn here about the best Node.js hosting providers
- Click this link and all your queries to best hosting will end.