Compile source packages on Ubuntu

ubuntu_apps_compIf you like to tweak applications your own way before installing them you will need to compile the source packages and install them. It may seem intimidating on Linux due to the so-called dependency hell. Ubuntu simplifies that for you to the extent that it automatically downloads all dependencies. There are two ways to do this:

  • apt-build: You may need to install apt-build first using synaptic. The syntax to build a package is:
    # apt-build install packagename
  • apt-get: I prefer this as it breaks down the process to provide a finer control. The syntax is:
    # sudo apt-get build-dep packagename //download package dependencies
    # apt-get -b source packagename //creates a .deb package
    # dpkg -i packagename.deb //install the package

To make changes to the package source code, compile and install, check this thread.

Repack installed packages on Ubuntu

ubuntu_logo_81x81I often try out several utilities on my system and forget to backup the deb packages. I was thinking of writing a small tool to repackage installed deb files on Ubuntu so that I can get back the deb file anytime I want. I found dpkg-repack which does exactly the same thing i.e. rebuild or regenerate a deb package from files installed on the system by the original package. It can handle a single package or a list of all packages on your system. Straight to the operations:

dpkg-repack is not installed by default. Install it:

# apt-get install dpkg-repack

To repackage a single package:

# dpkg-repack package_name

To repackage multiple or all the installed packages:

  1. List all the package present in your system in a file:
    # dpkg --get-selections | cut -f 1 > files.txt

    At this point you can edit the file to remove some packages

  2. You have to have package names space separated. Open the file in vi. Press gg to go to the first line and issue the following:
    :%s/\n/ /g

    Note that there is a space between / /. This will convert all the newlines to spaces.

  3. Issue the following to save and exit vi:
    :wq
  4. Copy the content of the file. Run the following to repackage:
    # dpkg-repack paste_file_contents_here

Unpack, modify and repack deb files

ubuntu_logo_81x81There are instances when you need to modify some file(s) inside a deb package and repack it for installation. This can be done very easily on Ubuntu and Debian using dkpg-deb:

  1. Copy the deb file to a directory
  2. Create the directory structure
    $ mkdir -p newpack oldpack/DEBIAN
  3. Extract the filesystem tree
    $ dpkg-deb -x file.deb oldpack/
  4. Extract the control information files
    $ dpkg-deb -e file.deb oldpack/DEBIAN
  5. Modify something if you want
  6. Repackage the deb file under newpack directory using xz compression
    $ dpkg-deb -Z xz -b oldpack/ newpack/

Check if a package is officially available in an Ubuntu release

ubuntu_apps_compUbuntu has thousands of packages. New apps get added and older or obsolete apps get dropped in each new release. Sometimes it becomes difficult to know if an app is officially available in a particular release. There is a simple way to verify. Open the following search link in your browser:
http://packages.ubuntu.com/search?keywords=packagename

Replace packagename with the name of the package you are looking for. For example, to look for pidgin, open the following link:
http://packages.ubuntu.com/search?keywords=pidgin

To check which versions of a package are available:

# apt-cache policy <packagename>

Rescue Ubuntu from unstable PPA issues

ubuntu_logo_81x81It’s too tempting to test out development versions of software and subsystems from PPAs and sometimes there are chances that you will end up in an unstable Ubuntu system. While it is very easy to figure out and fix issues with a single application, things can get complicated when you have an unstable subsystem like X or your desktop environment. I faced a similar situation recently. As I have no plans to move to Ubuntu Saucy from Raring now, I updated to Gnome 3.8 to get a taste of it. Things were running smoothly till I couldn’t wait to check out Gnome 3.10 as well. I installed packages from gnome3-staging and the ricotz-testing PPA and on the next login my notifications won’t work correctly, my custom theme got broken and the panel started refreshing on every window close. I had to struggle a while but I finally sorted things out by moving back to Gnome 3.6 from the Raring official repositories. This article explains how. Symptoms and related packages might be different on another system but the procedure to recover should be similar. Be warned, you need patience to get this done if your system is messed up pretty bad, sometimes even hours depending on your expertise and network speed.

First, you may need to install a different desktop environment to work within. For example, you can’t remove and recover Gnome from within it. As I already had LXDE, I logged-in to LXDE. In addition, have synaptic and ppa-purge installed beforehand. You will have a great advantage if you already had synaptic installed on your system and had history enabled (read, have history enabled from now if you are disabling it). Also, do not reboot till you are done as your system may not boot if you have tampered some boot related packages.

The next step is to try ppa-purge. Try removing the PPAs that led to the problems. The syntax is:

$ sudo ppa-purge ppa:gnome3-team/gnome3 //replace with intended PPA name

Keep a very keen eye on the changes it is going to do to your system before confirming anything, specially the following two sections if they are present:

Remove the following packages:
1) apturl
2) compiz
3) compiz-core
4) compiz-gnome
5) compiz-plugins-default
6) compizconfig-settings-manager
7) evince
...

Leave the following dependencies unresolved:
43) gnome-terminal-data recommends gnome-terminal
44) gucharmap recommends yelp
45) indicator-appmenu recommends indicator-applet | indicator-renderer
...

You may need to manually handle the packages listed in these two sections later, so save them in a text file. If nothing is listed, great! Probably this is the last step you need and you can skip the rest of this article. Otherwise, read ahead. Run:

$ sudo apt-get update

Once you are done with purging the PPAs and you have ended up with a huge list of removed software, open synaptic as root if it is still installed. Otherwise, skip and jump to the next paragraph from here. Try to find the packages (at least some) you have just upgraded (synaptic history could be of great help here if you had it enabled). Select any of the packages and go to Package ▸ Force Version… In the drop down list select the latest version from the base repositories (e.g. in my case raring or raring-updates). Once done, apply the changes. If any package is broken, either remove those as well or, to be safe, stop at the point something is broken and apply just the previous changes. After some iterations this exercise becomes tedious from synaptic due to the numerous dependency packages. Stop and go to the next paragraph to do the same from the terminal in another way.

Open a terminal and become root as you probably won’t love to type sudo repeatedly from now. Open the test file you got from ppa-purge above. Try to start with the important base packages as they will handle their dependencies while installing. For me it was gnome-session. But as you may still have some packages in the system which are at a higher version than provided by base release repositories you will not be able to install everything using apt-get. Here is an example of what I mean; follow the text in bold and the corresponding comments:

root@Tux # apt-get install gnome-terminal //trying to install gnome-terminal
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
gnome-terminal : Depends: libvte-2.90-9 (>= 1:0.30.1-2ubuntu1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

root@Tux # apt-get install libvte-2.90-9 //gnome-terminal depends on libvte-xxx
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libvte-2.90-9 : Depends: libvte-2.90-common (= 1:0.34.2-0ubuntu2) but 1:0.34.6-1ubuntu1~ubuntu13.04.1 is to be installed
E: Unable to correct problems, you have held broken packages.

root@Tux # apt-get install libvte-2.90-common //libvte epends on libvte-xxx-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
libvte-2.90-common is already the newest version. //already at a higher version from another PPA
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

root@Tux # apt-get remove libvte-2.90-common //remove higer version from other PPA
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libvte-2.90-common
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,390 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 113274 files and directories currently installed.)
Removing libvte-2.90-common ...

root@Tux # apt-get install libvte-2.90-common //install libvte-xxx-common from standard repo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libvte-2.90-common
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.5 kB of archives.
After this operation, 455 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ raring/main libvte-2.90-common all 1:0.34.2-0ubuntu2 [22.5 kB]
Fetched 22.5 kB in 0s (25.3 kB/s)
Selecting previously unselected package libvte-2.90-common.
(Reading database ... 113174 files and directories currently installed.)
Unpacking libvte-2.90-common (from .../libvte-2.90-common_1%3a0.34.2-0ubuntu2_all.deb) ...
Setting up libvte-2.90-common (1:0.34.2-0ubuntu2) ...
Installing new version of config file /etc/profile.d/vte.sh ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB
localepurge: Disk space freed in /usr/share/gnome/help: 0 KiB
localepurge: Disk space freed in /usr/share/omf: 0 KiB

Total disk space freed by localepurge: 0 KiB

