How to install MariaDB on Ubuntu 22.04

Endrit Qerreti

Endrit Qerreti

MariaDB provides a repository that you can add on your Ubuntu machine, and then use that repository to download MariaDB.

MariaDB can be easily installed on any linux distro, as MariaDB supports all linux distros. However, in this tutorial, we are using Ubuntu 22.04, and we'll be installing MariaDB on it by using the official MariaDB repository for Ubuntu 22.04.

In this tutorial, you will learn how to install MariaDB on Ubuntu 22.04.

Install MariaDB on Ubuntu 22.04

Installing MariaDB on Ubuntu 22.04, is easy. All you have to do is follow the steps below and install MariaDB on your machine.

Step 1 - Add MariaDB GPG Key

MariaDB provides a GPG key for its own repository. In order to be able to use this repository, the gpg key that you are downloading will be used later to verify the signature.

First, you need to download the GPG key on the keyrings directory /etc/apt/keyrings.

To do so, simply run the commands below one by one.

sudo mkdir -p /etc/apt/keyrings
sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp ''

Step 2 - Create MariaDB Repository

Next, you need to create a repository file that contains MariaDB repository information.

To create a repository file is quite easy.

1) First, change the working directory to /etc/apt/sources.list.d/

cd /etc/apt/sources.list.d

2) Next, create an empty file called mariadb.sources by using any text editor.

sudo nano mariadb.sources

3) Add the following on the file that you created with nano.

# MariaDB 11.1 repository list - created 2023-11-20 09:30 UTC
X-Repolib-Name: MariaDB
Types: deb
# is a dynamic mirror if your preferred mirror goes offline. See for details.
# URIs:
Suites: jammy
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp

4) Save changes.

Step 3 - Update package index

Now that you created the repository file for MariaDB, in order to make this file active and to be able to use it, you need to update the package index on your machine.

To do this, simply run the following.

sudo apt update

Step 4 - Install MariaDB

MariaDB repository is active now on your machine, this means you can proceed to install MariaDB.

To install MariaDB, simply run the command below.

sudo apt install mariadb-server

At the time of writing this tutorial, the latest version of MariaDB is version : 11.1

Uninstall MariaDB on Ubuntu 22.04

If you feel like something went wrong with the MariaDB installation , and want to uninstall it so that you can reinstall it again, then you can easily do so.

sudo apt remove mariadb-server


By now you should be able to install and use MariaDB on your Ubuntu 22.04 machine.