Cannot execute binary file exec format error in linux

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:

-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

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 ?

2 Answers 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 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:

and inside that file added following:

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

I reloaded file to apply previous commands:

and after running the java -version everything was okay.

Источник

Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»

В операционной системе Linux при запуске скаченного файла, либо при запуске самостоятельно скомпилированного файла вы можете столкнуться с ошибкой:

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

Если у вас англоязычная локаль, то ошибка будет примерно такой:

bash: ./program: cannot execute binary file: Exec format error

В самой ошибке вместо /путь/до/файла и ./program будет указан путь до файла программы, который вы хотите запустить.

Причинами данной ошибки могут быть:

  • попытка запустить 64-битный файл на 32-битной системе
  • файл скомпилирован для другой архитектуры (например, для ARM, а вы пытаетесь запустить его на ПК)
  • вы пытаетесь выполнить не исполнимый файл, а ссылку
  • файл размещён в совместной (shared) папке
Читайте также:  Linux foundation certified it associate

Чтобы получить информацию о файле, который вы пытаетесь запустить, можно использовать утилиту file, после которой укажите путь до файла:

program: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=03ada11d91d298913990bfc074ccc3a380d26b69, with debug_info, not stripped

Здесь мы видим, что файл предназначен для 64-битной системы, об этом говорит запись 64-bit, для процессора с архитектурой x86-64.

program: ELF-32-bit LSB executable, ARM, EABI4 version 1 (SYSV), dynamically linked(uses share libs), for GNU/LINUX 2.6.16, not stripped

Этот файл для 32-битных систем, для процессора с архитектурой ARM EABI4.

Если вы не знаете, какой битности ваша система, то выполните команду:

Для 64-битных систем будет выведено x86_64, а для 32-битных – x86.

О разрядности дистрибутивов Linux и о программ

На компьютер с 32-битным процессором вы можете установить только 32-битную операционную систему и в ней запускать только 32-битные программы.

На компьютер с 64-битным процессором вы можете установить как 64-битную ОС, так и 32-битный Linux. В случае, если вы установили 64-битный дистрибутив Linux, то в нём вы можете запускать и 64-битные программы и 32-битные. А если вы установили 32-битный дистрибутив, то в нём возможно запускать только 32-битные программы.

Итак, если у вас 32-битная система, а файл для 64-битной системы или даже для ARM архитектуры, то у вас следующие варианты:

  • скачать файл подходящей для вас битности и архитектуры
  • если вы самостоятельно компилировали файл из исходного кода, то заново скомпилируйте для процессора вашей архитектуры

Запуск ARM файлов в Linux

Часто можно запустить исполнимые образы ARM на amd64 системах если установить пакеты binfmt-support, qemu, и qemu-user-static:

sudo apt install binfmt-support qemu qemu-user-static

Заключение

Итак, ошибка формата выполняемого файла с невозможностью запустить бинарный файл возникает из-за несоответствия программы операционной системе или архитектуре процессора. Эта проблема не должна возникать, если вы установили программу из исходных репозиториев (кроме случаев неправильной настройки источников репозитория). При возникновении этой проблемы поищите файл, подходящий для вашей архитектуры или скомпилируйте файл из исходных кодов под архитектуру вашей операционной системы.

Связанные статьи:

Источник

How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu

While it shouldn’t happen when using the official apt-get repositories, if you download software off the Internet and run it then there’s a chance that you’ll see the dreaded bash: ./nameOfProgram: cannot execute binary file: Exec format error. This error, which is usually followed by bash: ./nameOfProgram.sh: Permission denied or something like it, indicates that Ubuntu wasn’t able to interface correctly with the binary you downloaded. This is because while it’s apparently a valid Linux binary, it’s designed for a different chipset than your kernel currently supports.

Most people using Ubuntu are on 32-bit or 64-bit processors based around a standard architecture that Intel released, regardless of who actually made their microchips. It’s important to remember that 64-bit processors can run in 32-bit mode, so if you’re getting this error even though you have a 64-bit processor there’s a chance you’re running a 32-bit version of Ubuntu. A few simple commands are all it takes to tell what your chip is operating as.

