Installing kde 6 (plasma 6) from source on ubuntu 24.04
Published: 2024-04-20 20:06:32

## Install qt 6

Install the latest qt 6.6 releases using [qt online installer](https://doc.qt.io/qt-6/qt-online-installation.html). Just select qt 6.6, no other packages are needed. I chose to install it to `/opt/qt` and created this directory with `sudo mkdir /opt/qt && chown $USER /opt/qt`. Then put something like `/opt/qt/<qt-version>/gcc_64/bin` to the head of the `PATH` environment variable via `~/.zshrc` or `~/.bashrc` (for me `<qt-version>` was `6.6.3`, the latest `6.6` release at the time I wrote this).

## Setup `pkg-config`

Ensure `pkg-config` can find the qt libraries installed above by adding `/opt/qt/<qt-version>/gcc_64/lib/pkgconfig` to `PKG_CONFIG_PATH` via your shell startup file. If you use `brew` then it's probably installed its own `pkg-config` which is now at the head of your `$PATH`. In this case ensure it can find the system `pkgconfig` files by also adding `/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig` to `PKG_CONFIG_PATH`.

Something like this should be okay:

```zsh
if [ -d /home/linuxbrew ]; then
  export PKG_CONFIG_PATH=/home/linuxbrew/.linuxbrew/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH
fi

QT6DIR=/opt/qt/6.6.3/gcc_64
if [ -d $QT6DIR/bin ]; then
  # for zsh:
  path=($QT6DIR/bin $path)
  # for bash:
  # export PATH="$QT6DIR/bin:$PATH"
  export PKG_CONFIG_PATH=$QT6DIR/lib/pkgconfig:$PKG_CONFIG_PATH
fi
```

## Install kde-builder

Follow the [initial instructions here](https://invent.kde.org/sdk/kde-builder#installation) at the `Generic Installation` section only.

The `kde-builder --install-distro-packages` doesn't seem much use as:

* The qt6 package versions it installed are out of date.
* It doesn't install most of the required dependencies.

I did run it and then manually uninstalled the qt6 dependencies since qt6 was already installed and configured using the steps above.

Then run

```zsh
kde-builder --generate-config
```

After this I edited `~/.config/kdesrc-buildrc` to install to `/opt/plasma6` by changing the line starting `install-dir`:

```
install-dir /opt/plasma6
```

And created this directory with:

```zsh
sudo mkdir /opt/plasma6
sudo chown $USER /opt/plasma6
```

## Add some unavailable python dependencies

Create a directory to store the dependencies:

```
sudo mkdir /opt/python
sudo chown $USER /opt/python
```

Add this path to `PYTHONPATH` in your shell config:

```
if [ -d /opt/python ]; then
  export PYTHONPATH=/opt/python/local/lib/python$(python3 --version | grep -o '3.[0-9]*')/dist-packages
fi
```

Then install them:

```
pip install --prefix /opt/python chai
```

Be careful that `brew` has not installed python otherwise you'll have something like `python3` pointing to your system python and `python3.12` pointing to brew's version, then the build scripts will detect brew's version and not see your system packages. I just uninstalled `brew`'s version.

## Start installing

```zsh
kde-builder workspace
```

This will inevitably fail many times and give the location of a log that indicates the error, which is usually a missing package. When installing that package use one with a `-dev` suffix.

After installing the package run:

```zsh
kde-builder --resume-from <name of package that failed> workspace
```

To resume building from where it left off.

I needed the following additional packages:

```zsh
sudo apt install libxkbcommon-dev libpolkit-gobject-1-dev libpolkit-agent-1-dev libxcb-damage0-dev libyaml-dev libsystemd-dev libstemmer-dev itstool libpcap-dev libsensors-dev libxcb-dpms0-dev libpipewire-0.3-dev libxcb-xtest0-dev libpam0g-dev libeis-dev libxcvt-dev liblcms2-dev libopenjp2-7 libappimage-dev libattr1-dev libnm-dev libqrencode-dev libdmtx-dev libzxing-dev libqalculate-dev libxcursor-dev libxtst-dev libpulse-dev modemmanager-dev python3-cairo libgtk-3-dev libxxf86vm-dev wl-clipboard libaccounts-glib-dev libsdl2-dev libxkbregistry-dev xserver-xorg-input-libinput-dev xserver-xorg-input-evdev-dev xorg-dev
```

I also had to install a perl cpan module:

```
cpan install URI::Escape
```

This worked for me because I had perl installed via `brew` (I haven't used perl for over 20 years, I guess it was a dependency of a package I did use), otherwise `sudo` may be necessary at the risk of polluting your `/usr` directory with files not managed by `apt`

`kaccounts` seems to be missing from the dependency list of `plasma-desktop` so at some point I had to install this manually via:

```zsh
kde-builder kaccounts
```

Before resuming:

```zsh
kde-builder --resume-from plasma-desktop workspace
```

# Create a startup script

Create the following file at `/opt/plasma6/bin/start-kde6`:

```zsh
#!/usr/bin/env bash

# replace $USER with the location of the user's home directory
# who built KDE6
source $USER/.config/kde-env-master.sh

if [[ -z "$DBUS_SESSION_BUS_ADDRESS" ]]; then
  exec dbus-run-session startplasma-wayland
else
  exec startplasma-wayland
fi
```

Ensure it is executable:

```zsh
chmod a+x /opt/plasma6/bin/start-kde6
```

## Add desktop entry to `sddm`

Create the following file:

```zsh
sudo touch /usr/share/wayland-sessions/plasmawayland6.desktop
sudo chown $USER /usr/share/wayland-sessions/plasmawayland6.desktop
```

Then add the following content:

```
[Desktop Entry]
Exec=/opt/plasma6/bin/start-kde6
DesktopNames=KDE6
Name=Plasma 6 (Wayland)
Comment=Plasma 6 by KDE
X-KDE-PluginInfo-Version=6.0.6
```

## Start kde6

Logout of your window manager and select the plasma 6 entry from sddm and see if it starts.

For me it didn't.

I got a black screen, the mouse cursor could be moved. Using my `krunner` keybinding I noticed some glitches at the top of the screen where `krunner` would usually appear. I could switch to another virtual console via `ctrl+alt+f3` to restart sddm, after this trying to start plasma6 again froze my computer and I had to reboot it. When I switched back to kde5, most of my keybindings were gone. Luckily I backed them up several kde config files before switching over and could restore them.

When I was in the virtual console and plasma6 was running, I noticed it had started `/usr/bin/plasmashell` instead of `/opt/plasma6/bin/plasmashell`. Disappointing. I verified that `PATH` and `XDG_CONFIG_DIRS` were set properly by looking at the environment of the `startplasma-wayland` process in the `/proc` filesystem, so why it's still choosing `/usr/bin/plasmashell` I don't know.

Some of my code is in KDE, for the notification system and scripting system. I'd love to be able to contribute again. The matrix chat for KDE is not open for registration so I'm not sure how I can get help to solve this problem.

I'm using the `nvidia-drivers` currently at version 550. Wayland on `plasma5` is okay, but copy and paste is not reliable. Especially in slack. Sometimes it works for a while and then breaks forever. To paste into my terminal I usually need to hit paste several times for the very first paste into that terminal, after which point it works.