≡ Menu

Installing npm on EC2 – Error “npm cannot be installed without nodejs”

I was playing around with node.js on EC2 the other day and ran into some trouble installing npm. I was getting this error

[]$ curl http://npmjs.org/install.sh | sudo sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
101  7881  101  7881    0     0  94200      0 --:--:-- --:--:-- --:--:--  148k
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

My initial attempt at finding a resolution revolved around trying to update the path env setting used by sudo. After spending some fruitless time on this I switched gears and came across Michael Dillon‘s Stack Overflow post which recommended setting up some symlinks to resolve the path issues.

sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf

Minutes later npm was up and running!

{ 2 comments… add one }

Leave a Comment