Не удается запустить бинарный файл ошибка формата выполняемого файла java


0

2

При попытке установить и/или обновить java выдается

java -version
bash: /usr/bin/java: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла

но судя по всем остальным попыткам посмотреть что с java, она есть

update-alternatives --config java
Есть 2 варианта для альтернативы java (предоставляет /usr/bin/java).

  Выбор   Путь                     Приор Состояние
------------------------------------------------------------
  0            /opt/java/jdk1.8.0/bin/java   100       автоматический режим
  1            /opt/java/jdk1.8.0/bin/java   100       ручной режим
* 2            /opt/jre-10.0.2/bin/java      1         ручной режим

так же пробовал

apt-get install default-jre
Чтение списков пакетов… Готово
Построение дерева зависимостей       
Чтение информации о состоянии… Готово
Уже установлен пакет default-jre самой новой версии (2:1.10-68).
Обновлено 0 пакетов, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 1241 пакетов не обновлено.

как решить не имею ни малейшего понятия

I ran a java executable file using the following command

java -cp .;aa/bb/cc/dd/Main.jar aa.bb.cc.dd.Main

where aa.bb.cc.dd is the package that has all the .java, .class, and Main.jar files
and this package is inside the src folder from where I am running this command.
I am getting an error

cannot execute binary file: Exec format error

Can anyone tell me where I am going wrong.

asked Nov 29, 2014 at 12:52

Learner's user avatar

1

Semi-colon in bash is used to separate commands. So in your case

java -cp .;aa/bb/cc/dd/Main.jar aa.bb.cc.dd.Main

java -cp . and aa/bb/cc/dd/Main.jar aa.bb.cc.dd.Main are considered as two separate commands and executed in sequence.

The issue can be fixed by changing the «;» to «:».

The path delimiter for java class path is «:» and not «;».

answered Jan 27, 2020 at 7:38

Vijayanand Thangavelu's user avatar

Stuck with an annoying error of “Cannot execute binary file“? Then don’t worry. We will provide you with all the working ways which will help you in fixing the problem.

We will also discuss why did the error occurred and similar queries related to it.

Contents

  • 1 What is a Binary file
  • 2 How to resolve cannot execute binary file
    • 2.1 Install GCC and Gfortran library
    • 2.2 Unmatched Architecture
    • 2.3 Download WienHQ for Ubuntu / MacOS
    • 2.4 Provide the permission
    • 2.5 Using dos2unix command
    • 2.6 Uncompress the file
  • 3 What is cannot execute binary file
  • 4 Causes for cannot execute binary file
  • 5 Fix: Cygwin cannot execute binary file
  • 6 Java- Cannot execute binary file
  • 7 FAQs on cannot execute binary file
    • 7.1 How to execute a binary file in Powershell?
    • 7.2 How to rectify “Cannot execute binary file”?
    • 7.3 Fix: Bash cannot execute binary files.
    • 7.4 Raspberry Pi cannot execute binary files.
  • 8 Winding up
  • 9 Trending Right Now

What is a Binary file

Binary means two. The two characters: 1, 0 are repeatedly used to store information and data. The text formats which use this binary format are known are binary format. A format can be changed to decimal, ASCII, BCD, or hexadecimal. We type in the ASCII format, but the computer interprets it in binary format.

A file that is written in binary format is known as a Binary file. The extension is “.bin“. These files can be executed in Linux by the syntax: “./file.bin

How to resolve cannot execute binary file

Try using one of the following methods and check if the nuisance of binary file unable to execute is rectified or not:

Install GCC and Gfortran library

For Linux Operating Systems, type the below code in the PowerShell:

sudo apt-get install gfortran

install-gfotran cannot execute binary file

For installing g++, GCC, and a few more libraries, use the following code:

sudo apt install build-essential

install-build-essential

Check if the error is fixed.

Unmatched Architecture

Open the settings of your computer and check if your system is 32 bit or 64 bit.

Now execute this code to check the architecture format of the specific binary file:

file filename

