66

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?

Gili
  • 1,295

4 Answers4

29

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.

January
  • 35,952
  • This looks promising. Using apt-get source without --compile seems to suppress the warning about unmet dependencies (allowing me to resolve them myself) – Gili Sep 27 '12 at 14:47
  • Is there a way to get packages that have no source this way as well? – soandos Feb 18 '14 at 16:03
  • Solution (2) will work regardless. Otherwise, you are on your own: maybe there is another way of installing package. Or download the deb package file and unpack it with ar: ar vx mypackage.deb. Then analyse the contents of the package and find out how to install it manually. – January Feb 18 '14 at 21:26
17

using a bash shell, and acquiring the "package.deb" file (assuming pack name is "package") you can run the following command to accomplish what you want - installing the package so that your home directory is treated the same way "/" would be treated in a normal install.

This is the command:

apt-get download package; dpkg -i --force-not-root --root=$HOME package.deb

You might face some errors, such as $HOME/var/lib/dpkg/lock is missing so just create all the missing files you will get from the errors and then the install should work without sudo.

notice that if "apt-get download" doesn't work, you can try "apt download" or "apitutde download package".

if neither methods work, you can just download the package manually from http://packages.ubuntu.com/

another method would be to run the chroot command with the parameter $HOME and then installing the same way as above only without --root=$HOME. that command would bring you in a shell where "/" is your current $HOME. to return to normal mode don't forget to "exit"

good luck.

AmazingMiki
  • 303
  • 3
  • 8
  • After creating the missing files dpkg complained about, it just started segfaulting. – Matt Chambers Nov 13 '17 at 18:05
  • 1
    Please note that man dpkg mentions that when using the --force family of options the following applies: "Warning: These options are mostly intended to be used by experts only. Using them without fully understanding their effects may break your whole system." – XavierStuvw Feb 12 '20 at 12:17
5

If you're on a shared web-hoster with ssh access but no apt-get no root etc. or a similarly restricted system the following may work for you. It worked for me on a system where uname -a returned something like SMP Debian 4.9.65-3+deb9u2~bpo8+1 (2017-01-05) x86_64 GNU/Linux

# examples tried on a shared hoster with ssh access but no apt-get no root etc.
# http://mirrors.kernel.org/ubuntu/pool/main/g/gawk/gawk_4.1.3+dfsg-0.1_amd64.deb
# https://github.com/dvorka/hstr/releases/download/1.25/hstr_1.25-1_amd64.deb

debURL="http://mirrors.kernel.org/ubuntu/pool/main/g/gawk/gawk_4.1.3+dfsg-0.1_amd64.deb"
# get the filename only, remove all till last slash "/"
# see http://wiki.bash-hackers.org/syntax/pe#substring_removal
debFile=${debURL##*/}
# change to your desired directory for installation/unpacking; here: $HOME
cd $HOME
# get the .deb file (no dependencies checked or resolved here)
curl -OL $debURL 
# unpack only the data part from the .deb file
# see https://en.wikipedia.org/wiki/Deb_%28file_format%29
ar p $debFile data.tar.xz | tar xJv --strip-components=2 -f - 
rm -v $debFile # clean up
echo "Done unpacking $debFile into $(pwd)"
iolsmit
  • 151
  • 1
  • 3
0

unpacking the .deb file might or might not work for your application. My suggestion is to get source code and compile, and install it in your local folder. That should be the universal solution for this question.