How do you install Node.JS on CentOS?

Solution 1:

su - 
yum install gcc-c++ openssl-devel
cd /usr/local/src
wget http://nodejs.org/dist/node-latest.tar.gz
tar zxvf node-latest.tar.gz
(cd into extracted folder: ex "cd node-v0.10.3")
./configure
make
make install

Note that this requires Python 2.6+ to use ./configure above. You can modify the "configure" file to point to python2.7 in line 1 if necessary.

To create an RPM package, you can use FPM:

# wget http://nodejs.org/dist/node-latest.tar.gz
# tar zxvf node-latest.tar.gz
(cd into extracted folder: ex "cd node-v0.10.3")
# ./configure --prefix=/usr/
# make
# mkdir /tmp/nodejs
# make install DESTDIR=/tmp/nodejs/
# tree -L 3 /tmp/nodejs/
/tmp/nodejs/
└── usr
    ├── bin
    │   ├── node
    │   ├── node-waf
    │   └── npm -> ../lib/node_modules/npm/bin/npm-cli.js
    ├── include
    │   └── node
    ├── lib
    │   ├── dtrace
    │   ├── node
    │   └── node_modules
    └── share
        └── man

Now make the nodejs package:

# fpm -s dir -t rpm -n nodejs -v 0.8.18 -C /tmp/nodejs/ usr/bin usr/lib

Then install and check the version:

# rpm -ivh nodejs-0.8.18-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:nodejs                 ########################################### [100%]

# /usr/bin/node --version
v0.8.18

Source: https://github.com/jordansissel/fpm/wiki/PackageMakeInstall

Solution 2:

If you have CentOS 6.x, and have enabled the EPEL repository, you can use yum to install node/npm:

$ sudo yum install npm

After the installation is complete, check to make sure node is setup properly:

$ node -v

(Should return something like v0.10.36).

If you want later versions of Node.js (e.g. 4.x, 5.x, etc.), you can use the Nodesource yum repository instead of EPEL.


Solution 3:

The gist "Installing Node.js via package manager" does NOT contain instructions for installing nodejs on CentOS any more. Since Fedora 18, nodejs becomes part of the standard repo. I try "epel-fedora-nodejs" repo, and find it no longer update, leaving the version at the outdated 0.6.0.

The good news is that, we have nave, a Virtual Environments for Node, to help us.

https://github.com/isaacs/nave

Installing nodejs is dead easy now.

$ wget https://raw.github.com/isaacs/nave/master/nave.sh
$ chmod +x nave.sh
$ ./nave.sh install 0.8.8
$ ./nave.sh use 0.8.8
$ node -v  
v0.8.8

In the nave.sh file, you may have to change the local urls to the match with the latest dist structure of nodejs. For 0.11.0 I changed the nave.sh to have the following URL

"http://nodejs.org/dist/v$version/node-v$version-linux-x64.tar.gz"


Solution 4:

For CentOS

yum install gcc-c++ make git
cd /usr/local/src/
git clone git://github.com/joyent/node.git
cd node
./configure
make
make install

Solution 5:

[Edit] Thank you David for pointing out in the comments below that the nodejs.tchol.org site is now pointing to a spam site (sic!).. So this answer doesn't work anymore, don't use it!

I can confirm that the method Chris explained in his solution does work in CentOS 5.4 (i've done it a minute ago :))

wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm
yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm
yum install nodejs-compat-symlinks npm

PS: of course you must be root (or use sudo) in order to install that..

Besides installing from source (which is always an option) maybe there is still an alternative: here I read that "node.js has been accepted into Fedora Rawhide as of December 2012 and will be available in Fedora 18.", so maybe it will eventually get into the standard CentOS repositories

I'll have a look at this..