0

I've been tasked to work on updating a Java program that hasn't been touched for years and I'm running into issues building it using the latest version of Java OpenJDK 14.0.1.7-2 on Centos 7. When I run the $ make all command to start compiling the Java program I get a /bin/sh: javac: command not found error message.

I've edited the .bash_profile file in my home directory and added:

export JAVA_HOME=/usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64/bin/java

Followed by: $ source .bash_profile to make the changes take effect and verified using echo $JAVA_HOME which gives me the expected output, but still no luck.

So far I'm only able to successfully build the program when Java OpenJDK 1.8 is installed along with with the additional javac repository.

Running the alternatives --display javac I get this on the final line:

Current `best' version is /usr/lib/jvm/java-1.7.0-openjdk 1.7.0.261-2.6.22.2.el7_8.x86_64/bin/javac.

This is strange to me as I have not installed Java OpenJDK V1.7 on my system

Running the alternatives --display java I get this on the final line:

Current `best' version is /usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64/bin/java.

Any suggestions on where I'm going wrong would be much appreciated.

5
  • You can help answerers by putting the outputs of alternatives --display java and alternatives --display javac in your question. A related question is unix.stackexchange.com/q/598351/5132 .
    – JdeBP
    Aug 7, 2020 at 18:02
  • 1
    Keep in mind, you need the java-latest-devel package if you want javac.
    – jsbillings
    Aug 9, 2020 at 0:58
  • Thanks for responding @JdeBP so by running your first command the final output message is Current best version is /usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64/bin/java which is what I'm expecting as it's the only version of Java I have installed, however with your second command I get Current best version is /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64/bin/javac which is odd as Java OpenJDK v1.7 was removed from my system using the Yum Extender package manager
    – user427317
    Aug 10, 2020 at 8:27
  • Thanks for responding @jsbillings I have java-latest-openjdk , java-latest-openjdk-devel and java-latest-openjdk-headless installed on my system and all of these packages are referring to the OpenJDK development tools 14
    – user427317
    Aug 10, 2020 at 8:31
  • In the question, not in comments. It's not legible in comments.
    – JdeBP
    Aug 10, 2020 at 10:17

2 Answers 2

0

A couple of things, i noticed in your JAVA_HOME environment variable you have the path to an actual bin, try changing that to this:

JAVA_HOME=/usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64/

You might wish to check the PATH environment variable too, use the following command:

find /bin/ /sbin/ /usr/sbin /usr/lib /usr/bin/ /usr/local/bin /usr/local/sbin ${HOME}/ /opt/ -type f -name 'javac' -exec dirname "{}" \;

IF that finds something export PATH=${PATH}:whatever-result-you-get-from-that or simply:

export PATH=${PATH}:$(find /bin/ /sbin/ /usr/sbin /usr/lib /usr/bin/ /usr/local/bin /usr/local/sbin ${HOME}/ /opt/ -type f -name 'javac' -exec dirname "{}" \;)

3
  • JAVA_HOME is always the path without the bin directory, e.g. export JAVA_HOME=/usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64 and export PATH=$JAVA_HOME/bin:$PATH
    – Freddy
    Aug 7, 2020 at 22:04
  • Thanks for responding @linuxgeek I've updated my JAVA_HOME as you listed and added the export PATH=$JAVA_HOME/bin:$PATH below. There was already an export PATH line in the .bash_profile. Is it ok to have two different lines of export path? Additionally your find command returned no results before and after I updated my environment variables.
    – user427317
    Aug 10, 2020 at 8:21
  • Yes, it is fine to have multiple PATH lines, the PATH env var i listed takes the old path and adds on to it. Just make sure the second one that includes that path is after the first one. As for the find I was only checking in bin directories, adjust the find command to have /usr/lib/ and it would return the path to javac but it looks like you're getting it figured out.
    – linuxgeek
    Aug 10, 2020 at 16:26
0

That the alternative for javac points to something that you say isn't currently installed indicates that the simplest answer is to update the alternative so that it points to a JDK that is installed. This will re-point the symbolic links so that /usr/bin/javac points to an actual executable again, and a PATH search for javac will work once more. No actual PATH change is needed.

alternatives --config javac

is the interactive way to do this, or alternatively

alternatives --auto javac

Further reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .