Install Node.js on CentOS 6.2

Posted on: by

The install of Node.js is pretty straight forward, with on gotcha when it comes to installing node packages that I will detail at the end.

If you haven’t already installed developer tools, you will need to do that now.

sudo yum groupinstall 'Development Tools' 
sudo yum install openssl-devel 

Now install Node.js.

wget -O - http://nodejs.org/dist/v0.6.18/node-v0.6.18.tar.gz | tar xzvf - 
cd node-v0.6.18/ 
sudo make install 

Problem installing node packages with sudo

To install node packages you have a little problem if you are using sudo. On CentOS 6.2 (and probably versions less than this), sudo has a secure path set secure_path = /sbin:/bin:/usr/sbin:/usr/bin. This is a problem because npm is installed in /usr/local/bin by default and sudo does not have access to that location in it’s path.

This is easy to fix if you have root access on your server, WARNING: this may make sudo less secure, so make sure you understand your system and it’s security needs before changing this.

To make this change you must use visudo to change the line Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin . This will take care of the problem now you can install packages using sudo like normal.


Tags: ,