Jump to content

Get Involved/development/Set up a development environment

From KDE Community Wiki

Information

Everything on this page only needs to be done once. Once you've done it, your development environment is set up and you can use it to submit patches and develop KDE Software!


Note

This procedure will set up kdesrc-build for Qt5 and KDE Frameworks 5.
Setting up kdesrc-build for Qt6 and KDE Frameworks 6 and setting up kdesrc-build inside a Docker container are advanced topics.


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. We will now go through the process of setting one up. 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, video tutorials can be found here.

Install basic tools

First you will need to use your operating system's package manager to install some basic tools:

  • KDE Neon/Kubuntu/Ubuntu/Debian: sudo apt install git cmake dialog
  • Arch/Manjaro: sudo pacman -S git cmake dialog extra-cmake-modules
  • Fedora: sudo dnf install git cmake dialog perl perl-IPC-Cmd perl-MD5 perl-FindBin bzip2
  • openSUSE Leap & Tumbleweed: sudo zypper install git breezy cmake dialog

Configure Git

We 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 "[email protected]"

The name you provide should be your actual name, not your KDE Identity username or a pseudonym. And 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).}}

Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as described here.

Set up kdesrc-build

Next, we need a method of managing dependencies. Every software has dependencies: other pieces of software that provide the functionality they rely on. In order to compile any piece of software, its dependencies must be available.

E.g. the KDE application KCalc depends on more than 20 other KDE git repositories: KDE Frameworks and other KDE libraries.

Most Linux operating systems do not provide development packages of the KDE Frameworks 5 and of other KDE libraries that are up-to-date enough for us to build from the "master" branch of the KDE git repositories. Therefore we will compile all of the KDE git repositories ourselves, including KDE Frameworks 5 and other KDE libraries. We should not use KDE files (binaries, libraries and other files) from the OS (i.e. the /usr directory). To do this, we use a command-line tool called kdesrc-build to download, manage, build, and install KDE git repositories. Let's set it up now!

First, we create a new directory for all the KDE source code we will be using. You will need many GB of free disk space. Budget 50 GB for KDE Frameworks + KDE Plasma, and 10-30 more for some apps as well. We then clone the kdesrc-build git repository in that directory.

# If you have an old installation of kdesrc-build and you want a clean kdesrc-build installation, run a command line like: # mv ~/.config/kdesrc-buildrc ~/.config/kdesrc-buildrc~bak ; mv ~/kde ~/kde~bak
mkdir -p ~/kde/src
cd ~/kde/src/
git clone https://invent.kde.org/sdk/kdesrc-build.git && cd kdesrc-build

Next, it's time to set up kdesrc-build and pick up the changes it made to your ~/.bashrc (or ~/.zshrc for zsh users) for the current terminal session:

# For supported operating systems (OSes), it installs all of the OS packages needed in order to build all of the KDE Frameworks 5.
./kdesrc-build --initial-setup
source ~/.bashrc

# Check that the command line above has worked by seeing if the PATH environment variable contains "~/kde/src/kdesrc-build".
echo $PATH

Warning

Do not run the command kdesrc-build without any arguments because this will build everything, which is probably overkill right now.

Note

If you use zsh and selected yes for auto-completions during the initial setup for kdesrc-build, add the following to ~/.zshrc if it is not already there.
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit


Run kdesrc-build --help for the kdesrc-build command line help.

Set up Qt

Qt is the fundamental framework that is needed for pretty much all KDE development. We need a recent enough version of Qt to proceed. If you are just getting started, we recommend that you use a Linux distribution that is well-suited for building software from source code either as the primary operating system or in a virtual machine.

You can look up the version of the Qt framework installed on your operating system by opening the application "Info Center" (KInfoCenter) > Basic Information > About this System > "Qt Version:"

If Qt 5.15 or later is installed, you're already done done with this step and can proceed to the next section! 🎉

...otherwise we now need to install a more recent version from somewhere. Your distribution might have one available. Alternatively, we need to configure kdesrc-build to build and install a recent Qt version for you. Building Qt using kdesrc-build is a more advanced topic.

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. Add ~/kde to the exclusions list in System Settings > Workspace > Search > File Search, like so:

Another way to exclude the "~/kde" directory from File Search indexing is if the check box "Enable File Search" is disabled.

Download non-KDE dependencies

If your distribution is supported, kdesrc-build --initial-setup will install the distribution packages which are needed in order to build KDE software. kdesrc-build is used in order to build any of the KDE git repositories. The packages for Qt and the rest of the dependencies are acquired using your Linux distribution's package manager.

Please install at least all of the dependencies needed in order to build all of the KDE Frameworks. Steps 4 and 5 of setting up kdesrc-build are here.

Reboot your computer and log back in so the package changes, and the changed ~/.bashrc take effect on your user account.

Once that's done, your development environment is set up and ready to build software! Let's take it for a spin.

Note

If you happen to find an external dependency needed to build KDE software that was not installed with kdesrc-build --initial-setup, once you finish this tutorial, you may send a merge request to https://invent.kde.org/sdk/kdesrc-build/-/blob/master/modules/ksb/FirstRun.pm in order to include the respective distro package to the list.


Set up a graphical IDE/tools

While not required, you may benefit from setting up graphical development tools or an Integrated Development Environment (IDE). You may want to try out KDevelop, the KDE IDE.

Next Steps

Now that you have a development environment set up, learn how to use KDE's kdesrc-build tool to manage and build software from source code!