正如Peter Eisentraut 所建议的那样,我确实最终通过重新安装来迁移我的 Homebrew 安装。您可以编写一些脚本来重新点击所有额外的水龙头,并重新安装所有以前安装的小桶,而无需太多手动工作:
#!/bin/sh
# save list of kegs for later reinstallation
brew list > kegs.txt
# back up old Homebrew installation
mv $HOME/brew $HOME/old-brew
# install Homebrew into /usr/local
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# retap all the taps
# NB: It is not enough to move the tap repos to their new location,
# because Homebrew will not automatically recognize the new formulae.
# There might be a configuration file we could edit, but rather than
# risk an incomplete data structure, let's just retap everything.
for tapDir in $HOME/old-brew/Library/Taps/*
do (
cd $tapDir
tap=$(git remote -v | \
grep '(fetch)' | \
sed 's/.*github.com\///' | \
sed 's/ (fetch)//')
/usr/local/bin/brew tap $tap
) done
# reinstall all the kegs
/usr/local/bin/brew install $(cat kegs.txt)
# much later... ;-)
rm -rf kegs.txt $HOME/old-brew
当然,定制的 Homebrew 安装会有额外的皱纹。例如,如果您已提交对任何与 Homebrew 相关的 Git 存储库的更改,您可能希望在重新安装小桶或清除旧安装之前导入该工作:
cd /usr/local
for f in $(find . -name '.git')
do (
repoDir=$(dirname $f)
cd $f/..
git remote add old-brew-$f $(dirname $HOME/old-brew/$f/..)
git fetch old-brew-$f
) done
请注意,我只是非常轻松地测试了上面的第二个片段,因为我个人没有以这种方式定制我的 Homebrew。
此方法未解决的 Homebrew 的另一个方面是在原始安装期间使用的自定义标志。例如,要安装,wine
您需要使用该--universal
标志安装各种依赖项,并且上面的脚本不会在启用此类标志的情况下重新安装它们。有关这样做的解决方案,请参阅@xuhdev 的答案。