Photo by Jivacore/Shutterstock.com
Linux has been reworked heavily since it first came out to the point that it’s no longer an OS for terminal kings. Just about everyone can use it now thanks to the much better user interfaces that we see in modern Linux distros. However, that doesn’t mean it can’t be frustrating at times.
In this article, we’re taking a look at the “cannot execute binary file: exec format error” issue and giving you a few solutions on how to get rid of the problem.
Also read: How to make a file executable in Linux?
Check the architecture
The first thing you should do is ensure you’ve got the right bin file. Binary files made for 32-bit systems won’t work on 64-bit systems and vice-versa. You can check the architecture of any file by using the command below.
If the architecture doesn’t match between your file and the PC you’re running it on, try running the corresponding binary file for the matching architecture.
Check the file
Binary files can be run on Windows, Linux and macOS. However, binaries made for one OS won’t run on the others. Generally, these files have different file formats to help users distinguish between them. If you’re trying to run a binary file made for Windows on a Linux distro, it’s obviously not going to work.
If you must run the binary on Linux however, we recommend downloading Wine and using it to run the file. Wine is a compatibility layer capable of running Windows applications on POSIX-compliant operating systems, including Linux and macOS.
Install GCC and Gfortran
GCC and Gfortran are required for several binary files to compile and execute properly. You can install them by typing the command below in your terminal.
sudo apt-get install gfortran && sudo apt-get install build-essential
Now try running your binary file again and it should run without a problem — fixing the ‘cannot execute binary file’ error.
Uncompress the file
Sometimes binary files are compressed to make them easier to share over the internet. Try uncompressing the file to see if that helps you run it fine. Run the following commands on at a time.
xz -d ./filename chmod +x ./filename ./filename
Check file permissions
Another potential reason for your binary file not running could be that the user doesn’t have permission to change or read the file. You can fix this by typing the following command in the terminal.
chmod +x filename
Once the permissions are set, you can run the file by typing this.
The Dos2unix command can sometimes help binaries made for DOS to run on UNIX systems. Try using the following command to see if your file runs or not.
If we’ve missed out on any fixes that helped you solve the ‘cannot execute binary file’ error, please comment down below with the fix.
Also read: What does ./ mean in Linux?