Working on GNU Linux - raysan5/raylib GitHub Wiki

Dependencies

Raylib has several dependencies that you need in order to work with it.

Install required tools

You need a GCC (or alternative C99 compiler), make and git (to download raylib repo).

sudo apt install build-essential git

Install required libraries

You need to install some required libraries; ALSA for audio, Mesa for OpenGL accelerated graphics and X11 for windowing system.

Ubuntu
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
Fedora
sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
Arch Linux
sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
Void Linux
sudo xbps-install alsa-lib-devel libglvnd-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa MesaLib-devel
  • For intel drivers
    sudo xbps-install mesa-dri mesa-intel-dri
    

Raylib-Quickstart, the simple solution to get started quickly.

The quickstart is a cross platform template for all desktop platforms that will setup raylib automatically.

https://github.com/raylib-extras/raylib-quickstart

It works with many compilers on windows, linux and Mac OS. Works with makefiles, visual studio, and VSCode.

Simply follow the instructions in that link and you will be done, you do not need to use the rest of this document.

Building Library Manually

To build your raylib game for GNU/Linux you need to download raylib git repository. raylib already comes with ready-to-use makefiles and CMake system to compile source code, examples and templates.

This guide is for all GNU/Linux distros, just note that APT is used as package manager for Debian based distros.

Wayland

WARNING: Wayland building requires manual generation of some wayland specific files. GLFW support for Wayland is "experimental and incomplete". For more info check issue #2666

Building for wayland requires the following additional packages

sudo dnf install wayland-devel libxkbcommon-devel wayland-protocols-devel

To build raylib for Wayland, -DUSE_WAYLAND=ON should be defined in the CMake step or -DUSE_WAYLAND_DISPLAY=TRUE in Makefile.

Build raylib using make

You can compile three different types of raylib library:

  • The static library (default method)
  • The dynamic shared library (often used on Linux)
  • The web library

Download the raylib repository from Github, then compile it with:

git clone --depth 1 https://github.com/raysan5/raylib.git raylib
cd raylib/src/
make PLATFORM=PLATFORM_DESKTOP # To make the static version.
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version.
make PLATFORM=PLATFORM_WEB # To make web version.

Warning: if you want to compile a different type of library (static, ...), you must type make clean before the compiling.

Install the library to the standard directories, usr/local/lib and /usr/local/include, or remove it:

sudo make install # Static version.
sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.

sudo make uninstall
sudo make uninstall RAYLIB_LIBTYPE=SHARED

NOTE: raylib is configurable and can be be built in a variety of ways. Please read src/Makefile, src/config.h and raylib.h itself for a full listing of available options and values.

Build raylib using CMake

sudo apt install cmake

Building with cmake on Linux is easy, just use the following:

git clone https://github.com/raysan5/raylib.git raylib
cd raylib
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install
sudo ldconfig

In case any dependencies are missing, cmake will tell you.

NOTE: raylib is configurable and can be be built in a variety of ways. See the CMake Build Options for a full listing of available options and values. Alternatively, you may use the curses UI provided by ccmake(1) for interactively configuring raylib.

Building Examples with make

If you have installed raylib with make install, Just move to the folder raylib/examples and run:

make PLATFORM=PLATFORM_DESKTOP

If raylib was installed with make install RAYLIB_LIBTYPE=SHARED

make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED

A more detailed command for the OpenGL ES GRAPHICS variant on Ubuntu 16.04 is:

make  PLATFORM=PLATFORM_DESKTOP  GRAPHICS=GRAPHICS_API_OPENGLES_20 RAYLIB_LIBTYPE=SHARED USE_EXTERNAL_GLFW=TRUE \
    CFLAGS="-fPIC -I/usr/include/GL" LDFLAGS='-L/usr/local/lib/raysan5 -lGLESv2 -lglfw3'

To compile just one specific example, add flags as needed:

make core/core_basic_window PLATFORM=PLATFORM_DESKTOP

To force recompile one example:

make core/core_basic_window PLATFORM=PLATFORM_DESKTOP -B

The raylib/games folder can be made the same way as the examples. Have fun!

Building examples with cmake

In raylib/examples run:

cmake -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=ON ..
make

Link raylib with system GLFW

Instead of using the embedded GLFW, you can download GLFW3 and build it from source (it requires CMake).

wget https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip
unzip glfw-3.2.1.zip
cd glfw-3.2.1
cmake -DBUILD_SHARED_LIBS=ON
sudo make install

Now with GLFW installed, you may build raylib while specifying USE_EXTERNAL_GLFW:

make USE_EXTERNAL_GLFW=TRUE
# or
cmake -DUSE_EXTERNAL_GLFW=ON

Install on GNU Linux

If you are a packager for a Distribution not listed here, please take the time and create a raylib package.

openSUSE

openSUSE has raylib in the official repository. Install it via:

zypper in raylib-devel

Users of older openSUSE versions will have to add the devel:libraries:c_c++ devel project.

Add the repo, refresh sources and install raylib:

zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_Factory/devel:libraries:c_c++.repo
zypper ref
zypper in raylib-devel

If you have any doubt, just let me know.

Fedora

Fedora has raylib in the official repository.

  • raylib-devel - needed only for development, installs runtime library too
  • raylib - runtime dependency for Fedora based systems

To install development files (for development)

Continue with:

#> dnf install raylib-devel

To install library only (for runtime)

Continue with:

#> dnf install raylib

Arch Linux

