The Wonderful World of Linux A mostly dead cpanel/linux blog

How To Easily Install NodeJS and NPM on Modern Linux Using Pre-Compiled Binaries

Installing NodeJS and NPM using the Precompiled Binaries

This is by far the easiest way to install NodeJS and NPM on modern linux distros. The nice folks at NodeJS have done all the work for you! However, because it is precompiled you may run into some issues but I personally have not experienced any yet. I have tested this on Centos 7 and 8 as well as other RHEL based distros such as Rocky Linux and AlmaLinux. I have also tried this on Ubuntu, but your mileage may vary.

Installing the latest cutting edge node

cd /usr/local/src

latestnode=$(curl 2>1  | grep linux | sed -e 's/<[^>]*>//g' | awk '{print $1 }' | grep $([[ $(getconf LONG_BIT) = 64 ]] && echo x64 || echo x86)  | grep tar.gz)
tar xzf $latestnode
cd $(echo $latestnode | sed -e 's/.tar.gz//g')

sudo rsync -Pav {bin,include,lib,share} /usr/

We first start by switching into our src directory. I like doing this as having random source files spread out in /root and /home can be awfully messy. The very next line is a fancy wget statement that curls the nodejs latest folder (from their web), grep’s for linux, strips out the html and then greps for whichever result matches your architecture and then downloads it! Pretty fancy! Following this we cd into the newly untarred directory and simply rsync the binary and library files. Thats it! You can verify by running the following:

node -v ; npm -v

If its copied correctly, those commands will not error out.

Installing LTS version of Node*

Coming Soon!