Compiling MariaDB From Source: The Master Guide
Complete step-by-step guide for compiling and building MariaDB from source on various flavors of Linux and on macOS.
This guide covers compiling MariaDB on Unix-like systems, including Linux and macOS. If you are building on Windows, please refer to the dedicated Building MariaDB on Windows guide.
This guide provides the universal workflow for building MariaDB Server from source code. While specific dependencies may vary by operating system, the core build process remains consistent across all modern platforms.
Major Steps
Prepare Your Environment
Before you begin, your system must have the necessary compilers, build tools, and library headers.
For details, see Install Build Dependencies.
Obtain the Source Code
Decide whether you need the latest development branch or a specific stable release.
Option A: Git clone (best for developers)
git clone --branch 11.8 https://github.com/MariaDB/server.git cd serverOption B: Source tarball (best for stability)
Download the
.tar.gzfrom the official MariaDB downloads and extract it:tar -xf mariadb-11.8.x.tar.gz cd mariadb-11.8.x
For details on both options, see Obtaining the Source Code.
Configure the Build (CMake)
MariaDB uses out-of-source builds to keep the source tree clean. This is where you define installation paths and features.
Create a build directory:
mkdir build && cd buildRun CMake:
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfoCommon flags like
-DCMAKE_INSTALL_PREFIXor debug options go here.
For common CMake configuration flags, see Common CMake Configuration Flags.
For a configuration alternative to configuring CMake, see The Quick Way: Using BUILD Scripts.
Compile
Once configured, use the CMake build tool to compile the binaries. Using the --parallel flag speeds this up by using multiple CPU cores.
cmake --build . --parallel $(nproc)cmake --build . --parallel $(sysctl -n hw.logicalcpu)For CMake 3.13+, run this:
cmake --build . --parallel Without a number, modern CMake automatically picks an appropriate number of jobs.
If you encounter build errors, see Troubleshooting Common Build Errors.
Install and Initialize
After a successful build, you must prepare the data directory and system tables before the server can start.
Install:
sudo cmake --install .(or run directly from the build directory for testing).Create Data Directory: Ensure the
mysqluser exists and has permissions.Initialize System Tables.
If running from the build directory (use this if you did not run the
cmakeinstall command – in that case, you must run the script from within your build folder):./scripts/mariadb-install-db --user=mysql --datadir=[path]If you installed to the system (
sudo cmake --install ..., in which case thePATHtomariadb-install-dbis set):mariadb-install-db --user=mysql --datadir=[path]
See this section for conventional locations of the data directory (
--datadir).
Test the Build
Before putting your fresh build into production, verify it against the official test suite. MariaDB includes MTR (MariaDB Test Run) for this purpose.
Run Unit Tests: Quickly check the core logic.
cmake --build . --target testRun Integration Tests (MTR): This launches actual server instances and runs thousands of SQL tests.
cd mysql-test ./mysql-test-run.pl --parallel=$(nproc)Pro-Tip: If a specific test fails, you can run it individually:
./mysql-test-run.pl alias.Note: You do not need to install MariaDB to the system to run these tests; they run entirely within the build directory.
After Building
After successfully building MariaDB from source, additional tasks can be found under Post-Build.
Summary of the Build Workflow
Step
Action
Primary Tool
1
Install Build Tools
apt / dnf / brew
2
Download Source
git / wget
3
Configure Features
cmake
4
Compile Binaries
cmake --build
5
Initialize Database
mariadb-install-db
Preparing Your Environment: Install Build Dependencies
This section covers the details of step 1 (Prepare Your Environment).
To compile MariaDB, you need a set of core build tools and development headers for various libraries.
Setting up the MariaDB Source Repository
Setting up the MariaDB source repository is optional but recommended. If you want to build the MariaDB version that comes with your operating system, you can skip this subsection, though.
Adding the MariaDB Repository Tool into the workflow ensures that you are getting the dependencies specifically tailored for the version of MariaDB you want to build (for instance, 11.8), rather than whatever outdated version happens to be in your operating system's default upstream repository.
Using the MariaDB Repository Tool
While your operating system's default repositories contain many build tools, they may lack the specific library versions required for the latest MariaDB releases. Using the MariaDB Repository Tool ensures your environment is perfectly synced with the version you intend to build.
1. Configure the Repository
Use the MariaDB Repository Configuration Tool to generate the setup commands for your specific operating system and desired MariaDB version.
Example for Ubuntu 24.04 and MariaDB 11.8 (don't copy this blindly – the example uses the 11.8 release and a specific mirror; adjust these strings based on the output of the Repository Configuration Tool):
2. Install Tailored Dependencies
Once the repository is active and the source lines are enabled, you can use the package manager to pull exactly what that specific MariaDB version requires:
Advantages of Using the Repository Tool
Version Accuracy: If MariaDB 11.x requires a newer
libsslorzstdthan what your operating system provides by default, the MariaDB repo often provides the correct headers.Completeness: It automatically handles the "Source Repositories" issue because the
add-apt-repositorycommand includes the--enable-sourceflag by default.Automation: It reduces the "Manual Package Table" from a primary task to a fallback for users who cannot or will not add external repositories.
The "Shortcut" Command
Most Linux distributions allow you to install all necessary dependencies for the "official" build with a single command.
This requires that "source repositories" are enabled in your package manager. Enable them like this:
Run this command:
Edit /etc/apt/sources.list and uncomment lines starting with deb-src.
Run dnf config-manager --set-enabled baseos-source appstream-source .
Source repos are usually enabled by default, but check dnf repolist to verify.
The shortcut command itself varies by operating system:
sudo apt build-dep mariadb-server
sudo dnf builddep mariadb (or yum-builddep mariadb-server)
sudo zypper source-install -d mariadb
Homebrew does not have a direct build-dep command. You can install the standard MariaDB build stack using:
Manual Package Table
If you are building a specific version or don't want to use the shortcut, use the list below to install the mandatory packages.
Use apt to install these tools:
Build tools:
build-essential git cmakeParser tools:
bison flexTerminal/UI:
libncurses-devSecurity/SSL:
libssl-devorgnutls-devCompression:
zlib1g-devMiscellaneous headers:
libaio-dev libboost-all-dev
Use dnf (or yum) to install these tools:
Build tools:
gcc-c++ git cmakeParser tools:
bison flexTerminal/UI:
ncurses-develSecurity/SSL:
openssl-develCompression:
zlib-develMiscellaneous headers:
libaio-devel boost-devel
Use zypper to install these tools:
Build tools:
gcc-c++ git cmakeParser tools:
bison flexTerminal/UI:
ncurses-develSecurity/SSL:
libopenssl-develCompression:
libzlib-develMiscellaneous headers:
libaio-devel boost-devel
Use brew to install these tools:
Build tools:
cmake gitParser tools:
bison flexTerminal/UI:
ncursesSecurity/SSL:
opensslCompression:
zlibMiscellaneous headers:
boost
The system-provided version of bison on macOS is often too old. After running brew install bison, you may need to add it to your PATH:
Optional Dependencies (Plugins & Features)
If you plan to enable specific storage engines or features, install these additional packages:
Feature
Dependency
Package Name (Generic)
S3 Storage Engine
libcurl
libcurl-devel / libcurl4-openssl-dev
GSSAPI (Kerberos)
krb5
krb5-devel / libkrb5-dev
RocksDB / MyRocks
snappy, lz4, zstd
snappy-devel, lz4-devel,
libzstd-devel
Systemd Support
systemd
systemd-devel / libsystemd-dev
Authentication
pam
pam-devel / libpam0g-dev
Obtaining the Source Code
This section covers the details of step 2 (Obtain the Source Code).
Depending on your goal, you can either clone the repository using Git or download a stable source tarball.
Option A: Git Clone (Recommended for Developers)
Using Git allows you to easily switch between versions and contribute patches. MariaDB uses submodules for certain components; you must initialize these for the build to succeed.
Clone the specific branch:
Choose a branch that matches the major version you need (for instance,
11.8).Initialize Submodules:
This command downloads the source code for external storage engines and connectors.
Option B: Source Tarball (Best for Stability)
If you do not need version control, downloading a pre-packaged source tarball is simpler. Submodules are already included in the tarball, so no extra steps are required.
Download: Visit the MariaDB Downloads page and select the "Source" tab.
Extract:
Key Takeaway: Git vs. Tarball
Updates
Easy (git pull)
Manual (download new version)
Submodules
Requires manual initialization
Pre-included
History
Full commit history available
No history included
Size
Larger (includes .git data)
Smaller
Common CMake Configuration Flags
This section covers the details of step 3 (Configure the Build).
When running cmake .., you can pass these options (using the -D prefix) to customize how MariaDB is built.
Install Path
-DCMAKE_INSTALL_PREFIX=/opt/mariadb
Defines where the server is installed (default: /usr/local).
Build Type
-DCMAKE_BUILD_TYPE=RelWithDebInfo
Options: Release, Debug, RelWithDebInfo (recommended).
Features
-DWITH_EMBEDDED_SERVER=ON
Builds the libmariadbd embedded library.
Storage Engines
-DPLUGIN_ROCKSDB=NO
Explicitly disables a specific storage engine (use YES to force enable).
Security
-DWITH_SSL=system
Use the system's OpenSSL (default). Options: system, openssl, gnutls.
Debugging
-DWITH_ASAN=ON
Enables AddressSanitizer to find memory leaks.
Standardization
-DBUILD_CONFIG=mysql_release
Configures the build to match the official MariaDB release binaries.
Pro-Tip: Managing Plugins
Most plugins are auto-detected based on the dependencies you installed in step 1. To see a full list of available options and their current status, run:
The Quick Way: Using BUILD Scripts
This section covers alternative details of step 3 (Configure the Build).
If you don't want to manually toggle CMake flags, MariaDB includes a BUILD/ directory containing pre-configured scripts for common development environments. These are especially useful for developers who need a specific setup (like a Debug build with Valgrind support) quickly.
How to Use a BUILD Script
These scripts must be run from the root of the source directory (unlike the manual "out-of-source" CMake method).
Common Script Variants
Most scripts follow a naming convention: compile-[architecture]-[type].
compile-pentium64-debug
Standard 64-bit development with debug symbols.
compile-pentium64-max
Enables almost all features and plugins (highest compatibility).
compile-pentium64-valgrind-max
Optimized for memory testing with Valgrind.
compile-amd64-debian-build
Mimics the configuration used for official Debian/Ubuntu packages.
Adding Extra Flags
You can still pass custom CMake flags to these scripts using environment variables or arguments, though most users find the defaults sufficient for testing.
Troubleshooting Common Build Errors
This section covers details of step 4 (Compile).
Compiling from source often hits roadblocks. Here are the most common issues and how to fix them.
CMAKE_CXX_COMPILER not found
Missing C++ compiler.
Install g++ (Linux) or clang (macOS).
Bison version is too old
macOS default bison is outdated.
brew install bison and update your PATH.
Could not find GSSAPI
Missing Kerberos headers.
Install libkrb5-dev or krb5-devel.
Could not find Curses
Missing terminal headers.
Install libncurses-dev or ncurses-devel.
No space left on device
/tmp or build dir is full.
MariaDB requires ~5GB to 10GB of disk space for a full build.
The "Clean Slate" Command
If you changed your CMake flags and things are getting weird, the best fix is to wipe the cache and start over.
Do not delete the source directory, only the contents of the build folder.
Notes
Conventional Data Directory Locations
This table lists typical locations of --datadir.
Linux (General)
/var/lib/mysql
macOS (Homebrew)
/opt/homebrew/var/mysql
macOS (Intel/Legacy)
/usr/local/var/mysql
FreeBSD
/var/db/mysql
Custom/Dev Build
~/mariadb-data (or any folder owned by your user)
Post-Build
This section covers optional additional things to do after building MariaDB successfully (step 8 (After Building)).
Packaging
If you need to deploy MariaDB to multiple servers, you don't have to compile it on every machine. Instead, use MariaDB’s built-in packaging support to create a distributable package.
MariaDB uses CPack (part of the CMake suite) to generate these packages.
Configure for Packaging: To ensure the package follows standard filesystem hierarchies, use the
mysql_releaseconfiguration.Generate the Package: After the build is complete, run
cpackfrom your build directory.Result: You will find a file like
mariadb-11.x.x-linux-x86_64.debin your build directory, which can be installed viadpkg -iorrpm -ivh.
Last updated
Was this helpful?

