Install NodeJS and NPM on a shared web server

NodeJS can be installed on you CPanel shared hosting plans, keep reading to see how.

$ npm --version

NodeJS download

Visit and copy the link to Linux 64-bit binary.

Connect to your web host via SSH, read this article if you’re not sure how.

Download the binaries to your home directory on the web server.

$ cd ~
$ wget language: JavaScript (javascript)

Extract NodeJS

tar xvf node-v14.5.0-linux-x64.tar.xzCode language: CSS (css)

If your web server doesn’t have have the tools to handle .xz files, as indicated by the error below. You can look at installing xz-utils with apt-get. If your web server doesn’t have apt-get available, try the work around below.

tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting nowCode language: JavaScript (javascript)

Workaround (only if you can’t extract .xz files):

  1. Download the binaries to your local machine
  2. Extract to a folder
  3. Compress the folder using .zip or something else the web server will handle
  4. Upload the compressed file to the web server home directory
  5. Uncompress $ unzip <filename>.zip

Install/Configure NodeJS

Now that you’ve downloaded the Linux binaries and extracted them into the home directory. Rename the extracted folder to something more friendly, such as “nodejs”.

mv node-v14.5.0-linux-x64 nodejsCode language: CSS (css)
mkdir ~/bin
cp nodejs/bin/node ~/bin
cd ~/bin
ln -s ../nodejs/lib/node_modules/npm/bin/npm-cli.js npm

Now verify everything is working.

node --version
npm --version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.