Open source software supply chain lighting plan, waiting for you>>>
Running sudo Java – version reports an error
[ admin@localhost xxx]$ sudo java -version
sudo: java: command not found
Reason:
When using sudo to execute a program, for security reasons, the program will be executed in a new and minimized environment. Environment variables such as path have been reset to the default state under the sudo command. So when a newly initialized path variable does not contain the directory of the program you want to run, and you use sudo to execute it, you will get an error prompt of “command not found”
View the path variable under the sudo command
sudo printenv PATH
/sbin:/bin:/usr/sbin:/usr/bin
Solution:
Set the path used by sudo command to the path of the current shell (recommended)
$ sudo env PATH=$PATH java -version
Alternatively, let the subshell use the path of the current environment (recommended)
$ sudo PATH=$PATH sh -c "java -version"
Or, use the visudo command to modify the configuration of the sudo command for secure path (not recommended)
$ sudo visudo
23558; ect/sudoersDefaults secure path =/sbin:/bin:/usr/sbin:/usr/bin
Defaults secure path =/sbin:/bin:/usr/sbin:/usr/bin:/YourJdkHome/bin
Similar Posts:
- Ifconfig command not found for Linux Installation Errors [How to Solve]
- CentOS Error -bash:systemctl:command not found
- centos Error: sudo gem command not found
- Sudo: Port: command not found Error [How to Solve]
- [Solved] Ls command not found is caused by the configuration of environment variables
- Solution to the error of cscope – Q option in Windows
- -bash: ls: command not found [How to Solve]
- Jenkins – mvn: command not found
- MySQL reports an error using load data local infile
- [Java] deepin solves the problem of picked up in JDK_JAVA_Options:-AWT. Usesystemaafontsettings=gasp