4

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 [email protected] 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!

11
  • I'd highly recommend installing node and npm using yum (as per the docs): sudo yum localinstall --nogpgcheck http://nodejs.tchol.org/repocfg/amzn1/nodejs-stable-release.noarch.rpm and sudo yum install nodejs-compat-symlinks npm. In addition to keeping things up to date, it tends to avoid a lot of the problems encountered when compiling from source.
    – cyberx86
    May 22, 2012 at 2:09
  • @cyberx86 just uninstalled node and reinstalled with yum. Node works, but npm doesn't seem to exist? May 22, 2012 at 2:41
  • If it was installed, it should be in /usr/bin/npm which is a symlink to /usr/lib/nodejs/npm/bin/npm-cli.js. Can you confirm that npm is in fact installed? (I use Amazon Linux and node.js/npm so I can confirm that it should work.)
    – cyberx86
    May 22, 2012 at 2:45
  • @cyberx86 /usr/bin/npm does exist, and so does /usr/lib/nodejs/npm/bin/npm-cli.js. Running npm -v returns -bash: /usr/local/bin/npm: No such file or directory May 22, 2012 at 2:51
  • @cyberx86 and adding /usr/bin to my path gets npm working! :) May 22, 2012 at 2:54

1 Answer 1

3

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.

1
  • 2
    As at Aug/13 the packages on nodejs-tchol.org appear to be unmaintained. They're 2 months and a major version number out of date.
    – Socio
    Aug 13, 2012 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .