1. Overview

Sometimes, when we want to install or run an application that we download from the Internet or build ourselves, we might get an error that says “bad ELF interpreter: No such file or directory”. In this tutorial, we’ll trace and try to solve what could be causing the error.

We tested the code on 64-bit Debian 10.10 (Buster) and 64-bit CentOS 8.3.2011 running on a 64-bit machine.

2. Introduction to the Problem

The problem usually occurs when we try to run a 32-bit application on a 64-bit operating system:

$ ./binaryfile
bash: ./binaryfile: No such file or directory

Some other Linux distributions (such as CentOS) may give a more meaningful error message:

$ ./binaryfile
ERROR: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Or we might see:

$ ./binaryfile
ERROR: /lib64/ld-lsb-x86-64.so.3: bad ELF interpreter: No such file or directory

We can check if the application is a 32-bit application using readelf:

$ readelf -a binaryfile | grep ELF
ELF Header:
    Class:                           ELF32

If the application is a 32-bit application, then the Class attribute in the ELF Header should say ELF32, and it should say ELF64 for a 64-bit application.

The cause of the “bad ELF interpreter” error is usually because the operating system doesn’t have the support libraries to run 32-bit applications, so we need to install them.

3. Installing Support Libraries for 32-Bit Applications

For the case where it says “ERROR: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory”, ld-linux.so is an ELF dynamic linker or loader that is part of the operating system to load and link the shared libraries needed by the application.

Since the OS cannot find the loader, we’ll install the package that has it, but first, we need to find the package name.

3.1. Finding the Package Name

If we’re using CentOS, we can run:

$ sudo yum provides ld-linux.so.2
Last metadata expiration check: 0:51:38 ago on Sun 29 Aug 2021 10:14:19 PM UTC.
glibc-2.28-151.el8.i686 : The GNU libc libraries
Repo : @System
Matched from:
Provide : ld-linux.so.2

glibc-2.28-151.el8.i686 : The GNU libc libraries
Repo : baseos
Matched from:
Provide : ld-linux.so.2

The package name is glibc-2.28-151.el8.i686.

Or, if we’re using Debian, we first need to install a small utility called apt-file, then download its database:

$ sudo apt-get install apt-file && apt-file update
$ sudo apt-file find ld-linux.so.2
libc6-i386: /lib/ld-linux.so.2
libc6-i386: /lib32/ld-linux.so.2
...

The package name is libc-i386.

3.2. Installing the Package

We can install the pack using dnf install in CentOS:

$ sudo dnf install glibc.i686

And in Debian, we can use apt-get install:

$ sudo apt-get install libc6-i386

Once we’ve installed the package, we can try to rerun the application:

$ ./binaryfile
./binaryfile: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

The error now says it cannot find the shared library libstdc++.so.6.

We’ll trace and install the dependency libraries in the next section.

4. Resolving the Dependency Problem

We can build or download the missing library and put it in the directory where the application can find it — for instance, in the same directory where the application is in or in one of the directories in the PATH variable. After that, we can try to rerun the application:

$ ./binaryfile
./binaryfile: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory

The error says that it cannot find another shared library.

We can keep repeating the process until all libraries are found, but let’s use the readelf tool to list all the libraries that the application needs:

$ readelf -a binaryfile | grep NEEDED
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
...
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]

We can find and install all the packages with the libraries the application needs, just like we did with the first package in the previous section.

5. Conclusion

The error “bad ELF interpreter: No such file or directory” usually occurs because we tried to run a 32-bit application on a 64-bit operating system but our OS doesn’t have the support libraries to run 32-bit applications. To solve this problem, we need to download and install the packages that the 64-bit OS needs for running 32-bit applications.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.