[Solved]-qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory


qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

If you are running this on an M1 MacBook, it's possible that you are running a native ARM image of Ubuntu instead of the emulated x86 image. If the Elasticsearch distribution you are trying to install is for x86_64, then it attempts to link to the x86-64-native ld.so, which of course isn't present on different platforms.

Either install the package for the ARM platform specifically if they provide one, or - more likely - run Docker explicitly as the emulated x86_64 platform:

        
            docker run --platform linux/x86_64 <image>
        
    

To resolve the error "qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory," you can follow these steps:

  1. First, ensure that the file '/lib64/ld-linux-x86-64.so.2' exists in your system. You can check this by running:
  2. ls /lib64/ld-linux-x86-64.so.2
  3. If the file does not exist, it's possible that your system is missing the necessary linker. You can try reinstalling the glibc package which provides this linker:
  4. sudo apt-get install --reinstall libc6
  5. If you're using a non-Debian based distribution, replace 'apt-get' with the package manager appropriate for your distribution, such as 'yum' for CentOS/RHEL or 'zypper' for openSUSE.
  6. After reinstalling the glibc package, try running your application again to see if the error persists.
  7. If the error still occurs, it's possible that your system is missing other necessary libraries. You may need to install additional packages based on the requirements of your application.
  8. Alternatively, if you're running your application within a container or virtual environment, ensure that the necessary libraries are included in the container or virtual environment image.

I faced the same issue when my Dockerfile specified a generic image name but installed linux/amd64 software. In this instance, you will get an ARM64 (M1) base image (unless you specify a different --platform in your build call), which does not come pre-populated with x86 shared objects.

It will faithfully try to run the x86 (amd64) code through Docker's qemu hypervisor but discover it is missing some basic shared objects that must be architecture-specific.

This means you need to call up your OS package manager and install the x86 shared object packages and make sure they are in your LD_LIBRARY_PATH. The error messages you see will tell you what you need to find.

In my case, using an ARM64 image based on Ubuntu/Debian, I use the 'apt' package manager. In other OS's, you might use 'yum' or 'rpm'. Go to the website for that OS (e.g., packages.debian.org) and search for your library dependencies in their packages, then specify that in your RUN call to build into the image.

For your error, you are likely looking for 'libc6'. Here's how I loaded it, which is an amd64 cross-compile package:

Example Dockerfile entries:

        
            RUN apt-get update
            RUN apt-get install -y wget unzip
            RUN apt-get install -y libc6-amd64-cross

            RUN ln -s /usr/x86_64-linux-gnu/lib64/ /lib64

            ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib64:/usr/x86_64-linux-gnu/lib"
        
    

Many thanks to @CharlesDuffy, as mentioned, the version of optipng-bin I was attempting to install (2.0.0) was shipped with x86_64 libraries and nothing to support ARM. Bumping to 4.2.0 did the trick.

Below step resolved my issue:

        
            FROM ubuntu:focal
            RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
            RUN ln -s /usr/bin/python3.8 /usr/bin/python
            RUN curl -OL https://golang.org/dl/go1.17.linux-arm64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-arm64.tar.gz -C /etc/golang; ln -s /etc/golang/go/bin/go /usr/bin/go; rm -f go1.17.linux-arm64.tar.gz
            RUN GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest; ln -s /root/go/bin/jb /usr/bin/jb
            WORKDIR /workspace
        
    

Dockerfile seems to be the most popular answer, but you can also set the DOCKER_DEFAULT_PLATFORM environment variable to linux/amd64.

        
            export DOCKER_DEFAULT_PLATFORM=linux/amd64