Ubuntu 提示sudo: java: command not found解决办法
此文章仅作为备份,原文章请转移:https://www.cnblogs.com/luminousjj/p/8308759.html,尊重原创,侵删~~
今天在配置zabbix用户远程执行命令时,提示如下
zabbix@iZbp1awxcdjhgbb5j29nzvZ:/data/poll_server$ java Command 'java' not found, but can be installed with: apt install default-jre # version 2:1.11-72, or apt install openjdk-11-jre-headless # version 11.0.15+10-0ubuntu0.20.04.1 apt install openjdk-13-jre-headless # version 13.0.7+5-0ubuntu1~20.04 apt install openjdk-16-jre-headless # version 16.0.1+9-1~20.04 apt install openjdk-17-jre-headless # version 17.0.3+7-0ubuntu0.20.04.1 apt install openjdk-8-jre-headless # version 8u312-b07-0ubuntu1~20.04 Ask your administrator to install one of them.
就很奇怪,明明已经在/etc/profile配置了环境变量,然后再sudoer里面添加了以下配置就好了
Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/root/jdk1.8.0_131/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL zabbix ALL = NOPASSWD: ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
再次执行
zabbix@iZbp1awxcdjhgbb5j29nzvZ:/data/poll_server$ sudo java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) zabbix@iZbp1awxcdjhgbb5j29nzvZ:/data/poll_server$ sudo bash /data/poll_server/server_start.sh teamid_3_0.jar is already running. pid=1214388 . teamid_3_1.jar is already running. pid=1214409 . teamid_3_2.jar is already running. pid=1214441 . teamid_3_3.jar is already running. pid=1214478 . teamid_3_4.jar is already running. pid=1214503 . teamid_3_5.jar is already running. pid=1214541 . teamid_3_6.jar is already running. pid=1214581 . teamid_3_7.jar is already running. pid=1214607 . teamid_3_8.jar is already running. pid=1214641 . teamid_3_9.jar is already running. pid=1214669 .
越学越感到自己的无知