On EC2: sudo node command not found, but node without sudo is ok

foobar picture foobar · Feb 12, 2011 · Viewed 93.2k times · Source

I have just installed nodejs on a new EC2 micro instance.

I installed it normally, ./configure -> make -> sudo make install.

Problem: When I run "node" under ec2-user, it runs perfectly. When I run "sudo node", it fails.

I found out that node is in:

[ec2-user@XXXX ~]$ whereis node
node: /usr/local/bin/node /usr/local/lib/node

and the current path is

[ec2-user@XXXX ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/ec2-user/bin

but, the sudo path is

[root@ip-10-112-222-32 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

then I tried to edit the root PATH to include the paths to node, so "node" runs when I'm logged in as root - but it still won't work when I log in as ec2-user and run "sudo node".

I need this to install npm properfly. Any idea on how to include the node path while running "sudo node"?

Answer

Michael Dillon picture Michael Dillon · Feb 21, 2011

Yes, it is a bit annoying but you can fix it with some links:

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

There might be more but that is all I have run across so far. Lack of node-waf will cause some npm installs to fail with a rather cryptic error message.