Linux – Trouble with installing npm and supervisor package on Amazon Linux AMI

amazon ec2amazon-web-servicesinstallationlinuxnode.js

I'm running an Amazon Linux AMI and successfully installed node.js by wget'ing the source, untarring the file, and running ./configure and then sudo make install. When I installed npm:

curl http://npmjs.org/install.sh | sudo sh

It outputs:

npm cannot be installed without nodejs.
Install node first, and then try again.

Maybe node is installed, but not in the PATH?
Note that running as sudo can change envs.

PATH=/sbin:/bin:/usr/sbin:/usr/bin

But node is clearly installed (running node -v shows its version), so it must be that node is not in my path.

I open ~/.bash_profile and add this line:

export PATH=/usr/local/bin:$PATH

Then run source ~/.bash_profile

and try to install npm again, only to find that it outputs the same message as last time, which the exact same PATH.

Then, the weird thing is that I notice that npm is actually installed! Running npm -v shows its version. Hm….

Then I run npm install supervisor in the directory of my app, and the supervisor folder is there in /node_modules, however the supervisor command does not exist.

Installing supervisor outputs:

npm WARN prefer global supervisor@0.3.1 should be installed with -g

so I try npm install -g supervisor which outputs

npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/supervisor'
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

so I try sudo npm install -g supervisor

but the output is sudo: npm: command not found

So to sum up, npm seems to be working fine, although the output when installing it would lead one to believe otherwise, and the supervisor package seems like it's installed, but its command is not working.

Any help on figuring this out would be greatly appreciated!

Best Answer

When possible, it is best to avoid compiling packages. In addition to often installing in non-standard locations, software that is compiled from source is much harder to keep up to date. Node.js provides a procedure to install from a repository - which includes npm and some other related components. The repository is kept up to date and is rarely more than a couple of days behind the source code. Moreover, instructions are available for Amazon Linux specifically:

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

npm should install to /usr/bin/npm which is a symlink to /usr/lib/nodejs/npm/bin/npm-cli.js. Of course, with some of the modifications made to your PATH, it is possible that npm may not be found. echo $PATH (as root) should resemble:

/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

One of the common problems when previous installs with npm fail is a corrupted cache - clear your npm cache (npm cache clear) and see if you have any success. Of course, installing a package globally, needs to be done as root.