2

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
  • Please edit your question to include the outputs of commands file /usr/local/java/jdk-16/bin/java and uname -m. Why are you trying to install java by any other means than apt? Apr 2, 2021 at 23:37

2 Answers 2

2

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.

1

From mkyong's blog:

1. Problem – Download the wrong JDK build

The error Exec format error means we download the wrong JDK build for a specific platform.

Download the appropriate JDK for your CPU architecture.

In my case, I dowloaded the one with suffix aarch64 by mistake. Instead it was x64 as usual.

Run lscpu to find the cpu architecture.

You must log in to answer this question.

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