Set up a development environment

Installing and configuring kde-builder

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 useful video tutorials.

The tool we will be using here for setting up a development environment and building KDE software is kde-builder. It will let you set up your development environment and compile applications on Linux and FreeBSD. Repo README with basic usage

Why kde-builder?

kde-builder 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 kde-builder 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).

Set up kde-builder

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

cd ~
curl 'https://invent.kde.org/sdk/kde-builder/-/raw/master/scripts/initial_setup.sh' > initial_setup.sh
bash initial_setup.sh

kde-builder will install git, a few runtime packages, and will install its executable in your PATH so you can run it from the terminal, as in the next step.

After the initial setup, you will need to generate a configuration file for kde-builder. Run:

kde-builder --generate-config

This will create a new file ~/.config/kde-builder.yaml. Documentation is available that lists all possible options and example values.

While during initial setup, kde-builder installed the essentials for itself to run, now it will need to install the required distribution packages to build KDE software. To do that, run:

kde-builder --install-distro-packages

Next, you'll want to test that things are set up correctly. Run this to verify kcalc is able to be built:

kde-builder --pretend kcalc

Finally, perform your first build.

kde-builder dolphin

This will build Dolphin, the Plasma file manager and its KDE-based dependencies. We choose Dolphin since it is a good test case to exercise the whole build process.

Now kde-builder is set up! 🎉 These common command line flags may come in handy.

Updating kde-builder

Once in a while you will want to update kde-builder to get its latest changes. To do so, run the initial_setup.sh file that was created when installing kde-builder:

cd ~
bash initial_setup.sh

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 kde-builder should have installed the required Qt6 packages for you already, in which case you don't need to do anything and may skip directly to the Configure git section.

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

Finding the latest Qt version

To find out the latest release of Qt, you can visit KDE's Qt repository mirror and check for the right branch:

A screenshot of the main page of the Qt repository mirror showing the branch list that appears once you click on the combobox that has 'dev' written on it.

Use Qt6 from the online installer

Instead of letting kde-builder build Qt for you, you may want to use the online installer that comes directly from Qt. To download Qt you will need to make an account.

First, go to the QtGroup website and create an account.

After creating your new Qt account, go to Qt for Open Source Development, click on "Download the Qt Online Installer", and follow the download process.

Run the downloaded file, log in with your new Qt account, and follow the wizard to install Qt. During the installation, choose the option "Custom installation", and:

  • Uncheck "Qt Design Studio"
  • Uncheck "Qt Creator"
  • Click on the collapsible for the latest version of Qt or double-click it
  • Check "Desktop"

This will install only the essential Qt libraries in ~/Qt by default, occupying a little less than 2 GB of storage.

Once installed, open the file ~/.config/kde-builder.yaml, uncomment the line with qt-install-dir: ~/kde/qt, and change it to point to your Qt installation. The actual path should be similar to this, depending on your Qt version:

qt-install-dir: ~/Qt/6.8.0/gcc_64

Once it is done, kde-builder will know to use the Qt provided by the online installer to build KDE software.

If you ever need to install more Qt components, you can open the newly installed Qt Maintenance Tool available on the menu launcher.

Use Qt6 from aqtinstall

If you are bothered by the fact that the Qt online installer requires a Qt account or if you don't want to undergo the process of building Qt6 with kde-builder, you may try using the unofficial installer aqtinstall which simply downloads Qt from the same sources as the official installer.

First, install aqtinstall:

pipx install --user aqtinstall

If you don't have pipx installed, you may need to install it from your distribution.

You can then install Qt with aqt. You will need to find the latest Qt release first.

aqt install-qt linux desktop 6.8 linux_gcc_64 --outputdir ~/Qt --modules all

This will install all Qt modules available in version 6.8 and will occupy a bit more than 8 GB of storage.

Once installed, open the file ~/.config/kde-builder.yaml, uncomment the line with qt-install-dir: ~/kde/qt, and change it to point to your Qt installation. The actual path should be similar to this, depending on your Qt version:

qt-install-dir: ~/Qt/6.8.0/gcc_64

Once it is done, kde-builder will know to use the Qt provided by the online installer to build KDE software.

Build Qt6 using kde-builder

It is possible to build Qt with kde-builder, but it will require a minimum of 30 GB of storage and have a long compilation time that may last up until a few hours depending on your machine.

To do this, open the file ~/.config/kde-builder.yaml and uncomment the line containing:

qt-install-dir: ~/kde/qt

Near the end of the file, add an override so you build Qt from the latest release instead of the development branch (the default):

override qt6-set:
  branch: 6.8

Then run:

kde-builder qt6-set

It will take quite a while to finish compiling.

Configure git

The first thing we will need to do after having set up kde-builder is to configure git.

Set your authorship information properly so that any changes you make to code can be properly attributed to you:

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

You should take the chance to create a KDE Identity account that you can use to access KDE's Gitlab instance where all KDE code resides, Invent. Take a look at Infrastructure: Gitlab to learn more about this.

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 Invent profile as described in the Invent SSH docs. Once you are done, we can start using kde-builder.

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...

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 kde-builder.
  2. You generated a configuration file for it.
  3. You installed the necessary packages to start building KDE software.
  4. You have set it up to use Qt (optional).
  5. You have set up git so you can start working on code.

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