The official Arch Repository contains the raylib package. Install via:

pacman -S raylib

CentOS 7 building from source

yum -y install devtoolset-9\*
scl enable devtoolset-9 bash
cd raylib/src/
make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_11 -B

Nix/NixOS

  1. Begin by downloading the latest stable release of raylib into your project folder. Use the following commands:
cd your-project-folder
mkdir external
wget https://github.com/raysan5/raylib/archive/refs/tags/5.5.tar.gz -P external/
tar xvf external/5.5.tar.gz -C external/
  1. Create a flake.nix file in the root folder of your project with the following content:
{
  description = "Raylib development environment";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self , nixpkgs ,... }: let
    system = "x86_64-linux";
  in {
    devShells."${system}".default = let
      pkgs = import nixpkgs {
        inherit system;
      };
    in pkgs.mkShell {
      packages = [
        pkgs.libGL

        # X11 dependencies
        pkgs.xorg.libX11
        pkgs.xorg.libX11.dev
        pkgs.xorg.libXcursor
        pkgs.xorg.libXi
        pkgs.xorg.libXinerama
        pkgs.xorg.libXrandr

        # Uncomment the line below if you want to build Raylib with web support
        # pkgs.emscripten
      ];
    };
  };
}
  1. Create the development environment with the dependencies using:
nix develop
Or with nix channels

Alternatively, you can create a shell.nix file in the root folder of your project with the following content:

{ pkgs ? import <nixpkgs> {} }:

  pkgs.mkShell {
    nativeBuildInputs = [
      pkgs.libGL

      # X11 dependencies
      pkgs.xorg.libX11
      pkgs.xorg.libX11.dev
      pkgs.xorg.libXcursor
      pkgs.xorg.libXi
      pkgs.xorg.libXinerama
      pkgs.xorg.libXrandr

      # Web support (uncomment to enable)
      # pkgs.emscripten
    ];
}

Then, run the following command to enter the nix-shell:

nix-shell
  1. To build raylib, navigate to the src directory inside the external/raylib-5.5 folder and run make:
cd external/raylib-5.5/src/
make PLATFORM=PLATFORM_DESKTOP
  1. Now you can compile your project with Raylib. The simplest possible Makefile for this would be:
RAYLIB ?= ./external/raylib-5.5/src/

all:
    gcc src/main.c -I $(RAYLIB) -L $(RAYLIB) -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

The simplest possible build command

After installing raylib from source or package manager, you can build a project with this command (modify as necessary):

cc game.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

Creating a Makefile will help with building as the project grows.

Common issues

I get an error: error while loading shared libraries: libraylib.so.351: cannot open shared object file: No such file or directory after rebooting. Right after building the library it worked fine.

If you install raylib with RAYLIB_LIBTYPE=SHARED you may find that compiler is unable to locate library file. That is because raylib wasn't installed to standard system library directories. You can check in which directory raylib was installed by looking at the make install output:

<...>
cp --update --verbose /home/<USERNAME>/<PATH_TO_RAYLIB>/raylib/libraylib.so.3.5.0 /usr/local/lib/libraylib.so.3.5.0
<...>

In this case raylib was installed to /usr/local/lib, but it can be that raylib gets installed into /usr/local/lib64 or some other directory. You should check the output yourself and make sure, that missing files are located in that directory.

Next all you need to do is either specify that install path in the makefile or set an environment variable. You can set an environment variable by typing:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib (replace /usr/local/lib with your install path)

You can append this command to the end of your ~/.bashrc or ~/.zshrc or other user login script, to make the change permanent. If you do so you'll be able to compile right away after you relogin. If you don't want to relogin just run source <YOUR USER LOGIN SCRIPT>

For issues related like not able to link a library like libGL or libGLX in Void Linux, it's probably due to broken symlinks.

The broken symlinks could be checked using below command:

sudo xbps-pkgdb -a

The above command will output something similar to below one:

ERROR: MesaLib-devel: broken symlink /usr/lib/libGLX_mesa.so (target: /usr/lib/libGLX_mesa.so.0)
ERROR: libglvnd-devel: broken symlink /usr/lib/libGL.so (target: /usr/lib/libGL.so.1)
ERROR: libglvnd-devel: broken symlink /usr/lib/libGLESv1_CM.so (target: /usr/lib/libGLESv1_CM.so.1)
ERROR: libglvnd-devel: broken symlink /usr/lib/libGLESv2.so (target: /usr/lib/libGLESv2.so.2)
ERROR: libglvnd-devel: broken symlink /usr/lib/libGLX.so (target: /usr/lib/libGLX.so.0)
ERROR: libglvnd-devel: broken symlink /usr/lib/libGLdispatch.so (target: /usr/lib/libGLdispatch.so.0)
ERROR: base-files: unexistent file /etc/issue
ERROR: base-files: conf files check FAILED.

This helps us to know which packages needs to be reinstalled to fix the broken symlink issus. From the above output, it's clear that libglvnd-devel, MesaLib-devel needs to be reinstalled.

One can you below command to reinstall these packages:

sudo xbps-install -f libglvnd-devel MesaLib-devel

Simple setup using Premake

The fastest way to get a game setup on with GCC, MinGW or Visual Studio is to use premake.

See https://github.com/raylib-extras/game-premake for instructions

Or watch the video tutorial here

https://www.youtube.com/watch?v=--gI9083QnU

⚠️ **GitHub.com Fallback** ⚠️