Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting up RetroArch on a Raspberry Pi

Setting up RetroArch on a Raspberry Pi

I just put the finishing touches on my Raspberry Pi 3 emulation machine running RetroArch. I was not a huge fan of RetroPie due to the reliance on Emulation Station - more moving parts meant that there were more things that could potentially break. I just wanted something that would run raw RetroArch, no frills.

This tutorial is mostly recreated from memory and was most recently tested with a Raspberry Pi 3 running Raspbian Stretch and RetroArch 1.7.7. If there is a mistake or a broken link, PLEASE message me and I will fix it.

Step 1: Install Raspbian

I used Raspbian Stretch Lite from this page. Write the image to your SD card using something like Win32 Disk Imager, or if you're using OSX/Linux follow a tutorial on how to write the image using dd.

Step 2: Get Comfortable

First things first, you're going to need to get Wi-Fi set up. Follow this tutorial. You will also need to give the GPU at least 128 megabytes of memory in order to properly run the more advanced interfaces, see this tutorial for instructions on how to do that.

After that, make sure your system is totally up to date:

sudo apt update
sudo apt upgrade

Unless you live in Great Britain, you will probably not be happy with some of the defaults. Use this to fix your keyboard:

sudo dpkg-reconfigure keyboard-configuration

Use this to fix your locale (choose en_US.UTF-8 if you live in the US):

sudo dpkg-reconfigure locales

Use this to fix your timezone:

sudo dpkg-reconfigure tzdata

It's probably a good idea to reboot at this point.

3. Compile RetroArch

Unlike some other tutorials, I believe in keeping things simple, explaining what flags I'm enabling and why, and not going overboard on bells and whistles or disabling things. So let's get started:

sudo apt install build-essential libasound2-dev libudev-dev

Okay, time out - what are we installing and why?

  • build-essential is a meta-package that depends on GCC, libc development libraries, and GNU Make. Essentially it contains the bare minimum needed to compile software on Debian.
  • libasound2-dev is ALSA. This library ensures that RetroArch will have sound - kind of important.
  • libudev-dev is udev. This library is necessary to ensure compatibility with a wider range of input devices. Without this, my DualShock 3 could be detected, but didn't actually work.

Now that we have libraries, grab the source for the latest stable version of RetroArch. You can find the latest source of RetroArch on the Releases page of the official RetroArch github - you want to copy the link labeled "Source code (tar.gz)". From now on, we are going to assume use of 1.7.7, but this is more than likely not the latest release, so please do check the releases page for the latest version.

curl -LO 'https://github.com/libretro/RetroArch/archive/v1.7.7.tar.gz'
tar -zxvf v1.7.7.tar.gz
cd RetroArch-1.7.7

Now to configure it:

CFLAGS='-mfpu=neon' ./configure --enable-alsa --enable-udev --enable-floathard --enable-neon --enable-dispmanx --disable-opengl1

