The Linux Page

How to recompile a package on Ubuntu and install the new version.

I have a problem with a package that doesn't exactly do what I need it to do so I wanted to recompile it.

Here are the steps to take to get the source, modify it, recompile the new version, and finally install that new version.

WARNING

Before you start, make sure that you make a copy of all the current settings. The installation step is not unlikely going to overwrite any existing changes.

So... let's assume that the package was well done and thus that the author properly tested that all the necessary build development tools are specified on the corresponding line in the spec file you can get them with:

    sudo apt-get build-dep <package-name>

Note that the name of the package may vary from the name of the .deb file because apt-get has some aliasing going on...

The next step is to get the source code. The cool thing here is that it takes the source and applies all the patches to it automatically. Really neat.

    apt-get source <package-name>

If all you wanted to do is try to recompile the source code you could use the -b flag (i.e. build). However, here I expect you to make changes to the source code first. Note that the source is downloaded in the current directory. So... you do not need the sudo command and you may want to first create a sub-folder:

    mkdir my-version-of-<package-name>
    cd my-version-of-<package-name>

Change directory (cd) to the folder you just created, get the source as indicated, change directory again to go inside that project (it should be nearly the same name without the ubuntu revision,) then in that same folder run the build command.

    dpkg-buildpackage -rfakeroot -uc -b

The build command configures the package, recompiles everything, and then creates the .deb file(s) of the package. Again, you do not need to be root to run this command. Actually, I strongly advice that you do NOT use sudo because it could create problems later.

Assuming you made changes to the code, you may get errors while recompiling. If so, fix the code and try again. If the code fixes you're making are pretty extensive, you may want to use make to test that it works. Once it does work, run the dpkg-buildpackage tool again and at least you should see the new .deb files.

WARNING

Before you install the new version of the module, make sure you made a copy of all the current settings. The installation step is not unlikely going to overwrite any existing changes.

Now that we got a .deb file (should be one directory up, right outside of the compilation directory,) we can install it with the dpkg tool.

    dpkg -i <package-name>.deb

Again, the  <package-name> may be different with a different set of versions in the string. Use ls to find out first.