65

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?

7
  • I suggest that's a duplicate of this question : [askubuntu.com/questions/147654/… [1]: askubuntu.com/questions/147654/…
    – user91632
    Sep 27, 2012 at 14:30
  • 9
    @kamil, it's not. I'm not trying to install without network access. I'm trying to install without sudo and into a non-system directory.
    – Gili
    Sep 27, 2012 at 14:35
  • If you don't have root on the system, you will not be able to resolve dependencies easily. It is sometimes possible, though; you would have to start installing the software in your home, starting with the bottom-most dependencies, and modifying your LD_PATH so that programs can find their libraries. However, you will fail if any of the packages requires root (or suid) to run.
    – January
    Sep 27, 2012 at 16:51
  • @January, I'm trying to compile a software project inside an automated build system. As far as I know, none of its dependencies (required to compile) require root.
    – Gili
    Sep 27, 2012 at 16:57
  • Well, then install the dependencies one by one manually. I don't see another solution that does not require root.
    – January
    Sep 27, 2012 at 17:00

4 Answers 4

28

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.

3
  • 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, 2012 at 14:47
  • Is there a way to get packages that have no source this way as well?
    – soandos
    Feb 18, 2014 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, 2014 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.

2
  • After creating the missing files dpkg complained about, it just started segfaulting. Nov 13, 2017 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." Feb 12, 2020 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)"
2
  • You're a genius man :) Thanks!!!
    – xfra35
    May 19, 2020 at 14:16
  • This is far better than the above two and should be the accepted answer.
    – xpt
    Jul 16, 2021 at 4:59
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .