75

I am a non-admin user on a large computer system. I need some up to date packages that are not installed on the system. I want to use yum to install them. As a user without sudo, admin, or root access, can I use package management to install packages in my home directory? I can always use make from the sources, but being able to use yum will make life easier.

  • 1
    not unless the yum binary is suid root (chances of that are slim). – h3rrmiller Jan 14 '13 at 17:41
  • 2
    @h3rrmiller, but is there any package manager that can install programs in $HOME, and hence not require sudo access? I know MacPorts on OSX can do so. What are such options for Linux? – highBandWidth Jan 14 '13 at 17:44

3 Answers3

53

Rather than use yum, find the rpms you want and download them. You still can't install them directly without being root, but RPM packages are actually fancy .cpio files, and you can unpack their contents. The easiest way to do this is probably via the mc ("midnight commander") file browser (one of the greatest pieces of software ever), which allows you to browse the contents of an .rpm and copy files straight out of it.

Sans that, you can use rpm2cpio to convert it to .cpio, then cpio to extract the files inside and put them in the right places. Both of these will already be installed on a redhat or fedora system. Here's an example installing "xsnow" (you probably want to do this in an empty directory):

»rpm2cpio xsnow-1.42-17.fc17.x86_64.rpm > xsnow.cpio

Notice I found an .rpm appropriate to my system, fc17 x86_64. This is important because these are precompiled binaries that are linked against other components. Now extract the .cpio:

»cpio -idv < xsnow.cpio 
./usr/bin/xsnow
./usr/share/doc/xsnow-1.42
./usr/share/doc/xsnow-1.42/README
./usr/share/man/man6/xsnow.6.gz
212 blocks
Press any key to continue...

If I browse through this directory tree, everything I need is there, except some of the meta-information that might help me resolve dependencies. This can be found using rpm -q -p [package] --[query]:

»rpm -q -p xsnow-1.42-17.fc17.x86_64.rpm --requires
warning: xsnow-1.42-17.fc17.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID d2382b83: NOKEY
libX11.so.6()(64bit)  
libXext.so.6()(64bit)  
libXpm.so.4()(64bit)  
libc.so.6()(64bit)  
libc.so.6(GLIBC_2.2.5)(64bit)  
libc.so.6(GLIBC_2.3.4)(64bit)  
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)  
rpmlib(PayloadIsXz) <= 5.2-1

Pretty sure I already have all this stuff. So now all I have to do is put the xsnow executable in my $PATH, which already includes a bin in my home directory:

»cp ./usr/bin/xsnow ~/bin

Viola! Now I can type xsnow and watch nothing, since as it turns out xsnow does not play well with KDE :( but hopefully the jist of the process is clear. I did not have to do anything outside my home directory.

If you need to install libraries you will need to create a directory in home for them too and add to ~/.bashrc:

export LD_LIBRARY_PATH=/home/you/lib
GAD3R
  • 66,769
goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • @siamii Well, do you have a better answer? – Marcin Aug 10 '13 at 20:59
  • 5
    Ok, so how about someone make a tool to make cpio files, and then copy everything to a non-root folder, like ./usr/bin to $PREFIX/usr/bin etc., and also recursively check and install dependencies. – highBandWidth Sep 10 '14 at 19:29
  • 2
    Two and a half years later, thanks for the helpful answer. You can do this in one line with:mkdir xsnow ; cd xsnow ; wget -O - ftp://195.220.108.108/linux/rpmfusion/nonfree/fedora/releases/17/Everything/x86_64/os/xsnow-1.42-17.fc17.x86_64.rpm | rpm2cpio - | cpio -idv – Larry Engholm May 26 '15 at 23:49
  • 3
    I have been using this for over 2 years on my office computer and it works like a charm every single time. I wanna express my sincere gratitude to you. I wish my university's IT is as competent. –  Aug 08 '16 at 18:50
  • Every once and a while while doing this I run into a Cannot symlink to '...': Permission denied or cpio: ....: Cannot open: Permission denied, is there a way to fix this? Note that I create these files without sudo, but then for some reason I need to use sudo to uninstall them – Phylliida Sep 20 '16 at 16:37
  • @Phylliida Looking at --no-preserve-owner in man cpio it seems by default if a non-root user does the unpacking, that user owns everything. It could be because of absolute paths used in links inside the archive. – goldilocks Sep 20 '16 at 16:52
  • Yea that does seem to be the case. Is there a way to fix this? – Phylliida Sep 20 '16 at 19:27
  • Not without modifying the package itself I guess. I presume it unpacks but either doesn't create or leaves those dangling; you could have a look at what they are from the errors to see if it matters. Shared libraries commonly have links referring to themselves that should be relative (e.g., libfoobar.so.1 -> libfoobar.so) but may sometimes have been done naively if it is a third party rpm. That's easy to fix -- just create relative ones. – goldilocks Sep 20 '16 at 19:36
  • 1
    This should be the accepted answer. – sancho.s ReinstateMonicaCellio Oct 11 '18 at 03:34
8

Most binaries are compiled to be installed into certain locations under /.

There are non-root package managers like Gentoo Prefix and Rootless GoboLinux and maybe 0install.

As you said compiling yourself would alleviate that issue, or using a chroot. However, your biggest hurdle with chrooting will be the prerequisites and linking to kernel shared objects.

h3rrmiller
  • 13,235
1

I gave up on using yum after reading other answers here, and found that these instructions worked for me (slightly modified from those described in the link):

Install miniconda in your user folder

$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ ./Miniconda3-latest-Linux-x86_64.sh

Install packages locally

$ conda install <pkg-name>

Done!

In the prompts I answered "yes" or took the default values, and now the conda package manager as well as anything I install with it is put under ~/miniconda3/. So, in my case, after I ran conda install R glpk, I see the following locations of binary files:

$ which conda R glpsol
~/miniconda3/bin/conda
~/miniconda3/bin/R
~/miniconda3/bin/glpsol

I still would prefer to use yum, but this solution keeps me moving forward.