Skip to content

Instantly share code, notes, and snippets.

@danmactough
Last active May 7, 2023 15:40
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save danmactough/96ccf7a51e733173894e to your computer and use it in GitHub Desktop.
Save danmactough/96ccf7a51e733173894e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get Homebrew in the new location
git clone git@github.com:Homebrew/homebrew.git ~/Homebrew
# Move all your installed packages to the new location
mv /usr/local/Cellar ~/Homebrew/Cellar
mv /usr/local/Library ~/Homebrew/Library
# Remove "root" directory files left behind
rm -rf /usr/local/.git /usr/local/{.gitignore,.yardopts,CODEOFCONDUCT.md,CONTRIBUTING.md,LICENSE.txt,README.md,SUPPORTERS.md}
# Remove all the now-broken symlinks
brew prune
# Create a symlink to `brew` executable from /usr/local/bin -- seemed like a good idea...
# https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Installation.md#untar-anywhere-and-then-symlink-the-brew-command-elsewhere
ln -sf ~/Homebrew/bin/brew /usr/local/bin/brew
# Fix all your symlinks :)
for PKG in $(brew list); do brew link $PKG; done
# Symlink the important folders
ln -s ~/Homebrew/Cellar /usr/local/Cellar
ln -s ~/Homebrew/Library /usr/local/Library
@pedzed
Copy link

pedzed commented Sep 28, 2018

The new default Homebrew location is /usr/local/Homebrew (rather than /usr/local). This makes line 10 outdated:

rm -rf /usr/local/.git /usr/local/{.gitignore,.yardopts,CODEOFCONDUCT.md,CONTRIBUTING.md,LICENSE.txt,README.md,SUPPORTERS.md}

Could be this now:

rm -rf /usr/local/Homebrew

Also, running brew prune after (re)moving the Library folder doesn't work.

$ brew prune
/bin/bash: /usr/local/Homebrew/Library/Homebrew/brew.sh: No such file or directory

Edit: I didn't read the very next command (which should be before brew prune), but I worked it out by using the path to the new brew executable.

@pedzed
Copy link

pedzed commented Sep 28, 2018

Symlinking to /usr/local requires sudo (i.e. the last two commands).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment