Install npm on CentOS 6 Using install.sh

Install npm on CentOS 6 Using install.sh

npm

How to install npm on CentOS 6 minimal using the install.sh script, including a workaround for the missing which command.

Prerequisites

you need to have Node.js installed, configured and working. How to install Node.js on centos 6.3. also, check you have curl installed:

yum install curl

The problem

npm can be installed using rpm or repo but there are situations where you might want to install npm using the install.sh script. CentOS minimal doesn’t include the ‘which’ command.

npm install.sh patch

because the install.sh script uses the command ‘which’, you need to create a patch. create a ‘which’ file in your /bin directory and add inside:

#!/bin/bash whereis $1 | cut -d " " -f2

and run:

cd /bin alias which=./which chmod +x which

check with ‘which node’ which should return ‘/usr/bin/node’ if you installed node.js using the rpm or repo.

finally, run the following:

cd /tmp curl -s http://npmjs.org/install.sh > npm-install-$$.sh sh npm-install-xxxx.sh

For me, it was npm-install-4691.sh, but it could be with other name.

You can now use the install.sh script on your CentOS minimal.

Happy coding.