Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
« Return to the tutorials list
We have updated the website and our policies to make sure your privacy rights and security are respected.
Click here to learn more about the way our website handles your data.

Remove this message.

How to install Node.js and NPM on shared WHM/cPanel hosting account

Daniel Gheorghe Difficulty: 10 / 50 Tweet

How to install Node.js and NPM on shared WHM/cPanel hosting account

I am on a shared hosting plan, but I need Node.js

I've noticed that this is a common query among website owners and/or developers. People need to be able to run various JavaScript tasks on a shared hosting environment so I decided to write this short step by step guide.

Obtain SSH access

The first thing you need to have in order to be able to install Node.js is SSH access to the server. If you already know how to access your server via SSH, skip to the actual installation.

Some hosting providers will allow jailed SSH access upon request, some offer it by default so you might need to post a ticket to be able to log in.

Once you've been given SSH access you can log in by using Putty on Windows or your Terminal on a Mac. If you have Linux I assume you already know how to do that (wink).

Here's how to gain SSH access on a WHM/cPanel shared server.

  1. Log into your cPanel account and click SSH/Shell Access
  2. Fill in the form under Generate new SSH key pair. Make sure you choose a strong key password (better known as passphrase).
  3. Click Generate, copy-paste the "Private Key" into an empty text file and then save it on your computer. (If you are on a Mac or Linux system you can skip to step 11)
  4. On windows, install Putty from here
  5. Once installed, run PuTTYgen.exe and click "Load an Existing Private Key File".
  6. From the dialog dropdown in the bottom-right corner choose all files, select the private key you've saved at step 4 and then save it in a format that's recognized by Putty (*.ppk).
  7. Fire up Putty and from the left panel choose Connection -> SSH -> Auth
  8. Then choose the *.ppk file using the Browse dialog and return to the Session screen.
  9. Type the hostname or IP of your server and the port. Some hosting firms use custom ports so make sure you find out if your port is different from the default 22. Then click connect, type your cPanel username and the chosen passphrase.
  10. (Mac and Linux Only) On a Mac or Linux system, fire up the terminal, navigate to the folder where you've saved you ssh key and type chmod 0600 KEY_FILE_NAME. Then type ssh -i KEY_FILE_NAME -p PORT_OF_SERVER CPANEL_USERNAME@SERVER_HOST. Make sure you replace the capitalized variables with the actual values you need.

Install NVM and the latest stable version of Node.js

  1. Navigate to the NVM repository and get the latest version number from there. Then put it in the command below by replacing VERSION_NUMBER with the most recent version number from Github and execute the command: curl https://raw.githubusercontent.com/creationix/nvm/VERSION_NUMBER/install.sh | bash.
  2. If successful, you will see a bunch of messages showing how to initially configure NVM. Now you need to load NVM by issuing this command: source ~/.bashrc
  3. Finally installing Node JS is done by running nvm install --lts which will install the latest stable version of Node.JS and NPM.
  4. To test type nvm use --lts and then you can issue node -v to see the installed version.

Common pitfalls

  1. If you get an error during installation saying you don't have the required GLIBC version then you need to install an older (potentially unsupported) version of Node.js
  2. To do that, execute nvm ls-remote --lts which will show you all the long term support Node.js versions that exist in the repository. Install an older one by issuing nvm install vX.X.X and then nvm use vX.X.X

That's it! If you have any questions let me know in the comments section.