Читайте также:  Открыть файл txt линукс

Method 1: Using the arch Command

If you’re not familiar with the type of microprocessor that you have installed on your machine, then you’ll first want to use the arch command from the command line. You’ll only see a single line of output returned to you after running this command. In many cases, you’ll see i686, which means that you’re on a 32-bit processor and therefore can’t run x86_64 binaries. If you instead see amd64 or something similar, then you’re on an x86_64 processor, and should at least theoretically be able to run most 32-bit and 64-bit binaries. Unlike Microsoft Windows, Ubuntu Linux actually contains the proper tools to permit users of 644-bit chipsets to run 16-bit Windows programs in their operating system in many cases as well.

These terms are still true even if you’re not actually using that particular model of microchip. For instance, i686 is how Linux refers to many 32-bit processors even if they aren’t actually Intel 80686 chips. Even if you’re using 64-bit Intel technology, arch might still call your processor an amd64 chip. This doesn’t indicate an error, and can be safely ignored. You can use cat /proc/cpuinfo or more /proc/cpuinfo to find out the exact type of processor you’re using. Since the lines in this file are long, you might want to push F11 before issuing it if you’re using a graphical terminal window. Users of a virtual console, especially those working with Ubuntu server, won’t have to worry quite as much.

You may see some other types of output, which might further restrict your options when it comes to running software. Ubuntu supported PowerPC architecture for the longest time, which is found in some workstations as well as many Classic Macintosh and older OS X Macintosh machines. You can actually still find Ubuntu repositories for these architectures, though they receive little support today. However, you more than likely won’t be able to run many Linux binaries you download from the Internet outside of the official repositories in this case. That doesn’t mean that Ubuntu doesn’t work on these machines, though you may want to look at the lighter Lubuntu distribution.

Method 2: Using the file Command

The file command identifies what different files contain, and it’s usually very accurate. Try identifying the file in question by typing file nameOfProgram to see if you get ELF 32-bit or ELF 64-bit as output. If it tells you that it’s an ELF 64-bit binary and you received i686 as output from the arch command, then there’s no way you can reasonably run it on your machine. If you’re on a 64-bit microprocessor running 32-bit Ubuntu, then you could technically reinstall the operating system, though this is a bit of an extreme step in order to run a single program.

Читайте также:  Командная строка astra linux команды

There is also the very real possibility, however slight, that you might instead come across a binary that when you attempt to run it spews out junk characters to the terminal even if you’ve run a malware scan on it. These characters usually take the form of either lozenge-shaped blocks, or alternatively rectangular cubes that have numerical values in them. Some computer scientists call the latter tofu, and represent the Unicode values of characters that your currently installed typefaces won’t be able to display. If the terminal is displaying them like this, then you can rest assured that this is neither a font error nor anything having to do with malware. Rather, this is simply because the compiled microprocessor opcode inside of the binary is so alien to your system that it doesn’t know how to interpret some of the code.

The best way to fix this is to install the proper package for your architecture. If you’re installing packages from inside Ubuntu, then the apt-get system or the graphical Synaptic manager has you covered without any problems. If you’re downloading packages from another distribution, then you’ll need to find the right one for your architecture. Take, for example, Arch Linux’s listing of the gvim package. While the default package features the x86_64 architecture, there’s also one for the i686 chipset. This one will work on 32-bit machines that work with the Intel interrupt structure, but remember that the terms i686 and 32-bit are not mutually inclusive all the time since other chipsets Linux supports actually do feature their own 32-bit implementations.

Users exploring the whole GNU/Linux scene might come across binaries compiled for far more exotic technologies than these. Linux is truly a cross-platform code scene, so you’ll see OpenRISC, MIPS, SPARC, M32R, MN103, ARM, ARC, Alpha and many other standards binaries are compiled to work with. More than likely, you won’t be able to run any of these, though ARM is an extremely popular tablet and smartphone platform. It’s also the platform that the Raspberry Pi is based around, which means if you’re actually running Ubuntu on a mobile device or the Ubuntu MATE distribution for Raspberry Pi you’ll actually need these instead of Intel 32-bit or x86_64 binaries.

Источник

Оцените статью
Adblock
detector