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

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


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

sudo ln -s /usr/local/bin/node /usr/bin/nodesudo ln -s /usr/local/lib/node /usr/lib/nodesudo ln -s /usr/local/bin/npm /usr/bin/npmsudo 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.


I added /usr/local/bin to secure_path in /etc/sudoers

$ sudo visudo

Then change this line:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

To:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin


it happens because the node executable is not found in /usr/bin. So follow the steps:

  1. find node:

whereis node

in my case: node: /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node

  1. make a symbolic link for node:

    sudo ln -s /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node /usr/bin/node

It's done!