DEV Community


Posted on


Package Your Tools

RPMs in $HOME! Amaze friends! Confound enemies! Install the binary versions YOU want! All this and more with native tools and no root!

Enough hype yet? This is a simple and maybe-ugly way to get RPMs that install into your $HOME directory to simplify management of hosted shells and tight VMs/containers where management infrastructure would be too much overhead. You won't need root to install these RPMs, but will need a RHEL/Centos host to build them on; Circle CI's free tier is great for this.

I feel like I misled DeChamp in a comment thread talking about the socket options for fuser, so I'll use this article as a roundabout apology and employ fuser as an example.

Building RPMs for $HOME

  1. Install rpm-build on the builder VM to do the heavy lifting:
    sudo yum install rpm-build -y;

  2. Install the FPM gem on the builder VM to handle the RPM building :
    git clone;
    cd fpm && gem install --no-ri --no-rdoc fpm;

  3. Create an install tree for your script on the builder VM. This file system tree will be reflected on the target host that the RPM is installed-on:
    mkdir -p $HOME/var/tmp/bin

  4. Add the scripts, libraries, configs and whatever else to $HOME/var/tmp/bin:
    cp $HOME/psmisc/src/fuser $HOME/var/tmp/bin

  5. Add a helper script called var/tmp/bin/ to relocate installed files:
    [[ -d $HOME/bin ]] || mkdir $HOME/bin;
    [[ -d $HOME/bin ]] && mv /var/tmp/bin/fuser $HOME/bin;

Please give these scripts distinctive names, RPM won't want to install over an existing script.

  1. Build an RPM from the contents of $HOME/var: cd && fpm -s dir -t rpm -n fuser --after-install 'var/tmp/bin/' var

Installing RPMs for $HOME

Now don't let your enthusiasm fizzle when rpm -i comes back with "error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)"! If root doesn't want to share its tree house we'll build our own!

mkdir $HOME/rpmdb
find /var/lib/rpm -type f |xargs file| awk '/Berkeley/ {print $1}' | tr -d ':' | while read src 
    db_dump $src | db_load $HOME/rpmdb/$(basename $src); 
rpm --dbpath $HOME/rpmdb --rebuilddb;

Now we can install our RPMs like so:

rpm --dbpath $HOME/rpmdb -i fuser-1.0-1.x86_64.rpm

Top comments (0)

Every Week

We have a Welcome Thread where we invite members to tell us a bit about themselves. Join the conversation with us!