215

I have no root access on this machine.

I would like to know if there is a way I can download Ubuntu packages and install them as non-root?

Probably in my ~/bin or ~/usr/share or something like that? Would that work?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Weboide
  • 10,493

4 Answers4

186

Apt doesn't support it directly, but there are ways to do it:

.deb Approach

apt-get download package_name  # replace `package_name` with the name of the package.

dpkg -x package.deb dir

If the deb isn't in the Ubuntu repositories, apt-get download package_name won't work, but you may be able to download it from a web site.

This will extract the .deb package to dir/. Then you can export the PATH where the binary is. As long as all dependencies of the binary are installed, it should run as normal.

schroot Approach

Another approach is to use schroot to create a non-root chroot. This is a somewhat involved process, but one you should be able find community help for as many developers set up chroot environments for compiling code.

apt-get source Approach

Finally, you could use the apt-get source command to fetch the source of the package and configure it to install locally. Usually this looks something like:

apt-get source package
cd package
./configure --prefix=$HOME
make
make install

The disadvantage to this approach is that you need the development environment available for this approach to work at all, and you might find yourself compiling dozens of packages in order to resolve all the dependencies.

Historical Approach

It used to be possible to install package.deb with dpkg into one's home directory.

dpkg -i package.deb --force-not-root --root=$HOME

The disadvantage to using dpkg like this is that error messages are likely to be cryptic; dpkg doesn't automatically resolve dependencies or create the directory structure it expects.

Savçı
  • 43
jbowtie
  • 13,195
  • 2
    If you have root access but just don't want to install a particular package globally, you could use sudo apt-get build-dep package to install everything required to build a package (after getting its source with apt-get source). – Vladimir Panteleev Jan 14 '13 at 22:25
  • the instructions to create a chroot seem to require root privileges ... Is there a way to use chroot without needing such privileges ? – josinalvo Feb 27 '13 at 14:44
  • @josinalvo, check for schroot – user.dz Mar 19 '14 at 22:45
  • You could also build a deb package that installs somewhere beside the usual system directories, but that would be extremely eccentric. Though occasionally done, usually by corporate entities like Google. – Faheem Mitha Aug 08 '14 at 13:13
  • 27
    This answer was written back in 2010. Have there been any changes to how this is done since then? – a06e Sep 16 '14 at 18:30
  • I just tried using method 2 (dpkg -i) and I'm getting the following error. Any ideas? dpkg: error: unable to access dpkg status area: No such file or directory – krasnaya Oct 24 '14 at 16:19
  • 44
    Even with --force-not-root, I get "dpkg: error: requested operation requires superuser privilege" – Clément Apr 19 '16 at 13:37
  • 18
    Folks, --force-not-root --root=$HOME, or variations thereof will not work. Debian binary packages are not designed to be installed in the home directory, period. Or, to put this another way,. "The following example will install package.deb into your home directory.". No, it won't. – Faheem Mitha Jun 13 '17 at 17:54
  • 4
    Sadly this won't work. I tried --force-not-root --root=/your/custom/path – Viet Jun 22 '17 at 10:12
  • @krasnaya, there are a few files/directories you'll need to create within your intended install dir: touch status, mkdir updates, and there may be one or two more. Use the error messages that appear to guide you. – Jellicle Jul 05 '18 at 15:44
  • dpkg -x <package.deb> <dir> this worked for me.
    things i learned that once you ran this command don't export but instead export path where binary files of that package are present e.g. I exported this path /path/to/dir/usr/bin/ with this command export PATH="/path/to/dir/usr/bin:$PATH"
    – Ahwar Jun 03 '20 at 16:48
  • 1
    Note that some binary packages such as bison have binaries that include hard-coded paths to files such as /usr/share/bison/m4sugar/m4sugar.m4. For such packages, a non-root working installation is impossible using dpkg -x and the only way to install non-root is by building from source. – Jonathan Ben-Avraham Apr 04 '22 at 16:41
  • how does it know where the package is after I download i.e. how does dpkg -x package.deb dir work? – Charlie Parker Dec 06 '22 at 02:01
  • @CharlieParker, dpkg -x package.deb <dir> just extracts the package, and the system doesn't know where it is. That's why you have to export PATH=$PATH:<dir>. – Jake Stevens-Haas Aug 30 '23 at 22:57
