by Joseph Long

My job these days involves a fair bit of wrangling with relatively ancient CentOS 6 (i.e. RedHat Enterprise Linux 6) systems. Cutting edge research, eight year old operating systems. Go figure.

In fairness to the University of Arizona's high performance computing staff, they do install regular CentOS updates. The deal with "enterprise" Linux, though, is that those updates don't really... update anything.

For example:

$ /usr/bin/git --version
git version 1.7.1

As of this writing, that version of git is over 9 years old. And, since these are shared HPC systems, we can't get updated packages installed without potentially disrupting other users. How can we work around this, bearing in mind we have no root access?

Linuxbrew

If you develop software on macOS, you've probably heard of Homebrew. Well, it turns out an enterprising graduate student (now graduated) has created Linuxbrew to leverage the build-from-source formulae of Homebrew on Linux to solve just this problem.

Unfortunately, CentOS 6 and its associated git are now so old that Homebrew can't even install itself. We have to help it along.

Build yourself a git

We can't install anything system-wide, but we can create a .local prefix in our home directory with its own bin, lib, etc. directories.

mkdir -p ~/.local/{lib,include,share,bin}

Next, follow this incantation to install git version 2.9.5. (Or, modify appropriately for a more recent version from here)

curl -OL https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
tar xvfz git-2.9.5.tar.gz
cd git-2.9.5
./configure --prefix=$HOME/.local
make
make install
export PATH="$HOME/.local/bin:$PATH"
git --version

If all went well, that last command should spit out

$ git --version
git version 2.9.5

You'll want to add the line export PATH="$HOME/.local/bin:$PATH" at the end of your shell rc file (typically ~/.bash_profile, ~/.bashrc, or ~/.profile) so the new git you compiled is made available in every session. (Some recent Linux distributions include ~/.local/bin in $PATH by default, but the CentOS 6.10 machine I'm using didn't.)

Manually install Linuxbrew to your preferred location

Switch to the directory where you want Linuxbrew installed and execute these commands

git clone https://github.com/Homebrew/brew .linuxbrew/Homebrew
mkdir .linuxbrew/bin
ln -s ../Homebrew/bin/brew .linuxbrew/bin
eval $(.linuxbrew/bin/brew shellenv)

These commands are modified from the Alternative Installation section of the Homebrew on Linux docs in order to be location-agnostic. I installed to a special /extra/$USER location that has more space than my home directory on the system in question, but $HOME is a perfectly valid choice too.

Now, do which brew and you should see something like this:

$ which brew
/extra/josephlong/.linuxbrew/bin/brew

Apply magic

Use the full path to brew from the last step to determine the correct line to add to your shell rc file. In my case, it's

eval $(/extra/josephlong/.linuxbrew/bin/brew shellenv)

Now, when I open a new session, I will have the brew command available. That's not the only trick though. We also need to add this line:

export HOMEBREW_NO_ENV_FILTERING=1

This allows Homebrew to see ~/.local/bin/ as a valid place to find git. Otherwise, it will stubbornly insist on using the ancient CentOS version, which will cause things to fail in interesting ways.

Brew!

Source your updated shell rc file, or open a new session. Now, you should be able to do brew update without errors, and brew install almost anything!

Thanks to Shaun Jackman (a.k.a. @sjackman) for his assistance figuring this out, and for creating Linuxbrew!

posted

← return home
Background image of the Carina nebula by NASA, ESA, N. Smith (University of California, Berkeley), and The Hubble Heritage Team (STScI/AURA)