122

Assume I have ssh access to some Ubuntu server as user and I need some not system tools to be installed for convenience (mc, rtorrent, mcedit). I do not want to bother admins for these small programs.

Is there a way to install them (make them run) without using something like sudo apt-get install?

Braiam
  • 35,991
yura
  • 1,367
  • 2
  • 10
  • 8

8 Answers8

77

You need to compile these from source. It should just be a matter of

apt-get source PACKAGE
./configure --prefix=$HOME/myapps
make
make install

The binary would then be located in ~/myapps/bin. So, add export PATH="$HOME/myapps/bin:$PATH" to your .bashrc file and reload the .bashrc file with source ~/.bashrc. Of course, this assumes that gcc is installed on the system.

thrig
  • 34,938
eof
  • 899
42
  1. Compile and install into ~/bin (and edit your .bashrc to set the PATH to include it). libraries can similarly be compiled and installed into ~/lib (set LD_LIBRARY_PATH to point to it), and development headers can be installed into e.g. ~/includes.

  2. Depending on the specific details of the programs you want to install and the libraries they depend upon, you can download the .deb files and use 'dpkg-deb -x' to extract them underneath your home directory. You will then have a lot of "fun" setting the PATH, LD_LIBRARY_PATH, and other variables. The more complex the program or app you're installing the more fun you'll be up for :)

    You will, of course, not be able to install setuid binaries this way - they'll install but (since you don't have permission to chown them to root or set the setuid bit on them) they'll just be normal binaries owned by you.

    Similarly, daemons and system services that expect to be running as a certain UID or have the ability to change uid, or expect files to be in /etc rather ~/etc and so on aren't likely to work well, if at all.

  3. Most sysadmins would consider mc and mcedit to be "mostly harmless", innocuous programs.

    Very few, however, would consider installing a torrent client to be harmless, especially if they have to pay for bandwidth or end up being legally liable. Most sysadmins would probably not be entirely happy for end-users to be installing such software without permission. They may say "sure, go ahead, knock yourself out" or they may not...but you should ask about anything that may cause problems for the owners/administrators of the machine.

cas
  • 78,579
  • 2
    I've heard that setting LD_LIBRARY_PATH is an evil hack. Does this apply here as well, or have I misunderstood? – Will Vousden Feb 10 '16 at 13:59
  • 3
    All the issues with setting LD_LIBRARY_PATH apply. yes, it is, or can be, an evil hack. sometimes evil hacks are necessary to achieve particular goals...the crucial thing when breaking "rules" is to know them well enough to know what they're designed to save you from, and exactly why you need to break them in this particular case, and what the risks are or might be. – cas Feb 10 '16 at 23:42
  • I just had to install an independent program (zoom), so first I tried the 2nd option (dpkg-deb -x to a local dir). Worked like a charm. I did not have to do any LD_LIBRARY_PATH hacks. Even if I have to, I would do it in the same command line so as not to affect the global settings (for example $ LD_LIBRARY_PATH=/home/usr1/zoom/opt/zoom:/home/usr1/zoom/opt/zoom/zoom ZoomLauncher). – HelloWorld101 Sep 14 '18 at 13:29
  • you only need to set LD_LIBRARY_PATH if one or more the packages you want to install provides any shared libraries. If it's just executables & data & docs & config files etc, then it can use the system libraries. – cas Sep 14 '18 at 23:40
  • can you provide a concrete example? – Charlie Parker Dec 06 '22 at 01:58
  • why doesn't apt-get install bubblewrap -t ~/.my_bins work? – Charlie Parker Dec 06 '22 at 01:59
  • @CharlieParker apt-get's -t option has absolutely nothing to do with what directory a package is installed in. -t (--target-release or --default-release) tells apt-get what the default release to install from is (e.g. stable, testing, unstable, experimental), same as the APT::Default-Release config option. You seem to be getting confused with the -t (--target-directory) option of some GNU programs (e.g. cp, mv, & ln), which is completely unrelated to apt's -t option. – cas Dec 06 '22 at 12:47
  • As for your request for a "concrete example", I have no interest in revisiting a 10 year old answer to a 10 year old question, especially when the question was generic - accordingly my answer was about two generic techniques for installing software without root privs. If you have a new question that's different enough to not be a dupe, then post a new question. – cas Dec 06 '22 at 12:53
10

You can use JuNest, which creates a small Linux container in user's directory, where you can install any packages.

niutech
  • 398
  • Junest basically makes a small archlinux system where you have fakeroot privileges, it's perfect – Rainb Jun 26 '20 at 10:05
4

I faced the same issue, here is how I quickly fixed it, assuming you have a linux server of the same OS and architecture.

  1. Install the software on the system you control

  2. Find the executable example which python and copy it to ~/

  3. Copy the libraries with:

    ldd "$(which python)"  | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ~/
    

Transfer the executable and the libraries to the other system where you only have local privileges, then run the following:

mkdir ~/lib
export PATH="$PATH:~/lib"
export LD_LIBRARY_PATH=~/lib:/lib:/usr/lib

This will create a folder ~/lib to store the libraries, add it to your path, and tell LD to look at the libraries there, so just add your executables and the libraries there, now you can run it as you'd elsewhere

This may be very hacky, but it's very portable, quick, and I haven't yet found something I can't run that way, of course, the software cannot try to do things that need root access, like binding to a lower port than 1024, etc.

muru
  • 72,889
Freedo
  • 1,255
2

There's actually a tool for that that i just made today
https://github.com/z3r0n3t/pkget All you need is access to bash no root are anything special You can use whet to download it as a zip file or use git clone

echo
  • 21
0

This is much better, found on askubuntu: https://askubuntu.com/a/391992/116108

Software Updates uses aptdaemon to do all the work. You can do that > from the command line using aptdcon:

Check for updates:

aptdcon --refresh

Install updates:

aptdcon --safe-upgrade
0

Here's how to install into local user bin directory, without using sudo:

install ./your-app ~/.local/bin/

Alternatively, just copying the app to that directory should also work.

Noam Manos
  • 1,031
-1

Concrete examples that worked for me:

#!/usr/bin/env bash

- 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

- 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