19

I assume you want to install jedit. First you have to find the package and download it. I just take the deb file from some mirror and open a console/terminal:

  1. mkdir /tmp/jedit && cd /tmp/jedit -- Makes a new diretory in tmp and changes into it.
  2. wget http://mirrors.kernel.org/ubuntu/pool/universe/j/jedit/jedit_4.3.1.dfsg-0ubuntu1_all.deb -- Download package
  3. ar x jedit_4.3.1.dfsg-0ubuntu1_all.deb or, easy to type, ar x *.deb -- this extracts the file contents
  4. tar xvzf data.tar.gz -- the file data.tar.gz has all the stuff which you need for executing the software
  5. usr/bin/jedit opens the editor
  6. done :-)

You can move the files to some point in your home directory and execute them from there.

qbi
  • 19,125
  • 13
    Note that pre- and post-install scripts don't get run; also you'll need to resolve any dependencies or paths yourself.

    But on a default install this is sufficient for a lot of desktop applications.

    – jbowtie Jul 29 '10 at 12:01
  • 1
    you can also download the package without searching for it, just do apt-get download (see other answer) – lib Jul 23 '15 at 14:59
  • i believe your link is broke. – Winnemucca Apr 13 '17 at 22:33
16

I wrote a program called JuNest which basically allows to have a really tiny Linux distribution (containing just the package manager) inside your $HOME/.junest directory.

It allows you to have your custom system inside the home directory accessible via proot and, therefore, you can install any packages without root privileges. It will run properly under all the major Linux distributions, the only limitation is that JuNest can run on Linux kernel with minimum recommended version 2.6.32.

For instance, after installing JuNest, to install jedit:

$>junest -f
(junest)$> pacman -S jedit
(junest)> jedit
knia
  • 103
  • 3
  • This will run just fine on Ubuntu right? – Seth Nov 02 '14 at 21:27
  • Yes, if the linux kernel version of ubuntu is greater or equal to 2.6.32 it will work. – user967489 Nov 04 '14 at 00:47
  • 3
    At first I thought you were talking about this. The second capitalized j makes the difference. – kon psych May 06 '15 at 21:42
  • 1
    The question was if we could install Ubuntu package. With junest, we will only be able install ArchLinux package and NOT an Ubuntu package. For e.g. if the same package is not available for ArchLinux, then this won't help. That said, thanks for Junest. – kiranpradeep Feb 20 '16 at 10:24
  • juju is junest now, and it works because of proot – Rainb Jun 26 '20 at 10:04
1

I find the accepted answer lacks a concrete example. This is a full working example:

# - opam (snap, no sudo)
# ref: https://askubuntu.com/questions/339/how-can-i-install-a-package-without-root-access
apt-get download opam
#apt-get download opam_1.2.2-4_amd64
#ls | less
mkdir -p ~/.local
dpkg -x opam_1.2.2-4_amd64.deb ~/.local/bin
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc.user

tr ':' '\n' <<< "$PATH"

opam --version

in particular you need to be careful because apt-get download might now give you the .deb fine with the exact name you expect.

Note this one usually also works:

# - install the bin then put it in path and restart your bash
mkdir ~/.rbenv
cd ~/.rbenv
git clone https://github.com/rbenv/rbenv.git .

export PATH="$HOME/.rbenv/bin:$PATH" echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc

exec $SHELL

#bash

rbenv -v

Charlie Parker
  • 425
  • 1
  • 5
  • 11
  • btw, don't install opam that way. see: https://stackoverflow.com/questions/74708063/how-does-one-install-opam-without-sudo-priveledges-on-linux-ubuntu?noredirect=1&lq=1 – Charlie Parker Dec 06 '22 at 20:52