Install to /opt instead of /home/linuxbrew

Does anybody know the reason the Brew install.sh script wants to install the linuxbrew stack to /home/linuxbrew?

I think /opt or maybe /var would make a lot more sense. Both of these directories are intended for system extras, while /home is, as its name implies, intended to be home to user data.

I’ve installed it to /opt on my RHEL 8 machine and intend to do some testing with it there, but I’d love to hear the rationale for putting it into /home, in case I’m overlooking something.

1 Like

That’s a good question. Linuxbrew is installed to /home to avoid requiring sudo, which is helpful for systems in which one can’t get root access, which is common for scientific computing clusters.

See also https://www.reddit.com/r/linux/comments/625koc/is_linuxbrew_needed_for_linux/dfk79p9/

That makes sense for /home/$USER/.linuxbrew but I’m referring to the fact that the default location is actually /home/linuxbrew/.linuxbrew

The install script prompts the user for sudo password, then creates a new dir in /home called linuxbrew, where it installs the whole stack. To access it, the user’s asked to add /home/linuxbrew/.linuxbrew/bin to their PATH. It works, it’s just severely non-standard.

Here’s the relevant code (with a few snips made for brevity) from the install script:

if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
  HOMEBREW_PREFIX="/usr/local"
  HOMEBREW_REPOSITORY="/usr/local/Homebrew"
  HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"
   [snip]
else
  HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"
  HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
  [snip]
fi

If HOMEBREW_ON_LINUX is not set, then Homebrew goes to /usr/local but if it is set, then /home/linuxbrew/.linuxbrew is created and used as the base directory.

I assume the authors did this for fear of clobbering something in /usr/local, which is relatively commonly used in Linux (at least moreso than in macOS by default), but I question whether /home is the appropriate place for it. This is one reason /opt exists.

It’s so a system administrator could create a linuxbrew role account. There are other, more technically pure ways to accomplish the same goal but this is the easiest way to get a non-root setup and still deliver binary packages, some of which may be non-relocatable.

That makes some sense.

I’ll see how things go with keeping it in /opt.

Thanks @jonchang

There’s a detailed explanation here:

See also the FAQ entry “Why install in /home/linuxbrew/.linuxbrew?”, which addresses precisely this question.

@sjackman on the topic of relocatable bottles, I recently came across the reproducible-builds.org project, and was wondering if progress in the build path independence criterion could help bottles become relocatable.

And more directly related to Linuxbrew: how can one identify non-relocatable bottles and help in making them relocatable? Is there some documentation for this type of work?

on the topic of relocatable bottles, I recently came across the reproducible-builds.orgproject, and was wondering if progress in the build path independence criterion could help bottles become relocatable.

That’s definitely relevant!

And more directly related to Linuxbrew: how can one identify non-relocatable bottles and help in making them relocatable? Is there some documentation for this type of work?

I would love more bottles to be relocatable, and I believe there is low-hanging fruit and improvements to be made on this front. A relocatable bottle contains the string cellar :any in the formula, and a non-relocatable bottle does not. Pick a formula that you care about that is not currently relocatable. Install the bottle, then run brew bottle -v FORMULA. It will tell you why the bottle is not relocatable. If you’re able to fix it and make it relocatable, please open a PR! If you want to work actively on it and discuss it more, open a GitHub issue, tag me, and I’d be happy to chat.

1 Like

A relocatable bottle contains the string cellar :any in the formula, and a non-relocatable bottle does not.

That seemed to be the case in my brief investigation, but I did find cases where this wasn’t done, e.g. in this commit. Was that an overlook, or is there more nuance to how the cellar :any bit can be used? I’m particularly confused about the following passage from the docs:

This can be omitted if a bottle is compiled (as all default Homebrew ones are) for the default HOMEBREW_CELLAR of /usr/local/Cellar.

Can you explain what this means, especially for Linuxbrew formulas?

Install the bottle, then run brew bottle -v FORMULA . It will tell you why the bottle is not relocatable.

Wow, that’s very helpful! Thanks for the tip.

If you want to work actively on it and discuss it more, open a GitHub issue, tag me, and I’d be happy to chat.

Most likely I’ll work on it occasionally rather than in a continuous effort, but I’ll make sure to ping you when I do.

The bottle block is updated automatically by the CI system. See commit https://github.com/Homebrew/linuxbrew-core/commit/fdae163144124be0f10666dd69cc689879e8d7c4

On Linux, omitting the cellar line is equivalent to cellar /home/linuxbrew/.linuxbrew/Cellar, meaning the bottle is not relocatable and can only be installed in the default cellar.

Looking forward to your PRs! Please @ me in your PRs.