1

I am on CentOS 7.5 and installing OpenJDK 11 from Adopt OpenJDK. It doesn't have an installer package so I am manually putting it in /usr/share. I then create the file /etc/profile.d/java.sh to set up JAVA_HOME and put the java executable on the path. When I run java -version from my own account it works fine. When I run sudo java -version it says java: command not found. Every time I try to search if someone else has had this problem I just keep getting the responses to create the /etc/profile.d file. Any ideas?

This is a fresh install of CentOS 7.5 on an Azure VM.

  • Does sudoers on Centos use a secure_path? – steeldriver Aug 26 '19 at 18:32
  • I don't know. I never heard of secure_path. But when I run sudo echo $PATH it shows the correct path. – markbernard Aug 26 '19 at 18:50
  • 1
    It will show you your current path because the $PATH valuable is evaluated before sudo is run. The net effect is that sudo sees something like sudo echo /bin:/usr/bin:/usr/share/jdk/bin, which isn't what you're trying to do. – roaima Aug 26 '19 at 19:27
  • @steeldriver I'm away from my servers at the moment but I'm pretty sure CentOS does. – roaima Aug 26 '19 at 19:28
  • @markbernard you might try running sudo -l and looking for a line containing secure_path – steeldriver Aug 26 '19 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.