Try downloading the 32 bt binary file from the internet, if available.

Download WienHQ for Ubuntu / MacOS

If you are trying to execute a binary file made through and for Windows Operating Systems, it may not work directly in your Unix systems. You will have to download a package that can transform an unmodified Windows binary to Unix usable ones.

Use the below link to download the WineHQ

https://wiki.winehq.org/Download

Provide the permission

One more reason for cannot execute a binary file is that the permission is not granted. To fix this, type the below in the PowerShell:

chmod +x filename
./filename

Using the sh command

Try the below syntax:

chmod +x filename.bin

sh filename.bin

Using dos2unix command

In Powershell, use the command:

dos2unix filename.bin

Check if it works out or not.

Uncompress the file

Check if the below line aids in executing the file:

xz -d ./filename
chmod +x ./filename 
./filename  

If your file is in a zipped format, try unzipping the compressed format and executing it as usual.

Remember to place the path address along with the name of the file.

If you download a binary file from the internet and try to execute it in PowerShell, sometimes you may encounter an error known as “Cannot execute binary file.

The Linux Operating System failed to execute (run or open) the specified file you mentioned in the previous line due to technical issues. A few reasons as to why this error has occurred are provided below.

Causes for cannot execute binary file

There can be broadly two reasons for a binary file to show “Cannot execute binary file” error:

  1. The file is an exe file and is compile only for Windows.
  2. The bit architecture of your system and the bin file does not match.

Fix: Cygwin cannot execute binary file

You can use Shell commands in Windows after downloading and installing the Cygwin application.

If you have executed:
C:cygwinbinfilename.exe -h always /bin/bash -l ls

Try this syntax:
C:cygwinbinfilename.exe -h always /bin/bash -l -c ls

cygwin-bash

If still, it didn’t work, try uninstalling and reinstalling all the necessary files of Cygwin again.

Java- Cannot execute binary file

If the Shell or Cmd Prompt window displays an “Exec format error” error, it wants to say that the current version is not compatible with your system.

If you are using AMD/ Intel processes, install the Linux/x64 build from here.

If you are using ARM type of processors: install the Linux-aarch64 build from here.

WineHQ-download

5 Strategies to Fix Adobe Short Media Token Validation Error Invalid Signature

FAQs on cannot execute binary file

How to execute a binary file in Powershell?

Open Powershell.
type the below syntax:
./filename
In place of the filename, you have to type the address and path along with the file’s name.

How to rectify “Cannot execute binary file”?

1. Install the latest version of GCC and Gfortran library.
2. Check if the architecture bit is the same or not.
3. Download WienHQ.
4. Uncompress the file.

Fix: Bash cannot execute binary files.

The Bash (Bourne Again Shell) is a SHELL command interpreter. If you try to execute a binary file (.bin) using Bash, which can not be read due to improper settings or unzipped file, it will display an error of Bash cannot execute the binary file.

Raspberry Pi cannot execute binary files.

Make sure that you have downloaded the correct version and file for your OS.
Try uninstalling and reinstalling the software:

Winding up

We hope that the above solutions might have helped rectify your issue, and your file got executed.

You can ping us anytime to ask us any of your doubts using the comment section available at the end of the page.

Trending Right Now

  • Resolve Error Code E4301 Using These 4 Exciting Methods

    Resolve Error Code E4301 Using These 4 Exciting Methods

    October 20, 2022

  • 15 Incredible Ways to Fix Paramount Plus Keeps Pausing Error

    15 Incredible Ways to Fix Paramount Plus Keeps Pausing Error

    by Amal SantoshOctober 20, 2022

  • 5 Strategies to Fix Adobe Short Media Token Validation Error Invalid Signature

    5 Strategies to Fix Adobe Short Media Token Validation Error Invalid Signature

    by Amal SantoshOctober 11, 2022

  • Fix the Apple TV 4K Turns off by Itself with 7 Wonderful Ways

    Fix the Apple TV 4K Turns off by Itself with 7 Wonderful Ways

    by Amal SantoshOctober 11, 2022