Okay, time out again - why are we passing these parameters to configure?

  • CFLAGS='-mfpu=neon' ensures that the --enable-neon option works, specified later.
  • --enable-alsa ensures that we're compiling with ALSA support. If the library isn't installed, the configure script will die screaming instead of disabling the feature.
  • --enable-udev ensures that we're compiling with udev support.
  • --enable-floathard ensures that RetroArch uses the Pi's built-in hardware Floating Point Unit. Without this, there is the possibility that floating point calculations might be emulated in software, which is much slower.
  • --enable-neon ensures that RetroArch can use the Pi's SIMD CPU instructions (called NEON) for extra speed. Some cores take advantage of this.
  • --enable-dispmanx ensures RetroArch can use the Pi's Dispmanx support for rendering graphics. Dispmanx is a low-level 2D graphics API unique to the Raspberry Pi's video core which you can use as an efficient alternative to OpenGL. Some emulators run faster with Dispmanx, but the downside is that it is not as featureful as OpenGL (for one, the OSD text at the bottom of the screen won't render), and comes with ugly bilnear filtering enabled by default, though this can be turned off. So we compile with support for both GL and Dispmanx, and you can decide for yourself which one you prefer.
  • --disable-opengl1 ensures RetroArch does not attempt to compile support for the legacy OpenGL 1.x standard, which the Pi does not support.

And that's it. Disabling 20 different options is pointless - all you're really saving is binary size. If the configure script completes without errors, you can then:

make
sudo make install

4. Configure RetroArch

Now that RetroArch is installed, run it:

retroarch

You will be presented with the GUI front-end. You can use the arrow keys to navigate the UI, x to select an option, z to back out, and esc to quit RetroArch completely. We still have a little ways to go, however, until we're completely up and running.

Quit out of RetroArch and edit the ~/.config/retroarch/retroarch.cfg file with your editor of choice - nano is good if you don't have a preference. Look for the line that mentions core_updater_buildbot_url and set it to http://buildbot.libretro.com/nightly/linux/armhf/latest/.

Next, unless you are incredibly lucky your controller probably is not working. Navigate to Online Updater, then Update Autoconfig Profiles and wait for the OSD text to stop flashing. Quit and restart RetroArch to see if your controller was found. If your controller still isn't configured, you might need to go to Settings, then Input, then Input User 1 Binds. It should be self-explanatory from here.

Now, let's test our updated settings. From the main menu, navigate to Online Updater, then Core Updater, and select 2048. Once it's installed, from the main menu, select Load Core then 2048. Finally, select Start Core. If everything went smoothly, you should be able to play a simple game of 2048 to prove that everything is set up correctly. To exit the game, press escape or use the button on your controller that you bound to said functionality.

At this point, you are now ready to follow other RetroArch tutorials that concern importing and playing your games.

5. Other Stuff

Does it bug you that sometimes your Pi will show a blank screen after a period of inactivity, which can only be undone by touching the keyboard? Use your editor of choice to modify /etc/rc.local and put the line setterm -blank 0 before the last line that says exit 0.

If you remember from earlier, we compiled RetroArch with Dispmanx support. To give it a spin and see if you prefer it to the default GL implementation, first ensure that you are using the default rgui menu driver - if you haven't changed your menu driver, you're fine. Next, at the Main Menu select Settings, Driver, then Video Driver and select dispmanx. You must then quit and relaunch RetroArch. If you ever want to go back, go to the same place and select gl instead.

RetroArch gives you many different choices for cores. Sometimes it's a little confusing trying to figure out which core is the best. Here is my suggestions based both on personal experience and other people giving me advice:

  • NES: FCEUmm.
  • Genesis: Genesis Plus GX. If you get slowdown, try PicoDrive.
  • 32X: PicoDrive.
  • SNES: Snes9x Next. If you get slowdown, try CATSFC.
@T0biasCZe
Copy link

T0biasCZe commented Jan 14, 2021

i get error when compiling retroarch 1.9.0 (i have raspberry pi 3B)

CC gfx/drivers_context/vc_egl_ctx.c
gfx/drivers_context/vc_egl_ctx.c: In function ‘gfx_ctx_vc_destroy’:
gfx/drivers_context/vc_egl_ctx.c:184:10: warning: implicit declaration of function ‘gfx_ctx_vc_bind_api’; did you mean ‘gfx_ctx_vc_destroy’? [-Wimplicit-function-declaration]
          gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
          ^~~~~~~~~~~~~~~~~~~
          gfx_ctx_vc_destroy
gfx/drivers_context/vc_egl_ctx.c: At top level:
gfx/drivers_context/vc_egl_ctx.c:459:13: error: conflicting types for ‘gfx_ctx_vc_bind_api’
 static bool gfx_ctx_vc_bind_api(void *data,
             ^~~~~~~~~~~~~~~~~~~
gfx/drivers_context/vc_egl_ctx.c:184:10: note: previous implicit declaration of ‘gfx_ctx_vc_bind_api’ was here
          gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
          ^~~~~~~~~~~~~~~~~~~
make: *** [Makefile:206: obj-unix/release/gfx/drivers_context/vc_egl_ctx.o] Error 1

Copy link

ghost commented Jan 20, 2021

@vol-2
Copy link

vol-2 commented Jan 20, 2021

If you want to use videocore and gles3 instead you need to disable fkms-v3d. You also need x11 windowing enviroment to use gles3. Use openbox and lightdm. Configure auto login with raspi-config.

Load terminal once in openbox configure

CFLAGS="-mfpu=neon" ./configure --enable-alsa --enable-udev --enable-neon --disable-videocore --enable-opengles --enable-opengles3 --disable-opengl1 --enable-x11

nd compile the same as above.

@alphanu1
I just realized while planning another build that you wrote here first that in order to use videocore plus opengles3, you need X. Then. in the CFLAGS, you disable videocore. Is that correct, or was it just a typo, thanks.

@alphanu1
Copy link

alphanu1 commented Jan 20, 2021

@vol-2 From my finding that is correct, I have not been angle to run GLES3 without a windowing environment like X. Disabling videocore output allows you to enable hardware accelerated GLES3.

You can just install xorg and add --enable-X11 to the CFLAGS. then run "startx ./retroarch". This way you don't have the DE environment overhead. RetroArch becomes you DE.

@vol-2
Copy link

vol-2 commented Jan 20, 2021

@vol-2 From my finding that is correct, I have not been angle to run GLES3 without a windowing environment like X. Disabling videocore output allows you to enable hardware accelerated GLES3.

@alphanu1 Thanks for the reply. By "disabling videocore output," does that mean the GPU is turned off and GLES3 uses the CPU to run, or does GLES3 sort of "take over" control of the GPU or something?

@alphanu1
Copy link

alphanu1 commented Jan 20, 2021

@vol-2 With the RPI 4, GLES uses the GPU you get much better performance. So you can't have both videocore and GLES3 running at the same time. You must enable full KMS mode in the config.txt(This is usually the default depending on the OS you echted). Videocore only works when full KMS is disabled.

@vol-2
Copy link

vol-2 commented Jan 20, 2021

@vol-2 With the RPI 4, GLES uses the GPU you get much better performance. So you can't have both videocore and GLES3 running at the same time. You must enable full KMS mode in the config.txt(This is usually the default depending on the OS you echted). Videocore only works when full KMS is disabled.

Thanks alphanu1.

I had been under the impression that the "videocore" was the GPU. So, I guess it is the videocore driver that is being used, and you are using GLES3 as a replacement driver or something like that. It's weird and I still find it a bit confusing, but I think I'm starting to get it, thanks.

@alphanu1
Copy link

alphanu1 commented Jan 20, 2021

@vol-2 Broadcom VideoCore 6 (present in the Raspberry Pi 4) contains a OpenGL ES 3.0 3D engine called V3D. When using --disable videocore this disables the (VC6) driver not the VideoCore hardware. Then when you --enable-OpenGLES3 this tells RetorArch to use GLES3 driver to control video output.

Also It should be possible to use EGL instead. This uses KMS and does not rely on X. I personally have not tried this yet. However, It works in theory

@vol-2
Copy link

vol-2 commented Jan 20, 2021

Broadcom VideoCore 6 (present in the Raspberry Pi 4) contains a OpenGL ES 3.0 3D engine called V3D. When using --disable videocore this disables the (VC6) driver not the VideoCore hardware. Then when you --enable-OpenGLES3 this tells RetorArch to use GLES3 driver to control video output.

Thanks for the explanation; I think I understand a lot better now.

I'm hoping I can get it running with GLES3 on a 15kHz CRT. In the past, I've run into issues where RA will refuse to run when X11 is installed. It usually says there is no resolution for X to start or something like that. I think it has to do with the way KMS handles sending the resolution to modedb; I've looked at the log file output and it fails on modedb not finding a suitable resolution. Even if I create a "valid" modeline for modedb to pull from and put it in the folder with all the other modes, it won't use it, like it's not on the list for the party or something. This also happens when I try to use an HDMI-VGA adapter with any non-standard resolution like a super-res.

I guess I can try again, with "startx ./retroarch", but not sure that it will work.

Copy link

ghost commented Jan 20, 2021

@vol-2 Broadcom VideoCore 6 (present in the Raspberry Pi 4) contains a OpenGL ES 3.0 3D engine called V3D. When using --disable videocore this disables the (VC6) driver not the VideoCore hardware. Then when you --enable-OpenGLES3 this tells RetorArch to use GLES3 driver to control video output.

Also It should be possible to use EGL instead. This uses KMS and does not rely on X. I personally have not tried this yet. However, It works in theory

Any idea where to start?

@alphanu1
Copy link

alphanu1 commented Jan 20, 2021

@lelecanfora If you are asking about EGL. Then you would install Raspbian lite to you SD card. Install EGL dev and drivers using

`sudo apt install libegl-dev libegl-mesa0` 

Mesa version number may have changed.

Install any other packages needed like udev and libasound2 etc. Then configure with the following

`./configure --enable-alsa --enable-udev --disable-videocore --disable-opengles --disable-opengles3 --disable-x11 --enable-kms`

You may need to you some CFAGS like

` CFLAGS='-march=armv8-a+crc -mtune=cortex-a53 -O2 -mfpu=neon-fp-armv8 -mfloat-abi=hard'`

As I have mentioned before, I have not tested this yet. So it may need some tweaks to get working.

@mjeshurun
Copy link

mjeshurun commented Jan 24, 2021

Thank you for this wonderful tutorial. I'm a Raspberry Pi noob, and I found the guide to be very helpful 🙏
Could someone kindly share the terminal commands I should run to compile the PSP, PS2, and Wii emulators core files (.so)?
I successfully managed to compile the cores for SNES, N64, PSX and Dreamcast, but I can't find how to do it for PSP, PS2 and Wii.
I wish I knew how to do it myself, but I'm too new to Raspberry Pi and Linux to know.
Also, can someone share the folder location into which I should copy the BIOS files? I have a few Roms saying the BIOS files cannot be found. I managed to find the relevant BIOS files on the Internet, but I don't really know where to put them on the Raspberry Pi, so that RetroArch knows they are there.
I'm using Raspberry Pi 4 4GB running Raspberry Pi OS with desktop.
Many thanks to all the active developers maintaining these projects 🙏

Copy link

ghost commented Jan 28, 2021

@alphanu1

@lelecanfora If you are asking about EGL. Then you would install Raspbian lite to you SD card. Install EGL dev and drivers using

`sudo apt install libegl-dev libegl-mesa0` 

Mesa version number may have changed.

Install any other packages needed like udev and libasound2 etc. Then configure with the following

`./configure --enable-alsa --enable-udev --disable-videocore --disable-opengles --disable-opengles3 --disable-x11 --enable-kms`

You may need to you some CFAGS like

` CFLAGS='-march=armv8-a+crc -mtune=cortex-a53 -O2 -mfpu=neon-fp-armv8 -mfloat-abi=hard'`

As I have mentioned before, I have not tested this yet. So it may need some tweaks to get working.

There are some misunderstanding in your tutorial. I've tried with open gl es 3 and my initial idea of avoiding x11 and alsa and everything that can make retroarch slower.

It worked perfectly: https://www.reddit.com/r/RetroArch/comments/l158qt/best_performing_retroarch_build_on_a_raspberry_pi/ please take a look and eventually correct your initial post, otherwise people might build a lesser performing one.

Also I've taken a look at the flags you setup and there is no armv8-a+crc or neon-fp-armv8 in the source code. Also cortex-a53 is Pi 3 not Pi 4 so I had to change that but it makes sense for the Pi 3 guide.

@gregoryklein
Copy link

gregoryklein commented Mar 10, 2021

The link you used for Raspbian Lite goes to a 404 page.

@SirCanucklehead
Copy link

SirCanucklehead commented Mar 31, 2021

LD retroarch /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_print_version':
retroarch.c:(.text+0x53398): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_parse_input_and_config':
retroarch.c:(.text+0x5495c): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_main_init':
retroarch.c:(.text+0x55ba4): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/menu/menu_displaylist.o: in function menu_displaylist_parse_system_info':
menu_displaylist.c:(.text+0x3760): undefined reference to retroarch_git_version' collect2: error: ld returned 1 exit status make: *** [Makefile:201: retroarch] Error 1

I got this error after putting in the sudo make install command

@avdyushin
Copy link

avdyushin commented Apr 6, 2021

LD retroarch /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_print_version':
retroarch.c:(.text+0x53398): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_parse_input_and_config':
retroarch.c:(.text+0x5495c): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/retroarch.o: in function retroarch_main_init':
retroarch.c:(.text+0x55ba4): undefined reference to retroarch_git_version' /usr/bin/ld: obj-unix/release/menu/menu_displaylist.o: in function menu_displaylist_parse_system_info':
menu_displaylist.c:(.text+0x3760): undefined reference to retroarch_git_version' collect2: error: ld returned 1 exit status make: *** [Makefile:201: retroarch] Error 1

I got this error after putting in the sudo make install command

@SirCanucklehead possible: libretro/RetroArch#12225 use 1.9.0 version

@bigOconstant
Copy link

bigOconstant commented Apr 11, 2021

@lelecanfora If you are asking about EGL. Then you would install Raspbian lite to you SD card. Install EGL dev and drivers using

`sudo apt install libegl-dev libegl-mesa0` 

Mesa version number may have changed.

Install any other packages needed like udev and libasound2 etc. Then configure with the following

`./configure --enable-alsa --enable-udev --disable-videocore --disable-opengles --disable-opengles3 --disable-x11 --enable-kms`

You may need to you some CFAGS like

` CFLAGS='-march=armv8-a+crc -mtune=cortex-a53 -O2 -mfpu=neon-fp-armv8 -mfloat-abi=hard'`

As I have mentioned before, I have not tested this yet. So it may need some tweaks to get working.

I tried this on a rpi4 and when i start it up I get

Cannot open video driver ... Exiting ...

@geearethree
Copy link

geearethree commented Apr 12, 2021

im an idiot and i need help!

im really new to linux, i really have no idea what im doing with all this.

I finally got retroarch installed (1.9.1 and 1.9.0 didnt work, so i just installed 1.7.7), but im getting the error:

  • failed to add service - already in use?
    i saw a solution to this listed, but i dont really understand what it means or what to do with it.
    if anyone could explain what to do to me that would be awesome, thanks

Copy link

ghost commented Apr 15, 2021

@slimeviathan
Copy link

slimeviathan commented Jun 1, 2021

Hi Alex, the second tutorial link has the warning "THIS PAGE IS NOW DEPRECATED" is there another tutorial that you would recommend?

@Unounited
Copy link

Unounited commented Jun 1, 2021

Retroarch 1.9.5 got Released, so allow me to help you on how to get Retroarch-1.9.5 on a PI4

Get the latest raspbian buster image here: https://downloads.raspberrypi.org/raspios_full_armhf/images/raspios_full_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-full.zip.

Go to raspberry pi imager on your pc or get it on your pi4 by doing:

sudo apt-get install rpi-imager

Set everything up. When ready, go to terminal and type:

sudo apt update
sudo apt full-upgrade

Now type:

sudo raspi-config

Advanced Options, GL Driver, Legacy, and reboot.

Next install these required packages:

sudo apt install build-essential libasound2-dev libudev-dev libgles2-mesa-dev libx11-xcb-dev libxxf86vm-dev libsdl2-dev libsdl1.2-dev

Now Download the Retroarch 1.9.4 from here: https://github.com/libretro/RetroArch/archive/v1.9.5.tar.gz, or do it this way:

wget https://github.com/libretro/RetroArch/archive/v1.9.5.tar.gz
tar -xf v1.9.5.tar.gz
cd RetroArch-1.9.5

Next we configure by doing:

CFLAGS='-mfpu=neon -mtune=cortex-a72 -march=armv8-a' ./configure --disable-opengl1 --enable-neon --enable-opengles3 --enable-opengles --disable-videocore

Then:

make
sudo make install

Now you have Retroarch installed. Check your pi menu in the games section to see if it's there, or run it by typing:

retroarch

Online Updater, and Update assets.

If you get a task failed, then don't worry about it for now.

Take care!

@philippludwig
Copy link

philippludwig commented Aug 18, 2021

None of these instructions work. When I start retroarch, all I get is:

failed to export dumb buffer: Permission denied
Failed to create scanout resource
failed to export dumb buffer: Permission denied
Failed to create scanout resource
Segmentation fault

@douglasdock
Copy link

douglasdock commented Apr 4, 2022

Hi...

I'm trying to install retroarch, but the following message appears when I do the "make" command:

"CC gfx/drivers_context/vc_egl_ctx.c
gfx/drivers_context/vc_egl_ctx.c:25:10: fatal error: VG/openvg.h: Arquivo ou diretório inexistente
25 | #include <VG/openvg.h>
| ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:206: obj-unix/release/gfx/drivers_context/vc_egl_ctx.o] Erro 1"

In "rasp-config" there is no option:

"Advanced Options, GL Driver, Legacy, and reboot."

I am using Raspiberry OS 64bit

@vol-2
Copy link

vol-2 commented Apr 5, 2022

douglas, things change with raspberry pi os on a driver level fairly quickly. if you're really serious about getting it up and running, i would roll back to a known working version for this. if you're just using it for retroarch, there's really no downside to using an older version of raspberry pi os. just look back through this thread and find a success story and compare the date to the release

@dogbusiness
Copy link

dogbusiness commented Apr 18, 2022

Hi everyone.
I installed the current version on raspbian - RetroArch-1.10.3.
If you get any file not found errors while making, make sure you installed the following libs. I am not sure it was mentioned before:

sudo apt-get install libxxf86vm-dev
sudo apt-get install libx11-xcb-dev

I had problems with xf86vmode.h and XF86VidModeSetViewPort

UPD: Make sure you enable experimental cores and change path of cores/info in config file:
libretro_directory = "/.config/retroarch/cores"
libretro_info_path = "
/.config/retroarch/cores/info"

core_updater_show_experimental_true = "true"

@guyster104
Copy link

guyster104 commented May 3, 2022

Hi all:
I just bought a pi 400, 8 GB model and running Ubuntu Mate 21.10's raspberry pi 64-bit image. I cloned retroarch 1.10, using the git clone --recursive method, and am having a problem with dependencies. ./configure wants libfreetype, and am not sure what to install to give it the library it's looking for. Does anyone have retroarch running on a 400? If so, could someone please post a tutorial on how to compile retroarch on such a machine? I also require accessibility support, since I am totally blind, and depend on a screen-reader to interact with the pi. I am mainly interested in games for the Atari 2600, and NES consoles, since those are the ones I grew up with.

@bigOconstant
Copy link

bigOconstant commented May 4, 2022

I just bought a pi 400, 8 GB model

Where did you manage to score one of those? I can't find it anywhere.

@guyster104
Copy link

guyster104 commented May 4, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment