Modifying, Building and Installing From Source in Ubuntu

Sometimes, you encounter something in Ubuntu that you'd like to change.  Most of the time, you can do this by opening some sort of preferences menu and checking a few boxes.  Other times, you might need to fire up dconf-editor or gconf-editor to manually modify keys in the dconf and gconf configuration databases.  This works well and is relatively simple, but it's up to the developers what settings you can change this way.

On other occasions, you may want to modify the program's source code instead.  This may be because you want to make big changes such as adding or removing major features, or it may just be that a configuration parameter that you want to change has been hardcoded into the source [which is arguably bad design!].

One of the major advantages of open source software is that the source is open, so this is possible!  It's also very straightforward, once you learn how.

For this example, I'll be modifying 'gnome-settings-daemon'.  By default, the system volume changes by 6% each time the 'volume up' and 'volume down' media keys on my keyboard are pressed.  6% is a pretty big jump, and it's easy to go from 'not quite loud enough' to 'way too loud' in a single button press.  I'm constantly opening up the graphical slider to get the volume just right.  This is extremely annoying, so I'm going to change it!

Installing The Tools

You'll need a few things to get started.  Install the necessary tools with:

sudo apt-get install devscripts dpkg-dev build-essential fakeroot bzr bzr-builddeb

Create a directory to hold the source code you'll be working on.

Making Your Changes

Open up a terminal and change directory into the directory you just created.
Use the Bazaar distributed version control software to download a copy of the source of the package you want to edit:

bzr branch lp:ubuntu/precise/gnome-settings-daemon

(I included 'precise' because I want the version for Ubuntu 12.04, 'Precise Pangolin'; if you want the branch for the newest Ubuntu distribution [currently 13.10, 'Saucy Salamander'], use lp:ubuntu/gnome-settings-daemon instead.)

Now, navigate into the source files you just downloaded and make the desired changes.  In my case:

cd gnome-settings-daemon/plugins/media-keys
nano gsd-media-keys-manager.c

(In the Nano text editor, I searched [ctrl-w] for 'volume_step', reduced the percentage step size from 6% to 2%, exited [ctrl-x] and saved.)

To update the package's version number and document your changes in the changelog:

debchange -i

Commit your changes locally, build a .deb installer file from the modified source, and install it:

bzr builddeb -- -b -us -uc
sudo dpkg -i ../your-package-name.deb

Success!  Restart your computer and test out your changes.  

Further reading


Besides just coding, there are many ways to contribute to an open-source project like Ubuntu: