Typically, a custom path is selected by compiling the installation or binary copy of the software path, taking the Nodejs software as an example, such as:/usr/local/node6.10/bin. Command not found will be prompted at this time when running with the sudo command. This problem occurs because there is a configuration in the/etc/sudoers configuration file:
Defaults Secure_path =/sbin:/bin:/usr/sbin:/usr/bin
As a result, there is no path to our custom installation software in the default path, so node cannot be found. We just need to add the path of node to the line behind it.
Defaults Secure_path =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/node6.10/bin
There are several other solutions:
1): Use the absolute path of the command.
2): Use sudo's env option, like this sudo env path= $PATH cmd.sh.
3): Copy or link the script to the system $path.
4): Re-compile sudo with no –with-secure-path option. (Ultimate solution).
The above method, please refer to the use of which, I prefer the first introduction of the kind, more controllable, and more convenient to use.
The Linux system uses sudo to handle a situation where command not found is encountered