Ubuntu – Installing packages into local directory

aptcompiling

I'd like to install software packages, similar to apt-get install <foo> but:

  1. Without sudo, and
  2. Into a local directory

The purpose of this exercise is to isolate independent builds in my continuous integration server.

I don't mind compiling from source, if that's what it takes, but obviously I'd prefer the simplest approach possible. I tried apt-get source --compile <foo> as mentioned here but I can't get it working for packages like autoconf. I get the following error:

dpkg-checkbuilddeps: Unmet build dependencies: help2man

I've got help2man compiled in a local directory, but I don't know how to inform apt-get of that. Any ideas?

UPDATE: I found an answer that almost works at https://askubuntu.com/a/350/23678. The problem with chroot is that it requires sudo. The problem with apt-get source is that I don't know how to resolve dependencies. I must say, chroot looks very appealing. Is there an equivalent command that doesn't require sudo?

Best Answer

This is, in general, not doable, because you would mess with the apt dependencies system.

There are two solutions:

  1. Install the source package, change into the source directory, configure and install the package irrespective of the packaging systems manually to a directory of your choice.

    apt-get source <package>
    

    This does not need root, downloads the package source, unpacks it in a directory within the current directory. You can then change to that directory, make modifications to the source, configure the installation to another target etc.

    Configuring to which installation directory the programs should go depends, however, on the particular program. Many programs use the ./configure --prefix localdir to target the installation to localdir; but this is by far not always the case.

  2. Create a chroot environment into which you will install the packages:

    debootstrap precise myfancyinstall
    

    Now you have created a dummy installation in the myfancyinstall/ directory

    chroot myfancyinstall
    

    You can use apt-get install within the chroot cage to install whatever you wish.