I've installed some of the software under /opt folder by compiling. I've added their "bin" directory to the path inside "/etc/environment". I can also use them as a regular user. For eg: NodeJS 10.15.1 has been installed in /opt and giving
node -v
outputs v10.15.1
.
Similarly if I run the same with sudo,
sudo node -v
I'm getting sudo: node: command not found
.
If I become root by sudo -s
and then execue node -v
, I'm getting
Command 'node' not found, but can be installed with:
apt install nodejs
The reason I want to use "sudo" is, I've installed "Angular" using "npm". And at certain times, ng serve
not reflecting new code changes automatically (which is default behavior of "ng serve" command).
So as pointed out in this post, I want to run this command with "sudo".
Why can't sudo find the executable when it has been added to "PATH"?
sudo /opt/path/to/node
? – rohtua Mar 10 '19 at 08:08export PATH=$PATH:/opt/path/to/node
that's the way I add applications or scripts to my path if they're installed in a custom location. You can do the same for local user as well. You'll have to close the running terminal session and start a new one for the changes to take effect. – rohtua Mar 10 '19 at 08:25sudo
reset the path to safe values ? Try to runsudo echo $PATH
– Soren A Mar 10 '19 at 10:43sudo sh -c 'echo $PATH'
(so that$PATH
doesn't get expanded by the local shell). Howeversudo
searches its ownsecure_path
rather than root'sPATH
AFAIK – steeldriver Mar 10 '19 at 11:41sudo /opt/node-v10.15.1-linux-x64/bin/ng serve --open
"), still showing "/usr/bin/env: ‘node’: No such file or directory". But one thing I don't understand is why paths in "/etc/environment" file is ignored? Why should I do these extra steps? – learner Mar 11 '19 at 08:05