How to Install Packages in Linux (Centos) Without Root User with Automatic Dependency Handling

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

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.

install rpm packages and dealing with dependencies

Yes, you can try to use a package manager, which will manage the dependencies for you. The problem will be to find the RPM file in a repository, add that repository to your package manager, update the index information of your pack. manager. Looking at that RPM, I think you will be using yum.

How to make rpm auto install dependencies

Create a (local) repository and use yum to have it resolve the dependencies for you.

The CentOS wiki has a nice page providing a how-to on this. CentOS wiki HowTos/CreateLocalRepos.


Summarized and further minimized (not ideal, but quickest):

  1. Create a directory for you local repository, e.g. /home/user/repo.
  2. Move the RPMs into that directory.
  3. Fix some ownership and filesystem permissions:

    # chown -R root.root /home/user/repo
  4. Install the createrepo package if not installed yet, and run

    # createrepo /home/user/repo
    # chmod -R o-w+r /home/user/repo
  5. Create a repository configuration file, e.g. /etc/yum.repos.d/myrepo.repo containing

    [local]
    name=My Awesome Repo
    baseurl=file:///home/user/repo
    enabled=1
    gpgcheck=0
  6. Install your package using

    # yum install packagename

CentOS rpm package depends on lib soname which it builds using cmake

When RPM builds packages, it automatically scans all the installed files and creates a list of things (eg, executables, libraries) that are provided by the package, as well as dependencies needed (eg, shared libraries, system features).

The idea is that tools (like rpmbuild) can identify at least some of the program dependencies automatically, so they should automatically add them as the package dependencies.

Libraries are a bit funny, because they are treated as both dependencies and a feature provided by the RPM package.

AFAIK, a so-version enables this feature specifically because that signals to the RPM's dependency finder that this is a well-formed library that others might want to consume.

There's a couple of things you can do:

  • Assuming the package actually includes a libABC.so.1 and libABC.so.1()(64bit) is listed in the provides of the package, just let it be? It makes it easier for other programs to eventually depend on this library.

  • If you don't like this behaviour at all, you can just disable this entire feature. Use AutoReq: no.

How do I update individual/multiple packages in local redhat/centos repo without syncing whole repo

yumdownloader --destdir DIR --resolve package1 package2 


Related Topics



Leave a reply



Submit