Error during the installation of Java: cannot execute binary file: Exec format error

I have feeling that I messed up something badly, I am a new Linux user, so I was trying to install Java…

So basically the command that I run in terminal is the following:

java -version

Error which I get

-bash: /usr/local/java/jdk-16/bin/java: cannot execute binary file: Exec format error

I was basically following this tutorial, and I might know where's problem, but now I can't find out which one tutorial I followed up, because after I did everything it didn't worked, so I tried another one... And I can't really recall the exact path where I was creating those changes(in which directory). I just know that I was going into /exec/ and there were some other files that I made changes to with nano, I remember that I added something like $JAVA_HOME = .... and then something.

If someone can help, I'd be grateful

1

1 Answer

I actually fixed this problem by doing following:

sudo update-alternatives --config java

This command shows each installation of Java along with its installation path:

Output:
There are 4 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status
------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-16-oracle/bin/java 1091 manual mode
* 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 4 /usr/local/java/jdk-16/bin/java 1 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-16-oracle/bin/java to provide /usr/bin/java (java) in manual mode

I choosed 2nd one and copied the path to it then did following:

sudo nano /etc/environment

and inside that file added following:

JAVA_HOME="/usr/lib/jvm/java-16-oracle/bin/java "

I reloaded file to apply previous commands:

source /etc/environment

and after running the java -version everything was okay.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like