Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change Homebrew's prefix?

Tags:

homebrew

Somehow, my Homebrew install has a prefix of ~/.rvm. I'd like to set it to the default of /usr/local.

Is this possible?

like image 986
Sam Selikoff Avatar asked Jun 24 '14 02:06

Sam Selikoff


People also ask

What does brew -- prefix mean?

The wiki says that brew --prefix <formula> prints where the formula is installed, meaning that it's behaviour of using the latest version rather than the installed version is incorrect, and it will cause problems with all automated scripts (such as the recommended bashrc addition above) that use it.

How long does Homebrew update take?

From 20 minutes to an hour. The devs are aware.

What is Homebrew cask?

Homebrew-Cask extends Homebrew and allows you to install large binary files via a command-line tool. You can for example install applications like Google Chrome, Dropbox, VLC and Spectacle.


2 Answers

For the benefit of anyone who's had to do a manual install of Homebrew.

Taking a look at the actual brew file is the line:

HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}"

It turns out it gets the prefix automatically from the parent directory of the install location, unless;

# Try to find a /usr/local HOMEBREW_PREFIX where possible (for bottles)
if [[ -L "/usr/local/bin/brew" ]]
then
  USR_LOCAL_BREW_FILE_DIRECTORY="$(symlink_target_directory "/usr/local/bin/brew" "/usr/local/bin")"
  USR_LOCAL_HOMEBREW_REPOSITORY="${USR_LOCAL_BREW_FILE_DIRECTORY%/*}"
  if [[ "$HOMEBREW_REPOSITORY" = "$USR_LOCAL_HOMEBREW_REPOSITORY" ]]
  then
    HOMEBREW_PREFIX="/usr/local"
  fi
fi

This'll grab the prefix value from the parent directory of any symlink to the brew executable so long as the Homebrew install directory is down stream from that directory (like /usr/local/Homebrew)

If you've manually installed directly into the usr/local/ directory, you'll still want to go and put a symlink in the usr/local/bin folder to your Homebrew/bin/brew executable to get the correct prefix path. That'll also avoid you needing to add the Homebrew/bin folder directly to your $PATH as well.

like image 105
Hobsie Avatar answered Oct 06 '22 16:10

Hobsie


Some of Homebrew's bottles (binary packages) can only be used with the default prefix (/usr/local) like e.g. rust. But if you still want to install it with a different prefix, then use:

arch -arm64 brew install rust

If you want to know, which prefix you already using:

brew config | grep HOMEBREW_PREFIX

In my case it is HOMEBREW_PREFIX: /opt/homebrew

like image 31
Lonely Avatar answered Oct 06 '22 16:10

Lonely