Set up a development environment

Installing and configuring kdesrc-build

Source code for KDE software lives on KDE Invent. But before you can work on it, you'll need to set up a development environment: a set of tools that allows you to access and edit the source code, compile it into a form that the computer can run, and deploy it to a safe location. To accomplish these tasks, you will need to enter commands using a terminal program, such as KDE's Konsole.

If you're not familiar with the command line interface, you can find tutorials here. However, advanced command line skills are not required, and you will learn what you need along the way!

If you're a visual learner, we also provide video tutorials about setting up kdesrc-build.

The tool we will be using here for setting up a development environment and building KDE software is kdesrc-build. It will let you set up your development environment and compile applications on Linux and FreeBSD.

Keep in mind

You only need to set up your environment once, and then you will be able to compile (and recompile) KDE software as often as needed later on!

Install git

Setting up your environment on a Linux machine is fairly simple. First you will need to use your operating system's package manager to install git:

| Kubuntu, KDE Neon |

sudo apt install git

| | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | Manjaro, Arch |

sudo pacman -S git

| | OpenSUSE |

sudo zypper install git

| | Fedora |

sudo dnf install git perl perl-IPC-Cmd perl-MD5 perl-FindBin

|

Configure git

We then need to set your authorship information properly so that any changes you make can be properly attributed to you:

git config --global user.name "Your Name"
git config --global user.email "you@email.com"

The name you provide should be your actual name, not your KDE Identity username or a pseudonym.

The email address must be the same as the email address used for your https://bugs.kde.org account.

If they don't match, then the BUG: and FEATURE: keywords won't work (see this page for more information).

For convenience, we can enable a feature that will later become useful when we start pushing code to a repository branch:

git config --global push.autoSetupRemote true

Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as described here. Once you are done, we can start using kdesrc-build.

Set up kdesrc-build

kdesrc-build is the official KDE meta build system tool. It is used to manage the building of many software repositories in an automated fashion.

Its primary purpose is to manage dependencies. Every software has dependencies: other pieces of software that provide lower-level functionality they rely on. In order to compile any piece of software, its dependencies must be available.

KDE software has two types of dependencies:

  • dependencies on other pieces of KDE software

  • dependencies on 3rd-party software

For example, the KDE application KCalc depends on more than 20 other KDE libraries as well as the Qt toolkit.

Some Linux distributions do not provide development packages for KDE Frameworks and of other libraries that are up-to-date enough for us to build from the "main" branch of the KDE git repositories (the branch where the development of the next software versions takes place), so we use kdesrc-build to compile them ourselves. The goal is to avoid using KDE binaries, KDE libraries and other KDE files from the operating system where possible (in the Linux case, these files reside in the /usr directory).

Let's set it up now! You will need many gigabytes of free disk space. Budget 50 GB for KDE Frameworks + KDE Plasma, and 10-30 GB more for some apps as well. Then clone the kdesrc-build git repository in the following directory:

mkdir -p ~/kde
mkdir -p ~/.local/share
cd ~/.local/share
git clone https://invent.kde.org/sdk/kdesrc-build.git
cd kdesrc-build

And create a symlink to make kdesrc-build accessible in your $PATH:

mkdir -p ~/.local/bin
ln -sf ~/.local/share/kdesrc-build/kdesrc-build ~/.local/bin

About ~/.local/bin

Some Linux distributions might not follow the Freedesktop Base Directory Specification that enforces that the ~/.local/bin directory be added to the $PATH, which is required for an executable to show up in the terminal without its absolute path.

To check if ~/.local/bin is in the $PATH, run: echo $PATH.

If the directory is not listed, then you will need to add it yourself. You can do so by adding the following to your ~/.bashrc (or equivalent in your preferred shell):

export PATH=$PATH:~/.local/bin

Closing and reopening your terminal window once should be enough for kdesrc-build to appear for the next steps.

Don't forget to warn your distribution to follow the specification.

Note

Some distros need source repositories enabled before you can install the development packages you need. Do that now, if needed:

Click here to see how to enable source repos

KDE neon/Debian/Ubuntu/Kubuntu/etc:

If the file /etc/apt/sources.list exists

Open the file /etc/apt/sources.list with a text editor such as Kate or nano. Each line that starts with "deb " should be followed by a similar line beginning with "deb-src ", for example:

deb http://us.archive.ubuntu.com/ubuntu/ noble main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ noble main restricted

Note: The URL might differ depending on your country, and instead of noble the name of the Debian or Ubuntu version should appear instead, like bookworm or jammy.

If the deb-src line is commented out with a #, remove the # character.

Lastly, run:

sudo apt update

If the file /etc/apt/sources.list does not exist

Starting with Kubuntu 24.04, the configuration file for apt repositories has moved to /etc/apt/sources.list.d/ubuntu.sources.

Open the file /etc/apt/sources.list.d/ubuntu.sources with an editor like Kate or nano. Change the contents of the file by replacing all occurrences of Types: deb with Types: deb deb-src. For example, replacing the following:

Types: deb
URIs: http://archive.ubuntu.com/ubuntu
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

With:

Types: deb deb-src
URIs: http://archive.ubuntu.com/ubuntu
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Note: The URL might differ depending on your country, and instead of noble the name of the Debian or Ubuntu version should appear instead, like bookworm or jammy.

Lastly, run:

sudo apt update

Initial setup

With that done, it's time to run the initial setup program, which will install the necessary binary packages from your Linux operating system:

kdesrc-build --initial-setup

The step kdesrc-build --initial-setup above installs the Linux binary packages that are needed for kdesrc-build to build all of KDE Frameworks and then creates a default configuration file ~/.config/kdesrc-buildrc. If you look at that configuration file, you will see that by default kdesrc-build will compile everything inside a new ~/kde folder for you. You will see that in the next page.

Updating kdesrc-build

Once in a while you will want to update kdesrc-build to get its latest changes. To do so, run the following:

# Go to where kdesrc-build was cloned:
cd ~/.local/share/kdesrc-build
# Update kdesrc-build itself:
git pull
# Install new distribution package dependencies, if any:
kdesrc-build --install-distro-packages

If you discover any external dependencies needed to build KDE software that were not installed with kdesrc-build --initial-setup or kdesrc-build --install-distro-packages, then please send a merge request to the repo-metadata/distro-dependencies repository to include the needed packages in the list.

Set up Qt

Qt is the fundamental framework that is needed for pretty much all KDE development. A recent enough version of Qt 6, currently Qt version greater or equal to 6.7, is required to proceed.

The initial setup of kdesrc-build should have installed the required Qt6 packages for you already.

If your Linux distribution does not provide recent versions of Qt packages, you have four options:

Disable indexing for your development environment

You'll want to disable indexing for your development-related git repos and the files they will build and install.

To do that, add the ~/kde directory to the exclusions list in System Settings › Search › File Search > Stop Indexing a Folder...

Next Steps

Your development environment is now set up and ready to build software.

To recapitulate the essentials:

  1. You installed and configured git.

  2. You cloned kdesrc-build using git.

  3. You ran the initial setup for kdesrc-build.

Time to learn how to use kdesrc-build to build software from source code!

Last updated