homebrew

How do you migrate a Homebrew installation to a new location?


I have a Homebrew installation in $HOME/brew, and historically it has worked well. Unfortunately, over time Homebrew has become less and less tolerant of installations outside of /usr/local. Various formulae make hard assumptions about the installation prefix, and do not work properly (i.e., were not tested) with a non-standard prefix. The brew doctor command even goes so far as to warn about this now:

Warning: Your Homebrew is not installed to /usr/local
You can install Homebrew anywhere you want, but some brews may only build
correctly if you install in /usr/local. Sorry!

As such, I would now like to migrate my Homebrew installation over to /usr/local. However, I am loath to simply mv all the files, as I suspect this will cause problems. I could not find any instructions on the Homebrew site or here on migrating an existing installation to a new prefix. Of course, I could uninstall Homebrew and then reinstall it, but I would prefer not to rebuild all my kegs.

As such: How might I write a script to perform such a migration?

Or is this impossible due to hardcoded absolute paths in linked binaries?


Solution

  • The modern way to do this is with homebrew-bundle.

    brew tap Homebrew/bundle
    brew bundle dump # Creates 'Brewfile' in the current directory
    # later ...
    brew bundle # Installs packages listed in 'Brewfile'