Main Tutorials

bash: /usr/bin/java: cannot execute binary file: Exec format error

Run a simple java command on Ubuntu and hits the below errors:

Terminal

$ java -version

bash: /usr/bin/java: cannot execute binary file: Exec format error

P.S Tested with Java 15 and Ubuntu 20

1. Problem – Download the wrong JDK build

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

For example, an AMD processor, based on x86_64 architecture.

Terminal

$ lscpu

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   43 bits physical, 48 bits virtual
CPU(s):                          24
On-line CPU(s) list:             0-23
Thread(s) per core:              2
Core(s) per socket:              12
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model:                           113
Model name:                      AMD Ryzen 9 3900X 12-Core Processor

And we download the Linux/AArch64 JDK build.

JDK Linux AArch64

Try running the java command, and we will hit the below error:

Terminal

$ java -version

bash: /usr/bin/java: cannot execute binary file: Exec format error

2. Solution – Difference between Intel, AMD and ARM processor

Intel and AMD processors are based on x86_64 architecture; The AArch64 is for ARM processor, which is based on ARM architecture.

For Intel or AMD processors on Linux, please download the JDK Linux/x64 build.

JDK Linux x64

For the ARM processor on Linux, please download the JDK Linux/AArch64 build.

JDK Linux AArch64

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
song
3 years ago

very good article

Jesan
1 year ago

thanks