Migrate Homebrew from Intel Macs to Apple Silicon Macs

Dump all your existing Homebrew packages:

brew bundle dump

If you’re using custom shell installed by Homebrew (ie. fish), change it back to bash temporarily:

chsh -s /bin/bash

You may also need to change this in System Preferences – Users & Groups (right click on your avatar and choose Advanced Options…)

Uninstall existing Homebrew (and all its packages):

curl -fsSL -o /tmp/uninstall.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
/bin/bash /tmp/uninstall.sh --path=/usr/local

Output:

Warning: This script will remove:
/Users/sparanoid/Library/Caches/Homebrew/
/Users/sparanoid/Library/Logs/Homebrew/
/usr/local/Caskroom/
/usr/local/Cellar/
/usr/local/bin/brew -> /usr/local/bin/brew

Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y

==> Removing Homebrew installation...
Warning: Failed to delete /usr/local/Caskroom
rm: /usr/local/Caskroom: Permission denied
Warning: Failed to delete /usr/local/Cellar
rm: /usr/local/Cellar: Permission denied
==> Removing empty directories...
Password:
==> /usr/bin/sudo /usr/bin/find 
/usr/local/bin 
/usr/local/etc 
/usr/local/include 
/usr/local/lib 
/usr/local/opt 
/usr/local/sbin 
/usr/local/share 
/usr/local/var 
/usr/local/Caskroom 
/usr/local/Cellar 
/usr/local/Homebrew 
/usr/local/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find 
/usr/local/bin 
/usr/local/etc 
/usr/local/include 
/usr/local/lib 
/usr/local/opt 
/usr/local/sbin 
/usr/local/share 
/usr/local/var 
/usr/local/Caskroom 
/usr/local/Cellar 
/usr/local/Homebrew 
/usr/local/Frameworks -depth -type d -empty -exec rmdir {} ;
==> Homebrew uninstalled!

The following possible Homebrew files were not deleted:
/usr/local/.com.apple.installer.keep
/usr/local/Frameworks/
/usr/local/Homebrew/
/usr/local/MacGPG2/
/usr/local/bin/
/usr/local/etc/
/usr/local/include/
/usr/local/lib/
/usr/local/opt/
/usr/local/remotedesktop/
/usr/local/sbin/
/usr/local/share/
/usr/local/var/
You may wish to remove them yourself.

Reinstall Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This script will install Homebrew in the new /opt/homebrew/ directory:

==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Reinstall packages from your dump bundle:

brew bundle
# or:
brew bundle install --file /path/to/your/Brewfile

Switch back to your favorite shell:

chsh -s /opt/homebrew/bin/fish

Restore previously installed Node modules:

ls /usr/local/lib/node_modules/ | while read m; do
  npm install -g "$m"
done

Please note that it does not take care of your local linked modules.

Check if everything works:

brew doctor