root@Tux # apt-get install gnome-terminal //install gnome-terminal
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
gnome-terminal-data gnome-user-guide libvte-2.90-9 libwebkitgtk-3.0-0
libyelp0 yelp
Suggested packages:
gstreamer1.0-ffmpeg
The following NEW packages will be installed:
gnome-terminal gnome-terminal-data gnome-user-guide libvte-2.90-9
libwebkitgtk-3.0-0 libyelp0 yelp
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.3 MB/10.4 MB of archives.
After this operation, 57.9 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com/ubuntu/ raring/main libvte-2.90-9 amd64 1:0.34.2-0ubuntu2 [258 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ raring/main libwebkitgtk-3.0-0 amd64 1.10.2-0ubuntu1 [8,231 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ raring/main libyelp0 amd64 3.6.2-0ubuntu1 [109 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ raring/main yelp amd64 3.6.2-0ubuntu1 [43.3 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ raring/main gnome-user-guide all 3.6.2-0ubuntu1 [1,632 kB]
Fetched 10.3 MB in 49s (208 kB/s)
Selecting previously unselected package libvte-2.90-9.
(Reading database ... 113180 files and directories currently installed.)
Unpacking libvte-2.90-9 (from .../libvte-2.90-9_1%3a0.34.2-0ubuntu2_amd64.deb) ...
Selecting previously unselected package gnome-terminal-data.
Unpacking gnome-terminal-data (from .../gnome-terminal-data_3.6.1-0ubuntu4_all.deb) ...
Selecting previously unselected package gnome-terminal.
Unpacking gnome-terminal (from .../gnome-terminal_3.6.1-0ubuntu4_amd64.deb) ...
Selecting previously unselected package libwebkitgtk-3.0-0.
Unpacking libwebkitgtk-3.0-0 (from .../libwebkitgtk-3.0-0_1.10.2-0ubuntu1_amd64.deb) ...
Selecting previously unselected package libyelp0.
Unpacking libyelp0 (from .../libyelp0_3.6.2-0ubuntu1_amd64.deb) ...
Selecting previously unselected package yelp.
Unpacking yelp (from .../yelp_3.6.2-0ubuntu1_amd64.deb) ...
Selecting previously unselected package gnome-user-guide.
Unpacking gnome-user-guide (from .../gnome-user-guide_3.6.2-0ubuntu1_all.deb) ...
Processing triggers for gconf2 ...
Processing triggers for menu ...
Processing triggers for gnome-menus ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils ...
Processing triggers for man-db ...
Processing triggers for libglib2.0-0:amd64 ...
Setting up libvte-2.90-9 (1:0.34.2-0ubuntu2) ...
Setting up gnome-terminal-data (3.6.1-0ubuntu4) ...
Setting up gnome-terminal (3.6.1-0ubuntu4) ...
Setting up libwebkitgtk-3.0-0 (1.10.2-0ubuntu1) ...
Setting up libyelp0 (3.6.2-0ubuntu1) ...
Setting up yelp (3.6.2-0ubuntu1) ...
Setting up gnome-user-guide (3.6.2-0ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for menu ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB
localepurge: Disk space freed in /usr/share/gnome/help: 0 KiB
localepurge: Disk space freed in /usr/share/omf: 0 KiB

Total disk space freed by localepurge: 0 KiB

root@Tux # //done with gnome-terminal

This shows that you need to dig to the last conflict, remove the rogue package and then install it again whence it will be installed from the default release repositories. However, you can reduce the number of steps greatly if you start with the important base packages. In addition, remember that one package might also have multiple unresolved conflicts and the procedure is same for all.

Once done, probably you will be back to your standard repository packages ;). Log out and try logging in to Unity.

Linux package converters

ubuntu_apps_compWhile having numerous Linux distros has a great advantage of choice, one drawback is that package management is not unified yet. Packaging system is different on the major distros and their forks. Though it happens almost never on Ubuntu, I am pretty sure some other distro user might face situations where a particular software is not packaged for his distro. Quite unfortunate and frustrating when we consider the fact that all these distros are just userspace forks running the same kernel in the core.

One possible solution to this problem is package conversion. Though it won’t work with core system packages many a time it comes handy when normal apps packages are converted. Here are 2 apps which do the same on Linux:

Find out which package a file belongs to on Ubuntu

ubuntu_apps_compIn a previous post I wrote about how to know which files are installed by a package. Here’s the reverse of that – how to detect which package installed a particular file. dpkg -S does that. I was looking for a way to know which package the process gnome-pty-helper belongs to when I googled it out.

$ dpkg -S gnome-pty-helper
libvte-2.90-9: /usr/lib/libvte-2.90-9/gnome-pty-helper

dpkg -S searches for the pattern. So it’s advisable to use the absolute path to the file for more accurate results.

Ubuntu: baseline and clone a setup

ubuntu_apps_compIt’s difficult to remember the configuration of all your applications while migrating to a different workstation or doing a fresh install or just upgrading. Here’s a crude procedure to migrate settings from one system to another.

  1. Copy your home directory to an external device. Include hidden files.
  2. Prepare a list of applications installed:
    $ sudo dpkg-get-selection > /home/username/package.selections
  3. Backup /etc/apt/sources.list
  4. Complete the new installation
  5. Copy sources.list from Step 3 to /etc/apt
  6. Run
    $ sudo apt-get update
  7. Run
    $ sudo dpkg –set-selections /home/package.selections && apt-get dselect-upgrade
  8. Copy config files (including .config directory and files within it) of backup home directory from Step 1 in your new home directory.

which vs. whereis vs. dpkg -L

terminalWhile most people using any flavour of Linux must have used which to locate where an executable binary of a command is located, a similar utility whereis may not be so well-known. which looks for a binary within the directories in your $PATH. whereis on the other hand returns you a lot more; it shows you almost everything that came with the command – binary, source code and the man pages location. Quite useful! Example:

$ whereis ls

Now let’s see what dpkg -L can do for Debian packages. You installed a .deb file and you want to know quickly which are the files that got installed with it. Here’s how to do it:

To get the correct name of the package gcstar:

$ dpkg --get-selections|grep gcstar
gcstar                        install

To see which files were installed by this package:

$ dpkg -L gcstar