Compile batocera.linux

The official and recommended way to compile batocera.linux is by using a development container made on purpose with Docker. Although you can do it directly on your Linux machine, if it's a supported Ubuntu Linux.

Note that it's also possible to compile batocera.linux within an LXC container but it's not recommended or officially supported.

If you are not familiar with git, you should first take a look at this page explaining the basics for contributing to Batocera Linux with git.

Choose either Docker or Direct Compilation.

Make sure you have a reasonably fast CPU, and at least 8GB of RAM (even 12GB+ if you need to compile MAME). If you have a CPU with 8 cores or more (lucky you!), you might need more than 8GB RAM to compile batocera.linux with all threads in parallel. You also need between 80GB and 130GB of free disk space for each platform you intend to compile for in order to download and compile the final Batocera image.

The x86_64 version is the largest, downloading packages and building them takes up to 130GB.

If compiling inside of a VM, you may need to set its CPU type to host to avoid “missing CPU instruction” errors like #error PCSX2 requires compiling for at least SSE 4.1.

If you already have a working Docker installation on your Linux system, you just need to install git (if you don't have that already as well), and skip to the preparations section.

Otherwise, the first step is to install Docker on your machine. Each OS and Linux distribution has a particular way to install Docker.

Please note that most developers use Ubuntu Linux to compile batocera.linux. In October 2018, Docker on Windows is not stable enough to compile Batocera.

In March 2020, with the Docker container running as non-root (regular user), you can compile Batocera on MacOS Mojave 10.14 (Darwin 18.0.0).

Once Docker is installed, you have to get it up and running (depending on your OS, for Linux Solus or Arch Linux for example, you would start it up with sudo systemctl start docker.service and make sure that your user is in the docker group).

Git is used to download the batocera.linux sources, outside of the docker container.

The way to install the necessary packages vary for each Linux distribution. You can find the necessary packages for Ubuntu below.

* Ubuntu 18.04 (might still work with 16.04 too)

 sudo apt-get install build-essential git libncurses5-dev libssl-dev mercurial texinfo zip default-jre imagemagick subversion hgsubversion autoconf automake bison scons libglib2.0-dev bc mtools u-boot-tools flex wget cpio dosfstools libtool
 sudo dpkg --add-architecture i386
 sudo apt-get update
 sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

* Ubuntu 20.04 (Includes requirements for some experimental packages)

 sudo apt-get install build-essential git libncurses5-dev libssl-dev mercurial texinfo zip default-jre imagemagick subversion autoconf automake bison scons libglib2.0-dev bc mtools u-boot-tools flex wget cpio dosfstools libtool gcc-multilib g++-multilib python3-pip
 sudo dpkg --add-architecture i386
 sudo apt-get update
 sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

pip3 install conan

Choose a work directory (your $HOME?) and clone the batocera.linux source code:

git clone

Enter the newly created directory.

 cd batocera.linux

By default, the buildroot submodule will not be cloned. This is required for Batocera, run the following:

 git submodule init
 git submodule update

You only need to do this once.

Depending on the target you want to build Batocera for, you need to select one of the batocera-XXXXX_defconfig files, where XXXX has to be replaced with the architecture you are building to. Available ones are:

  • rpi1
  • rpi2
  • rpi3
  • rpi4
  • rpizero2
  • cha (capcom home arcade)
  • odroidxu4
  • rk3326 (odroid go advance/super and clones)
  • rk3288 (miqi, tinkerboard)
  • rk3399 (rockpro64 and clones)
  • gameforce
  • orangepi-pc
  • orangepi-zero2
  • x86_64
  • x86 (32 bits, old PCs)
  • s812
  • s905 (odroid c2)
  • s905gen2
  • s905gen3
  • s912
  • s922x (odroid n2)
  • tritium-h5

You can find them all listed in the configs directory.

To make things easier, there is makefile described here that makes the compilation process smoother.

1. Install build environment

 make batocera-docker-image

2. Customize directories

By default, Batocera will download dependencies to $(PROJECT_DIR)/dl and build to the $(PROJECT_DIR)/output folder. You can check the current default directories with the following command:

 make vars

To change the directories that Batocera will build to, rename the file to and change the DL_DIR ?= and OUTPUT_DIR ?= lines to point to wherever you want to.

I recommend you disable tracking of changes in that file with:

 git update-index --assume-unchanged

3. Build an image

Command is different for each target architecture, but share the same suffix like make rockpro64-build or:

 make x86_64-build

You can check valid targets architectures with make vars.

4. Shell

It's also possible to get a shell to the desired build environment. Similar to -build, with make rockpro64-shell or:

 make x86_64-shell

5. Build a single package

To build a single package, you can open a shell or use the -pkg target. Examples:

 make rk3326-pkg PKG=batocera-splash
 make x86_64-shell PKG=libretro-mame

6. ccache

To enable ccache for all builds, add the necessary options to An example is provided there. See EXTRA_OPTS. No need to edit defconfig.

7. Compile clean builds

 make x86_64-cleanbuild

8. Build a webserver to upgrade your Batocera

You can easily upgrade your Batocera test machine with the build you have just compiled. Let's imagine your build box's IP address is If your build machine has Python3 installed, you can run a webserver with:

 make x86_64-webserver

Then, you can launch an upgrade from your Batocera test box. If your build box hosting the web server is on, you can simply upgrade to your freshly brewed build by entering from your Batocera SSH:


Of course you can still use out of tree builds to compile Batocera. So, for x86_64, you can do the following:

make O=$PWD/output/x86_64 BR2_EXTERNAL=$PWD -C $PWD/buildroot batocera-x86_64_defconfig
cd output/x86_64

Source tree will stay pristine and we be reused for other builds following the same procedure with a different output directory. For example:

make O=$PWD/output/rpi3 BR2_EXTERNAL=$PWD -C $PWD/buildroot batocera-rpi3_defconfig
cd output/rpi3

Then, you can take some time for a coffee (or two, or two hundreds actually). Depending on how powerful your CPU is, how much RAM you have, and how fast your SSD/HDD is, compiling a whole Batocera system can take many hours. Don't forget, it's the full OS with all the emulators that we are compiling here, it's not a small task.

Please also mind that the process will take a significant amount of space, so ensure to have between 50GB (RPi) and 150+GB (x86_64) of free space on that partition.

Exit the container if you ran the build inside of it.

The output will be under output/images/batocera and will be gzipped. Its name contains the release version, the platform, and the build date. For instance: output/images/batocera/batocera-5.25-x86_64-20200221.img.gz

You can then flash it with Etcher by following the instructions or by using dd if you don't want to leave the command line:

gunzip output/images/batocera/batocera-XXXX.img.gz
dd if=output/images/batocera/batocera-XXXX.img of=/dev/**yourtargetdevice** status=progress

You can download sources from Internet before compiling by running the following command, assuming you started with x86_64:

cd output/x86_64
make source

Personally, I even run it during 10 minutes and then run make in parallel.

If you want to check on the current status for your x86_64 build:

tail -f output/x86_64/build/build-time.log

If you ran make source, you can easily find what's remaining to compile by running :

for i in output/x86_64/build/*; do test -d "$i" && test -e "$i"/.stamp_built || echo "$i"; done; for i in output/x86_64/build/*; do test -d "$i" && test -e "$i"/.stamp_built || echo "$i"; done | wc -l
docker run -it --rm -v $PWD:/build -v $HOME/dev/batocera/DL:/build/dl batocera-docker
docker image ls
docker rmi <image_name> or docker image rm <image_name>
docker ps
docker kill [container name]

Follow this page to know more about the structure of the Batocera source code and where your modifications need to be made.

Add --security-opt seccomp:unconfined to your docker command line or update the libseccomp2 package

As of February 2020, it looks like this step is not required any longer.

Refer to the Compiling on LXC containers page for info on how to compile Batocera inside of a LXC container.

This usually happens when the current Linux kernel in the folder is incomplete or was halted during compilation. To fix it, run the following:

make x86_64-shell
rm -rf build/linux-*

This may happen at any point during compilation, but usually is related to a specific emulator. To check for errors with specific packages, place a “stamp” file into the questionable package's output folder. For example, if bsnes was the emulator causing the compilation issues:

touch ~/batocera.linux/output/x86_64/build/libretro-bsnes-hd-0fd18e0f5767284fd373aebd75b00b5bab0d44a9/{.stamp_built,.stamp_target_installed}

If that goes to its end, then it can be recompiled with the following:

rm -rf /home/kend/batocera.linux/output/x86_64/build/libretro-bsnes-hd-0fd18e0f5767284fd373aebd75b00b5bab0d44a9
make libretro-bsnes-hd

This can be used to determine if it is a local issue with that package or a global issue with Batocera.

It is possible that the downloaded code has been corrupted, or outdated. This can be remedied by performing a clean build.

make <target>-cleanbuild
  • compile_batocera.linux.txt
  • Last modified: 11 hours ago
  • by atari