[Update 16/06/2012] : Thanks to Blakpawn (see comments below), the soprano virtuoso backend now compiles again
As promised a long time ago, finally KDE has (almost) moved to git -kdemultimedia did it a couple of weeks ago- so I can finally write a comprehensive post about how to compile an almost full KDE installation from sources and setup it for your every day work/fun.
I highly recommend you to read all the post before starting with the process; I know it’s kind of tl;dr but I think that if it’s your first time on doing that, you should really have an idea about what you’re about to do. It’s for your own sake, after all
Also, since I cleaned up a lot the scripts I use, if you encounter some kind of error please let me know so I can fix it!
Ok, let’s start.
Let’s get straight on this: you’re gonna need a lot of space. About 8GB for the sources, plus 15GB for the build. But there’s even more; if you want to compile Qt too, which I do, you need extra 1.4GB for the sources which becomes 3.4GB after the build process (but of course you will “make distclean” it before compiling KDE to save a couple of GB ).
But that’s for the folder where your Qt an KDE sources+build files reside; the partition where you’re going to install all the system files will need about 7GB of free space (again, plus 900MB if you plan to compile and install Qt).
You also need time, so don’t try this guide if you are strict with some sort of deadline of yours. Depending on your computer, KDE compile process alone takes about 10 hours (Qt ~40 min), so take an afternoon/evening free (and let your computer do the looong compile process during the night).
Oh right, Kubuntu 12.04 (or other Ubuntu based distro) is needed of course
Erase every other DE?
Common sense would suggest to keep a stable desktop environment for rescue, if someday something goes terribly wrong and you can run nothing but a terminal console. However, from my personal experience (almost 3 years running KDE self-compiled), I’ve never witnessed any serious crash. Sometimes the build may fail due to XY component requiring a new version of a ZY library, but that’s all. Moral of the story: if you don’t feel comfortable with fixing a possible broken setup from the console (aka grep’ing the build log looking for errors, use vim/nano, lynx if needed etc …) then just play safe and keep your default DE
Brief intro about the steps we are going to walk
There’s nothing hard or difficult with compiling and setting up kde. In fact, the steps are the following:
- download the compiler + all the required libraries;
- download Qt sources (optional);
- download source libraries depending directly on Qt (you don’t need those if you keep Qt version shipped with your distro);
- download KDE sources;
- remove your old DE (optional);
- compile Qt + the libraries directly depending on it (again, you don’t need this if you keep Qt version shipped with your distro);
- compile KDE sources;
- finishing touches to make your freshly installed KDE fully functional;
- compile extra software which depends on Qt, like VLC (again, needed only if you compile Qt);
- extra task for the brave ones only
Step 0: downloading compiler and required libraries
Tha’s really simple: copy and paste this long command in your terminal, and then wait until everything has been downloaded and installed:
sudo apt-get install build-essential libcv-dev libopencv-dev libcvaux-dev libopencv-gpu-dev libwayland-dev libhighgui-dev libjpeg-dev cdbs debhelper cmake git-all bzr libstdc++6-4.7-dev libxml2-dev libxslt1-dev libtinyxml-dev libwpg-dev libbz2-dev shared-mime-info dbus-x11 libxkbfile-dev libgl1-mesa-dev libglu1-mesa-dev mesa-common-dev libxext-dev libical-dev libpng12-dev subversion libsm-dev libxinerama-dev libtiff4-dev libxrender-dev libfontconfig1-dev libboost-all-dev libxcursor-dev doxygen libgif-dev libdbus-1-dev libssl-dev libgpgme11-dev libasound2-dev kdesdk-scripts libpth-dev libjasper-dev ssh libglib2.0-dev libpcre3-dev diffstat libexpat-ocaml-dev libclucene-dev libclucene0ldbl libexiv2-dev quilt libspectre-dev xsltproc libxtst-dev libxdamage-dev libxcomposite-dev libaspell-dev libenchant-dev libsmbclient-dev libopenexr-dev libraw1394-dev libpulse-dev libpci-dev libusb-dev libnm-glib-dev libnm-glib-vpn-dev libnm-util-dev network-manager-dev libgphoto2-2-dev libeet-dev gstreamer0.10-plugins-base libcppunit-dev libgstreamer-plugins-base0.10-dev libssh2-1-dev libiw-dev libxss-dev libslp-dev lm-sensors bluez libbluetooth-dev libgps-dev libxklavier-dev libsasl2-dev acl flex bison libck-connector-dev libmono-2.0-dev libsensors4-dev libxrandr-dev lzma-dev libssh-dev libxft-dev libosip2-dev libeigen2-dev libdvdread-dev libmusicbrainz3-dev libmusicbrainz4-dev libflac-dev libflac++-dev libsndfile-dev libsamplerate-dev libogg-dev libmpcdec-dev libmad0-dev libmp3lame-dev libavbin-dev libavcodec-dev libswscale-dev libcdparanoia-dev mysql-server libmysqlclient-dev libmysqld-dev libtidy-dev libimlib2-dev libnl-dev libexempi-dev libv4l-dev xscreensaver libcfitsio3-dev libindi-dev xplanet libsane-dev libxxf86vm1 libchm-dev libdjvulibre-dev libepub-dev libacl1-dev libvncserver-dev libortp-dev libspeex-dev libotr2-dev libmsn-dev libmediastreamer-dev libmeanwhile-dev libgadu-dev libpilotobjects-dev libhunspell-dev libsvn-dev libarchive-dev libfftw3-dev libtheora0 libvorbisenc2 libxine-dev libxine-xvdr libmtp-dev libloudmouth1-dev libxine1-ffmpeg libgpod-nogtk-dev libaudio-dev liblcms1-dev libmng-dev libsqlite0 libsqlite0-dev libxmu-dev libgpod4-nogtk libpam0g-dev libffi-dev python-dev libgamin0 libgamin-dev libsearchclient-dev libraptor1-dev librdf0-dev libudev-dev libimlib2-dev liblzma-dev libdmtx-dev libqalculate-dev ruby-dev ruby libreadline-dev libindi-dev libfacile-ocaml-dev libopenbabel-dev libgsl0-dev libopenal-dev libmusicbrainz4-dev libantlr-dev virtuoso-opensource-6.1 virtuoso-opensource-6.1-bin virtuoso-opensource-6.1-common libxvmc-dev libgtk2.0-dev libgtk-3-dev docbook-xsl libxvmc-dev shared-desktop-ontologies libpolkit-agent-1-dev libpolkit-backend-1-dev libpolkit-gobject-1-dev libwrap0-dev libassuan-dev dblatex telepathy-core telepathy-devel telepathy-mission-control-5 libmission-control-plugins-dev libopenjpeg-dev libcanberra-dev libmusicbrainz3-dev libavformat-dev libhighgui-dev libcvaux-dev libzeitgeist-dev libqrencode-dev libglew1.6-dev libgsf-1-114 libgsf-1-common libgsf-1-dev liblcms2-dev libpqxx3-dev libspnav-dev libspnav0 libwpd-dev libwpg-dev libxbase2.0-0 libxbase2.0-dev libwpg-tools libopenvg1-mesa-dev gtk-doc-tools mono-mcs mono-dmcs mono-gmcs
Step 1: downloading Qt sources + libs depending directly on it
Create a folder where put all the sources you’re going to download, i.e. “src” in your Home folder. Open a terminal and type:
$ git clone git://gitorious.org/qt/qt.git
And then, the other libs you need (cd ~/src is omitted to save some space) :
$ git clone git://gitorious.org/qjson/qjson.git
$ bzr branch lp:libdbusmenu-qt
$ git clone git://git.freedesktop.org/git/poppler/poppler
$ git clone git://anongit.freedesktop.org/telepathy/telepathy-qt4
$ git clone https://github.com/mxcl/liblastfm.git
Note: if you don’t build Qt, instead of downloading the sources, just run sudo apt-get install libqjson-dev and so on (your package manager will help you for the correct lib names ).
Step 2: downloading KDE sources
Download the kdesrc-build utility from here: http://kdesrc-build.kde.org/ and then unpack it inside ~/src ; install the kdesrc-build executable in /usr/local/bin/ , and save my configuration script in your home dir (remove the .doc extension, thanks WordPress.com for the media upload restrictions <.<). kdesrc-build is a very complex and well made script that eases a lot your life: based on the config file options, he’s able to download entire modules source from the kde git repository, update/build/install them without any interaction. I strongly recommend you to open it and have a look to the options available (and adjust the paths too).
In fact, now you just have to type in your console
And wait until all the sources gets downloaded inside ~/src. If, for any reason, some module fails being downloaded, don’t panic! Just cd to the folder where that module should be downloaded and then issue a “git clone git://anongit.kde.org/path/of/the/module” command
[Fix to build libsoprano_virtuosobackend] : use the following patch -> http://paste.ubuntu.com/968384/ ; save it as patch.patch inside your kdesrc/soprano folder.
Then, simply type
$git apply patch.patch
and you’re done
Step 2: remove your old DE
You don’t need to perform this step if you planned to keep a rescue DE, so feel free to jump directly to Step 4.
Otherwise, hit CTRL+ALT+F1 to switch to tty1. From this point, we are gonna use only the terminal. Again, I highly suggest you to read the whole post before actually erasing your DE; if you encounter some lengthy commands and you’re afraid to forget some of them, it’s the last chance you have to copy/paste it inside a text file, and rename it i.e. as step$NUMBER.sh . In this way, from the console, a simple “sudo sh step$NUMBER.sh” will execute all the tedious command for you.
Assuming you have KDE, get rid of it is fairly simple:
$sudo apt-get remove kde-icons-oxygen libqt* libpoppler* poppler-utils libqca2 libqimageblitz4 libsoprano4 libstreamanalyzer0 libstreams0 kdebase-* kdegraphics* kdelibs5-data amarok-common kate-data kde-baseapps-data kde-runtime-data kde-workspace-data kdegames-card-data ksysguardd libakonadi-kabc4 libkipi-data libkonq5-templates language-pack-kde-en oxygen-icon-theme-complete oxygen-cursor-theme
If you have Gnome, I’m sorry but you have to figure it out on your own. I tried once to do that (when Canonical decided to drop the sponsorhip of Kubuntu, I started installing Ubuntu to get familiar with which packages I have to remove), but I failed miserably.. Every time I did an apt-get update, some gnome-related-crap was still installed on my computer, so that’s up to you (and if you successfully do that, drop a comment here so I can update this section ).
Step 3: compile Qt + libraries depending on it
From the terminal, cd to the folder containing the Qt sources. Qt automatically sets the branch with the current release (at the moment it’s 4.8) so you don’t need to do anything but configuring the sources with the following parameters (assuming to install the libraries in /opt/qt4 ):
./configure -debug -fast -no-separate-debug-info \
-system-libpng -system-libjpeg -system-zlib \
-dbus -webkit -no-phonon -plugin-sql-mysql \
-gtkstyle -developer-build -opensource\
-declarative -script -scripttools \
-nomake examples -nomake demos -prefix /opt/qt4 -v
Answer “yes”, and wait ~6 minutes until the configure process gets executed. Then, type “make” and leave your computer compile for about 40 minutes; if everything went right, type
$sudo make install && make distclean
to install the libraries and cleanup the source dir. Before compiling and installing everything else, it’s better to update few environment variables to expose Qt and the various libs we are going compile and install. Type the following lines (again, assume Qt installed under /opt/qt4 and kde installed -not yet- under /opt/kde4) :
export MAKEFLAGS=-j6 # instead of “6″, put your number of cpu cores+2 here
Now it’s time to compile the other libraries:
- cd to QJson source directory, and then type: mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR .. && sudo make install && rm -rf ../build
- cd to libdbusmenu-qt source dir, and type again: mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR .. && sudo make install && rm -rf ../build
- cd to poppler source dir and point to the last stable tag if you want (i.e. “git checkout poppler-0.19.3″) ; then, type: mkdir build && cd build && ../configure –prefix=$KDEDIR && make && sudo make install && rm -rf ../build
- cd to telepathy-qt4 dir and again, point to the last stable tag if you want (as for poppler, I’ve always compiled from master branch) then type: mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR .. && sudo make install && rm -rf ../build
- and now, go to liblastfm dir, point to the last stable tag if you want, and type ./configure –prefix $KDEDIR && make && sudo make install && make distclean
Step 4: compile KDE (!)
This is the simplest step of all the entire post: write this
$sudo kdesrc-build –no-src
hit enter, and go to sleep
Note: you may have noticed that kdesrc-build can download and build/install the modules in one go; however I keep this two steps decoupled for a couple of reasons:
- i’d like to update first all the sources before going to sleep and keep my laptop disconnected from the internet during the night (many friends of mine got they console/tv/pc video card burned by a thunder when they were sleeping/away sooooo let’s try to minimize the risk);
- for the reason above, you can have quickly notice if some module has been moved/renamed (happened a LOT of times within kde telepathy projects);
- there is no valid reason to update a module using root privileges at all.
Step 5: compile KDE (!)
“Are you fucking kidding me?” you might say.. Due to an unfortunate circular dependency, the answer is no. Don’t get me wrong: it’s nothing that will block you from loading kde (it’s just polkit-kde-kcmmodules that didn’t compiled because it requires kde-workspace, but kde-workspace in turn requires –optionally– polkit, so everything works fine except that) and gets automatically fixed the second time you rebuild kde,so if you want, you can start use kde right now: it’s just me being nitpick about the need to have everything compiled before going further
To be completely sure about that, type that command:
$sudo kdesrc-build –no-src polkit-kde-kcmodules-1 kdelibs kde-workspace
and wait for finished.
Step 6: finishing touches
Now it’s time to tell the system how to load your self-compiled kde environment. First of all, inform X11 to use kdm:
$sudo nano /etc/X11/default-display-manager
and change the line from /bin/kdm to /opt/kde4/bin/kdm . Then, open kdm.conf file:
$sudo nano /etc/init/kdm.conf
and again, replace all the occurrences of /bin/kdm with /opt/kde4/bin/kdm . At this point, X11 knows how to launch kdm, but kdm itself doesn’t know anything yet about what to do when an user logs in. To fix that, create a kde4.desktop file wherever you want, and put the following lines:
Name=KDE 4.9 (from trunk)
Save it, copy it into /opt/kde4/share/apps/kdm/sessions/ and give rx permissions. Now kdm knows that it has to execute the script called kdestart.sh, when the option “KDE 4.9 (from trunk)” is selected: let’s create it, and add these two lines
Save it, copy it into /opt/kde4/bin/ and give rx permissions. Ok, a script which calls an other script, whoooo! (Reason: Exec and TryExcec lines doesn’t allow run multiple commands, so we have to fake it. If you don’t plan to use ssh, just skip the previous script creation and modify the .desktop file accordingly)
Startkde.sh is more simple to create:
$sudo cp /opt/kde4/bin/startkde /opt/kde4/bin/startkde.sh
But why do we do that? Because inside startkde.sh we are going to add some extra definitions to run kde properly; if we would add them in kdestart script instead, that file will be overwritten the next time you rebuild kde, losing our definitions. The lines you have to add, right after the comments at the very beginning of the file, are the bunch of exports you’ve already seen in Step 3. The beginning of startkde.sh after that modification will look like this:
# DEFAULT KDE STARTUP SCRIPT ( 4.8.3 (4.8.3) )
Good, now we are almost finished. In fact, due to DBus and polkit strictness, you need to copy some files from $KDEDIR to /usr to get everything work fine (aka dialog requiring root password). Let’s fix these last details!
$sudo cp /opt/kde/share/polkit-1/actions/* /usr/share/polkit-1/actions/
$sudo cp /opt/kde4/share/dbus-1/interfaces/* /usr/share/dbus-1/interfaces/
$sudo cp /opt/kde4/share/dbus-1/services/* /usr/share/dbus-1/services/
$sudo cp /opt/kde4/share/dbus-1/system-services/* /usr/share/dbus-1/system-services/
Extra: if you want to configure kde to detect and interact with grub2/burg, you may be interested in reading the developer’s blog. It has a very descriptive tutorial!
Now everything is working: reboot and enjoy kde!
Extra: compile and install VLC
Compiling VLC is really easy; as always, download its dependencies
$sudo apt-get install libavformat-dev libavutil-dev libpostproc-dev liba52-0.7.4-dev libxcb-shm0-dev libxcb-xv0-dev libx11-xcb-dev libsdl1.2-dev libfribidi-dev libmatroska-dev libfaad-dev libtwolame-dev libdca-dev libmpeg2-4-dev libtheora-dev libx264-dev libxpm-dev libdca-dev libmpeg2-4-dev libtheora-dev libx264-dev libmpeg2-4-dev libdca-dev libtheora-dev libx264-dev libsdl-image1.2-dev libcddb2 libcddb2-dev libconfig++8 libdirac-decoder0 libdirac-dev libdirac-encoder0 libdvbpsi-dev libffado-dev libffado2 libfluidsynth-dev libfluidsynth1 libjack-dev libjack0 libmodplug-dev liborc-0.4-dev libportaudio-dev libportaudio0 librsvg2-dev libschroedinger-dev libshout3-dev libtar libtar-dev libupnp-dev libupnp3 libupnp3-dev libxml++2.6-2 libzvbi-common libzvbi-dev libzvbi0 libxpm-dev libvdpau-dev libva-dev x11proto-xf86dri-dev x11proto-dri2-dev liblivemedia-dev libdc1394-22-dev libavc1394-dev libportaudio-dev libprojectm-dev libxcb-keysyms1-dev libxcb-composite0-dev libncursesw5-dev
Then download the latest stable tarball from their website, exctract its content and move inside that directory. Type
$mkdir build && cd build && ../configure –enable-libva –enable-xvideo –enable-sdl –enable-avcodec –enable-avformat –enable-swscale –enable-mad –enable-a52 –enable-libmpeg2 –enable-dvdnav –enable-faad –enable-vorbis –enable-ogg –enable-theora –enable-mkv –enable-freetype –enable-fribidi –enable-speex –disable-flac –disable-taglib –enable-live555 –enable-caca –enable-skins2 –enable-alsa –enable-qt4 –enable-ncurses –enable-realrtsp –enable-twolame –enable-real –enable-mozilla –with-mozilla-pkg=xulrunner-plugin –enable-x264 –disable-lua –disable-mozilla –prefix=/opt && make && sudo make install && rm -rf ../build
and create some symbolic link to make it work
$sudo ln -s /opt/lib/libvlc* /usr/lib/
$sudo ln -s /usr/local/lib/libx264.a /usr/lib/
$sudo ln -s /opt/lib/vlc /usr/lib/vlc
Oh, and if you prefer QtCreator over KDevelop, building it is very simple:
$git clone git://gitorious.org/qt-creator/qt-creator.git
$cd qt-creator && qmake qt-creator.pro && make && sudo make install && make distclean
Only the brave: Build KDE .. with gcc-snapshot toolchain
To download it, you need to add the corresponding ppa:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get install gcc-snapshot
and then make it the default one with the following commands:
sudo update-alternatives –install /usr/bin/gcc gcc /usr/lib/gcc-snapshot/bin/gcc 40
sudo update-alternatives –install /usr/bin/g++ g++ /usr/lib/gcc-snapshot/bin/g++ 40
sudo update-alternatives –config gcc
sudo update-alternatives –config g++
and select from the menu the gcc-snapshot version
Aaand here it is one screenshot from my Devel activity, with some tweaks like using Oxygen Fonts, better (imho) tab style, a less intrusive “current window” shadow.