Introduction

This error will occur on linux or Mac systems, when trying to execute any java command such as java -version
In this article, we will understand different reasons why below error

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

might occur and possible ways to resolve it.

Reasons
There might be many reasons of this error such as
1. Java architecture
Architecture of your java binary is different from machine architecture. Example, java binary is 32 bit while your system is 64 bit.
You can check the architecture of java binary with below command

$ file /usr/bin/java

Its output is somewhat as

/usr/bin/java: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c0e68d88922d9aa1c102a8a25adcfce4f958e4f4…

The output shows that the architecture of the Java binary file is 64-bit. You can check if the installed system supports this architecture.
2. Install missing libraries
Java library has dependencies on other files. It might happen that some dependent libraries are missing on your system.
To check the dependencies of java library, use below command

$ ldd /usr/bin/java

The output of this command will show you the dependencies of java library as below

linux-vdso.so.1 => (0x00007fffa1f1a000)
libjli.so => /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/../lib/amd64/jli/libjli.so (0x00007f7b0f2a0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7b0f0a5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7b0eddb000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7b0f4a8000)

If any of these libraries are missing on your system, you will get Exec format error.
Install them using the package manager for your Linux distribution.
For example, to install the libc6-i386 package on Ubuntu, you can use the following command:

$ sudo apt-get install libc6-i386

This command will install 32-bit version of the C library, which is required to execute 32-bit binary files on a 64-bit system.

3. Update java
You can reinstall or update the java runtime environment variable using below commands

$ sudo apt-get update
$ sudo apt-get install default-jre

4. Check permission
Check if java binary file has execute permissions.
You can use the ls command to check the file permissions as below

$ ls -l /usr/bin/java
-rw-r--r-x 1 root root 7867 Feb 10  2023 /usr/bin/java

This output shows that the user does not have execute permissions on java binary.
To provide execute permission, use chmod command as below

$ sudo chmod +x /usr/bin/java

5. Check corrupted file
It may also happen that the java binary file is corrupted or damaged.
To ensure that it is not, use md5sum command to calculate the checksum of java binary as below

$ md5sum /usr/bin/java

Its output will be

3d1e6967b5c0g4j7b1a2efc9d9e3a9iu /usr/bin/java

If the checksum does not match the expected value, the file may be corrupt and you may need to reinstall it.

6. Check for symbolic link
A symbolic link is like a short cut to the actual file.
It might happen that the java command is a symbolic link to the actual binary.
Ensure that it points to the correct location using below command

$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Feb  11  2023 /usr/bin/java -> /etc/alternatives/java

$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 73 Feb  11  2023 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

In this example, the java command is a symbolic link that points to the /etc/alternatives/java file, which in turn, is a symbolic link to the actual binary file.
If either of these links is broken or pointing to the wrong file, you may get the Exec format error message.

To correct the symbolic link and point it to the correct location, use below command

$ sudo ln -fs /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/bin/java

Here,
ln, deletes the old java symbolic link and creates a new one that points to the /usr/lib/jvm/java-11-openjdk-amd64/bin/java file,
-f, option is to overwrite the existing symbolic link, if it exists, and
-s option is to create a symbolic link, rather than a hard link.

Hope this article will resolve the bash: /usr/bin/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

MarianD's user avatar

MarianD

1,0102 gold badges10 silver badges15 bronze badges

asked Apr 2, 2021 at 23:23

Aldin's user avatar

1

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.

answered Apr 2, 2021 at 23:43

Aldin's user avatar

AldinAldin

211 gold badge1 silver badge3 bronze badges

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.

answered Jul 14, 2022 at 20:29

Maicon Mauricio's user avatar

  • Не удается запустить bluestacks произошла непредвиденная ошибка код ошибки 1
  • Не удается записать диск код ошибки 0x8007045d
  • Не удается закончить создание этой подписи ошибка превышения размера
  • Не удается задать пароль причина ошибка 800708c5
  • Не удается загрузить ютуб код ошибки 2