- Calling java from Bash: «Cannot execute binary file»
- 1 Answer 1
- You must log in to answer this question.
- Related
- Hot Network Questions
- Subscribe to RSS
- Introduction
- Java Oracle Installation /usr/bin/java: cannot execute binary file
- cannot execute binary file: Exec format error while running java 11.0.7-open with sdkman
- 1 Answer 1
Calling java from Bash: «Cannot execute binary file»
I’m getting this error when I try to run the script using build.sh in the MSYS environment under Windows (64-bit!):
./build.sh: ./build.sh: cannot execute binary file
Whatever the problem is, it’s with the script itself and not the command in the script. What text editor did you save the script with, maybe it has lines ending in CR/LF instead of LF?
That’s a weird error message: build.sh is telling you it can’t run build.sh ? What’s the output of file build.sh ?
1 Answer 1
The file was encoded in UCS-2 Little Endian !
Changing the encoding to UTF-8 without BOM resolved the issue.
Msys copes with Windows line endings. Cygwin doesn’t. Neither copes with weird Windows formats that aren’t ASCII-based, such as UCS-2 or UTF-8 with a U+FEFF prepended (which Windows calls a BOM).
@Gilles I’ve just tried it using Cygwin: it doesn’t work — as you said! The problem is that PowerShell adds a CRLF EOL symbol at the end of the file. Here’s my question at SO if someone can help: stackoverflow.com/questions/13135808/…
You must log in to answer this question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.27.43548
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Introduction
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
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
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
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
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 .
Java Oracle Installation /usr/bin/java: cannot execute binary file
Hi I’ve been trying for 1 day to get Oracle Java running on Ubuntu. I have a powermac g5 with Ubuntu 12.04 ppc64. uname -a :
Linux LK37 3.2.0-53-powerpc64-smp #81-Ubuntu SMP Thu Aug 22 21:17:14 UTC 2013 ppc64 ppc64 ppc64 GNU/Linux
david@LK37:~$ sudo lspc [sudo] password for david: sudo: lspc: command not found david@LK37:~$ sudo lspci 0000:00:0b.0 PCI bridge: Apple Inc. CPC945 PCIe Bridge 0000:0a:00.0 VGA compatible controller: NVIDIA Corporation NV43 [GeForce 6600 LE] (rev a2) 0001:00:00.0 Host bridge: Apple Inc. U4 HT Bridge 0001:00:01.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-X bridge (rev a3) 0001:00:02.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-X bridge (rev a3) 0001:00:03.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-Express Bridge (rev a3) 0001:00:04.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-Express Bridge (rev a3) 0001:00:05.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-Express Bridge (rev a3) 0001:00:06.0 PCI bridge: Broadcom BCM5780 [HT2000] PCI-Express Bridge (rev a3) 0001:00:07.0 PCI bridge: Apple Inc. Shasta PCI Bridge 0001:00:08.0 PCI bridge: Apple Inc. Shasta PCI Bridge 0001:00:09.0 PCI bridge: Apple Inc. Shasta PCI Bridge 0001:01:07.0 Unassigned class [ff00]: Apple Inc. Shasta Mac I/O 0001:01:0b.0 USB controller: NEC Corporation OHCI USB Controller (rev 43) 0001:01:0b.1 USB controller: NEC Corporation OHCI USB Controller (rev 43) 0001:01:0b.2 USB controller: NEC Corporation uPD72010x USB 2.0 Controller (rev 04) 0001:03:0c.0 IDE interface: Broadcom K2 SATA 0001:03:0d.0 Unassigned class [ff00]: Apple Inc. Shasta IDE 0001:03:0e.0 FireWire (IEEE 1394): Apple Inc. Shasta Firewire 0001:05:04.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5780 Gigabit Ethernet (rev 03) 0001:05:04.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5780 Gigabit Ethernet (rev 03) david@LK37:~$
bash: /usr/bin/java: cannot execute binary file
At the moment I have Installed jdk-7u25-linux-x64.tar.gz in /usr/lib/jvm/jdk1.7.0/bin/ as said in this post I already tried the web install but I get a 404 error. I hope you can help me. I started using Ubuntu yesterday so please give me the complete terminal code, it will be a lot easier for me. For those who care I want to play Minecraft and with the OpenJDK I got a java.lang error. That’s why I want to install Oracle Java.
cannot execute binary file: Exec format error while running java 11.0.7-open with sdkman
when running java —version or java -jar some_file.jar (specifically ‘SKlauncher 3-beta.15.jar’). Why do I get this error and how to make java work?
.sdkman/candidates/java/current/bin/java: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=092cfbfe7cf2936bdbc489b4ec39bebcff2b0b12, not stripped
Doesn’t look that it’s about 32 or 64 bit. That executable is for x86 (Intel) processors, not for ARM.
1 Answer 1
Not only 32-bit versus 64-bit is important, but also that the JDK is compiled for the ARM-processor. For that reason I prefer to use BellSoft LibericaJDK which has a Raspberry Pi-version and also includes JavaFX in case you want to run a JavaFX UI-application.
E.g. to use JDK 13 on Raspbian OS:
$ cd /home/pi $ wget https://download.bell-sw.com/java/13/bellsoft-jdk13-linux-arm32-vfp-hflt.deb $ sudo apt-get install ./bellsoft-jdk13-linux-arm32-vfp-hflt.deb $ sudo update-alternatives --config javac $ sudo update-alternatives --config java
When this is done, we can check the version again and it should look like this:
$ java --version openjdk version "13-BellSoft" 2019-09-17 OpenJDK Runtime Environment (build 13-BellSoft+33) OpenJDK Server VM (build 13-BellSoft+33, mixed mode)