How do you migrate a Homebrew installation to a new location? -
i have homebrew installation in $home/brew
, , historically has worked well. unfortunately, on time homebrew has become less , less tolerant of installations outside of /usr/local
. various formulae make hard assumptions installation prefix, , not work (i.e., not tested) non-standard prefix. brew doctor
command goes far warn now:
warning: homebrew not installed /usr/local can install homebrew anywhere want, brews may build correctly if install in /usr/local. sorry!
as such, migrate homebrew installation on /usr/local
. however, loath mv
files, suspect cause problems. not find instructions on homebrew site or here on migrating existing installation new prefix. of course, uninstall homebrew , reinstall it, prefer not rebuild kegs.
is there existing script or documented practice performing such migration?
or impossible due hardcoded absolute paths in linked binaries?
i wrote script achieve goal migrate homebrew packages new system, applies case (named backup-homebrew.sh
):
#!/bin/bash echo '#!/bin/bash' echo '' echo 'failed_items=""' echo 'function install_package() {' echo 'echo executing: brew install $1 $2' echo 'brew install $1 $2' echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed install.' echo '}' brew tap | while read tap; echo "brew tap $tap"; done brew list | while read item; echo "install_package $item '$(brew info $item | /usr/bin/grep 'built source with:' | /usr/bin/sed 's/^[ \t]*built source with:/ /g; s/\,/ /g')'" done echo '[ ! -z $failed_items ] && echo following items failed install: && echo $failed_items'
you should first run script on original system generate restore script:
./backup-homebrew.sh >restore-homebrew.sh && chmod +x restore-homebrew.sh
then, after installing homebrew on new system (in case same system), run restore-homebrew.sh
install packages have on original system.
the benefits of script on 1 given @ctrueden script tries installation options used when installed packages.
a more detailed description in my blog.
Comments
Post a Comment