Linux – Fix Bash: ./program: Cannot Execute Binary File: Exec Format Error

bashlinuxUbuntu

When I run the command

./program 

I get the error:

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

When I run uname -a I get:

4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016 i686 i686 i686 GNU/Linux

Also I checked the information about the program that I was trying to run and I got:

ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=c154cb3d21f6bbd505d165aed3aa6ed682729441, not stripped

/proc/cpuinfo shows

flags       : fpuvme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts

How can I run the program?

Best Answer

You have a 64-bit x86 CPU (indicated by the lm flag in /proc/cpuinfo), but you’re running a 32-bit kernel. The program you’re trying to run requires a 64-bit runtime, so it won’t work as-is.

If you can find a 32-bit build of the program (or build it yourself), use that.

Alternatively, you can install a 64-bit kernel, reboot, and then install the 64-bit libraries required by your program.

To install a 64-bit kernel, run

sudo dpkg --add-architecture amd64
sudo apt-get update
sudo apt-get install linux-image-generic:amd64

This will install the latest 64-bit Xenial kernel, along with various supporting 64-bit packages. Once you reboot, you should find that uname -a shows x86_64 rather than i686. If you attempt to run your program again, it might just work, or you’ll get an error because of missing libraries; in the latter case, install the corresponding packages (use apt-file to find them) to get the program working.

Related Question