How to install packages in Linux (CentOS) without root user with automatic dependency handling?
Asked Answered
W

5

76

Is it possible to use RPM or YUM or any other package manager in Linux, specifically CentOS, to install a package either already downloaded or from repo to a custom location without admin/root access?

I tried building from sources, using cmake, configure, make, make install etc, but, it ended up having so many dependencies one after other.

Or are there any better alternatives?

Williamsen answered 15/4, 2016 at 15:23 Comment(0)
H
93

It is possible to use yum and rpm to install any package in the repository of the distribution. Here is the recipe:

Find the package name

Use yum search.

Download

Download the package and all of its dependencies using yumdownloader (which is available on CentOS by default). You'll need to pass it --resolve to get dependency resolution. yumdownloader downloads to the current directory unless you specify a --destdir.

mkdir -p ~/rpm
yumdownloader --destdir ~/rpm --resolve vim-common

Choose a prefix location

It might be ~, ~/centos, or ~/y. If your home is slow because it is on a network file system, you can put it in /var/tmp/....

mkdir ~/centos

Extract all .rpm packages

Extract all .rpm packages to your chosen prefix location.

cd ~/centos && rpm2cpio ~/rpm/x.rpm | cpio -id
  • rpm2cpio outputs the .rpm file as a .cpio archive on stdout.
  • cpio reads it from from stdin
  • -i means extract (to the current directory)
  • -d means create missing directory

You can optionally use -v: verbose

Configure the environment

You will need to configure the environment variable PATH and LD_LIBRARY_PATH for the installed packages to work correctly. Here is the corresponding sample from my ~/.bashrc:

export PATH="$HOME/centos/usr/sbin:$HOME/centos/usr/bin:$HOME/centos/bin:$PATH"

export MANPATH="$HOME/centos/usr/share/man:$MANPATH"

L='/lib:/lib64:/usr/lib:/usr/lib64'
export LD_LIBRARY_PATH="$HOME/centos/usr/lib:$HOME/centos/usr/lib64:$L"

Edited note (thanks to @AmitNaidu for pointing out my mistake):

According to bash documentation about startup files, when connecting to a server via ssh, only .bashrc is sourced:

Invoked by remote shell daemon

Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable.


Now if you want to install a lot of packages that way, you might want to automate the process. If so, have a look at this repository.


Extra note: if you are trying to install any of gcc, zlib, make, cmake, git, fish, zsh or tmux , you should really consider using conda, see my other answer.

Haggard answered 29/9, 2018 at 11:2 Comment(8)
So, let's put things forward, how to download things like this? It should add new repo... e.g.- copr.fedorainfracloud.org/coprs/ivoarch/Tilix or group install like this? e.g.- hiroom2.com/2017/07/26/centos-7-xfce-enRoute
I have yum on my system, but no yumdownloader. I found this alternate way to yum download only in Redhat docs: yum install --downloadonly --downloaddir=./rpm but when I ran it, it still said root priv was needed.Fetus
From your bash startup files link: Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable.Bonefish
Thanks! I am sure I'll figure out a way to make this work but after installing i was greeted with "error while loading shared libraries: libreadline.so.6: wrong ELF class: ELFCLASS64"Hardpan
In case you're like me thinking you then run yum install, you don't. The final executables are in ~/centosSivia
can you add a note to mind to install the doc in the environement: export MANPATH=$MANPATH:$HOME/centos/usr/share/man. By the way: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/centos/usr/lib:$HOME/centos/usr/lib64" is better with reusing the environement. Moreover put the $PATH and LD_LIBRARY_PATH at begin or end but the sameNeed
I don't have yumdownloader on my host. Any other way around this?Recurved
If you need to install a group repository package (e.g. if you would normally do yum groupinstall 'Development Tools'), you can download the group using, e.g. yumdownloader --resolve @'Development Tools' (I think).Oliverolivera
H
26

TL;DR Use Miniconda, conda-forge is amazing.

curl "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" | sh

Or, alternatively:

curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh > Miniconda.sh
bash Miniconda.sh -b -p ~/conda
# -b is used to specify that this is done "in batch", so skip the EULA prompt
# -p lets you specify where you want conda installed

Commonly wanted packages:

  • gcc conda install gcc
  • zlib conda install zlib
  • make conda install make
  • cmake conda install cmake
  • git conda install git
  • fish conda install -c conda-forge fish
  • zsh conda install -c ActivisionGameScience zsh
  • tmux conda install -c conda-forge tmux
    • This tmux has a bug with the name of the ncurse library it uses. You can work around it by going to your da/lib folder and symlinking ln -sT libtinfow.so.6.1 libtinfo.so.6

For the rest, you can try https://anaconda.org/search?q=.


I've tried for a long time to get a package manager to work well on CentOS/RedHat but without success. The best I could do was to install a Gentoo Prefix at the correct location on another CentOS with root access, then scp a .tar.xz of the whole installation to the target server (only way to get a proper gcc for Gentoo Prefix). I could emerge (build & install) packages on the target server but kept hitting problems with locals and permissions.


I recently achieved a user installation of some interesting packages using conda. Here is how to install it from the command line:

curl "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" | sh

If like me, your home folder is hosted on a remote drive (a network file system), you might not want to install it in your home folder, so you might want to use something like mkdir /var/tmp/lo then specify an installation folder like /var/tmp/lo/da during the installation.

You'll then be able to install quite a lot of packages, though maybe not all those you wanted. Most of the time, if it is not in the default channel, it will be in conda-forge. You can check for existing packages at https://anaconda.org/search?q=


Other package managers I've tried to use after conda:

Linuxbrew

I thought that with that it would be easy to install homebrew (linuxbrew) but their sources are messy and use hard-coded absolute path to ruby interpreter, which fails because it isn't the last version and so on and so on and I gave up.

Nix

Nix still requires you to use the /nix folder. They hard-coded it too and it's hard to sed it correctly from every download it has to do during the installation (let alone updates).

Gentoo Prefix

I expect Gentoo Prefix to be easier to install directly now that we gcc can be used on the target server. -- Ok, I tried but met permissions bugs during installation (2018-09-28):

portage.exception.OperationNotPermitted: chown(b'~/gentoo/tmp/var/tmp/portage/sys-apps/gentoo-functions-0.12/image/var', 2000, 2000)

PkgSrc

I'm going to try pkgsrc now. -- Use (older) version 64-bit EL 6.x if on CentOS 6 or if encountering (G)LibC version issues with the 7.x one. -- No luck, pkgsrc hard codes /usr/pkg/sbin and /usr/pkg/bin. So it can't be used as user, unless maybe setting up a fakechroot environment. But I've never done that and I expect usability issues.


Please comment/answer if you succeed in installing any other package manager.

Haggard answered 28/9, 2018 at 18:41 Comment(1)
Interesting, although upon running that curl command I get a runaway >>> Please answer 'yes' or 'no':' that I cannot answer after scrolling through the EULAGettogether
R
3

Download the packages, and indicate to include dependencies with the --resolve flag.

yumdownloader --resolve openslide-tools

Iterate over all downloaded rpm files.

for i in *.rpm; do rpm2cpio $i | cpio -idv; done

the output will be stored in your present working directory $PWD/usr/*

Realism answered 2/1, 2021 at 13:3 Comment(0)
B
2

This answer by goldilocks sounds like what you are looking for.

https://unix.stackexchange.com/a/61295

It's still not a pretty process, but seems easier than building from source.

Otherwise you might want to look into non-root package managers as an alternative to yum.

Bullshit answered 15/4, 2016 at 15:30 Comment(3)
That rpm2cpio solution seems to extract files fine, but the extracted libraries (*.so) are broken.Williamsen
You're probably going to need to setup your linker and your pkgconfig in order for the OS to be able to find the libraries when they run.Bullshit
And here I was all these years thinking it was possible as non root and I was just too lazy to learn.Sivia
D
0

Yes it is. If the software is packaged in repos. And admin installed PackageKit-command-not-found package.

See: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound

Didymium answered 18/4, 2016 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.