Install QEMU User Space Emulator on Ubuntu 26.04

Install QEMU User Space Emulator on Ubuntu 26.04

QEMU User space emulator provides the ability to run binaries compiled for different CPU architectures on a host system. It is commonly used for cross-architecture testing and software validation. This tutorial demonstrates how to install QEMU User space emulator on Ubuntu 26.04.

Install QEMU User

Run the following command to update package lists:

sudo apt update

Install the QEMU User package:

sudo apt install -y qemu-user

The package installs emulators for various architectures. To confirm successful installation, version checks can be performed for a few commonly used emulators:

qemu-aarch64 --version
qemu-riscv64 --version
qemu-loongarch64 --version

Testing QEMU User

Download the aarch64 (64-bit ARM) architecture binary for testing purposes:

curl -sSLo yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_arm64

Grant execute permissions to the binary:

chmod a+x yq

Create a sample YAML file:

printf "status: success\ndata:\n  - name: John\n    age: 25\n  - name: James\n    age: 29" > test.yaml

Attempt to execute the aarch64 binary directly:

./yq e '.' test.yaml

Running the binary directly produces a result indicating that execution is not possible on the host architecture:

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

Run the binary through the QEMU User space emulator:

qemu-aarch64 ./yq e '.' test.yaml

Expected result:

status: success
data:
  - name: John
    age: 25
  - name: James
    age: 29

Uninstall QEMU User

If decided to uninstall QEMU User space emulator and clear unnecessary dependencies, run the following command:

sudo apt purge --autoremove -y qemu-user

Leave a Comment

Cancel reply

Your email address will not be published.