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


Warning: This script will remove:
/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...
==> /usr/bin/sudo /usr/bin/find 
/usr/local/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find 
/usr/local/Frameworks -depth -type d -empty -exec rmdir {} ;
==> Homebrew uninstalled!

The following possible Homebrew files were not deleted:
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)...
==> This script will install:
/opt/homebrew==> The following new directories will be created:

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"

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

Check if everything works:

brew doctor