How to set up SDL2 on Linux

This article explains how to get started with SDL2 in Linux. For other SDL2 tutorials (including setting up on Windows), check out my SDL2 Tutorials at Programmer’s Ranch.

Using apt-get

If you’re on a Debian-based Linux distribution, you can use the APT package manager to easily install the SDL2 development libraries. From a terminal, install the libsdl2-dev package:

sudo apt-get install libsdl2-dev

Installing from source

If for whatever reason you can’t use a package manager, you’ll have to compile SDL2 from the source code. To do this, you first have to download SDL2:


After extracting the archive to a folder, cd to that folder and run:


When it’s done, run:

make all

Finally, run:

sudo make install

Testing it out

To verify that you can compile an SDL2 program, use the following code (it’s the same used in my “SDL2: Setting up SDL2 in Visual Studio 2010” article at Programmer’s Ranch):

#include <SDL2/SDL.h>

int main(int argc, char ** argv)

    return 0;

You can use vi or your favourite editor to create the source code:


To compile this (assuming it’s called sdl2minimal.c), use the following command:

gcc sdl2minimal.c -lSDL2 -lSDL2main -o sdl2minimal

We need to link in the SDL2 libraries, which is why we add the -lSDL2 -lSDL2main. Be aware that those start with a lowercase L, not a 1. The program should compile. It won’t show you anything if you run it, but now you know that you’re all set up to write SDL2 programs on Linux.


8 thoughts on “How to set up SDL2 on Linux”

  1. I found this very helpful, thanks for the post. I thought setting up libsdl would be much more difficult but I got through this with no problems in under 7 minutes.

  2. Hi, I just wanted to say thank you!
    It worked like a charm and now I’m off to the races with some SDL2 action 😀

    Best wishes from Germany

  3. Thanks for the straight-forward, concise instructions on how to install SDL2 on Linux. I initially tried using the “apt” method, but it failed on my particular Linux distro, so it was great that you also included the “make” method as well.

  4. This isn’t a Linux tutorial, it’s an Ubuntu tutorial and should be labelled as such. Really tiresome to see rank amateurs poisoning open source like this.

    1. What’s tiresome is ungrateful and arrogant people being rude without knowing what they’re talking about.

      There is no mention of Ubuntu in the article. The apt-get instructions work on any Debian-based distribution (the screenshots are from Linux Mint), and installing from source works on any distribution.

      Who’s the amateur now? A public apology would be in order.

Leave a Reply

Your email address will not be published. Required fields are marked *