JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to solve the problem of not being able to execute binary files in Linux

Author:JIYIK Last Updated:2025/03/23 Views:

In this article, we will learn how to execute binary files in Linux. We will also learn how to troubleshoot the error if Linux fails to execute the binary file.

Usually, this error occurs when we run shell scripts in Linux. This article will provide all the working methods to help you resolve this issue.


Linux binaries

In programming, binary means two and a binary file has two characters (1,0). Binary files are used to store information and data.

In Linux, binary files have the extension .bin. Binary files can be executed in Linux using the syntax ./file.bin.

When we execute binary files in Linux system, sometimes we get the error "cannot execute a binary file". This error means that the Linux system does not recognize it as a shell script or executable file.

Let us see how to fix this error in Linux.


Solve the "Cannot execute binary file" error in Linux

The reason could be that the architecture type of the binary does not match. Another reason could be that the user does not have permission to execute the binary.

We will provide you with several solutions to eliminate this problem in Linux. Try one of the following solutions and check if the error is resolved.

Check the file structure

The first thing you need to do when you get this error is to make sure you got the right binary. Because if you have a 32-bit binary and execute it on a 64-bit system, it will not execute and will give you the error.

32 bit binaries will not work on 64 bit systems and vice versa. We can check the architecture of any file in Linux using the following command.

The syntax of the command:

$ file filename

Commands for file structures:

$ file test.sh

Check the file structure

As shown in the figure, we have used the terminal command file test.sh. We can see the architecture of the file named test.sh in the output.

This way, we can also find the architecture of a binary file.

If the architecture of your binary does not match the system you are running it on, you will need to run your binary on a matching architecture system.

Check your binary file format

We run binaries on Windows, Linux, and macOS. Binaries made for Windows will not run on other operating systems, and vice versa.

These binaries have different formats to help users distinguish between them. If you run a binary made for Windows or macOS on a Linux system, it will not work.

You must be on a Linux operating system to run binaries made for Linux.

Installing GCC and Gfortran packages in Linux

If these two packages GCC and Gfortran are not installed in our Linux system, then this may be the reason why our Linux system cannot execute the binary files. These packages (GCC and Gfortran) must be installed in order for multiple binary files to compile and execute correctly.

We can install these libraries using the following commands in our terminal.

Command to install the Gfortran package:

$ sudo apt-get install gfortran

Installing Gfortran package in Linux system

Command to install the GCC package:

$ sudo apt-get install build-essential

Install GCC package in Linux system

After installing these two packages in your Linux system, you can resolve the error of unable to execute binary file.

Try to unzip the binary file

Sometimes we compress binary files to make them easier to share on the Internet. If the binary file you are executing is compressed, try uncompressing the file.

We can decompress the binary file using the following command in the terminal.

Command to unzip the file:

$ xz -d ./filename

Check binary file permissions

Another reason why the binary file cannot be executed on Linux system could be that the user does not have permission to change or read the file binary. We can fix this issue by granting execution permissions to the binary file using the following command in the terminal.

Command to grant execute permission to a file:

$ chmod +x filename

After setting the permissions, we can run the binary using this command in the terminal:

$ ./filename

Use dos2unix command to execute binary files

The best solution to fix the problem of not being able to execute binary files is to use dos2unix command in Linux. This command helps us to run binary files made for DOS on our Linux system.

Command to convert DOS binary files to Unix format:

$ dos2unix filename.bin

After using this command in the terminal, the binary file in DOS format will be converted to Unix format. Then, our Linux system can execute the binary file.

This article explains all the possible solutions to fix the cannot execute binary file error in Linux. We hope you found this Linux article helpful in understanding how to execute binary files in Linux.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Detailed explanation of command return value $? in Linux

Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM

? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re

Common judgment formulas for Linux script shell

Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM

In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –

How to use the Linux file remote copy command scp

Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM

Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial