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.

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:

KubuntuKDE Neon
sudo apt install git
ManjaroArch
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

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.6, 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 > Start Indexing a Folder...

The Search field in System Settings.

The Search field in System Settings.

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!