62

I recently purchased a MacBook Pro 13" with the M1 chip and transferred all my data over using a Time Machine backup. Homebrew packages are currently installed in /usr/local/opt/ but it is my understanding that they should be under /opt/homebrew for Apple Silicon Macs.

How can I:

  1. Get the list of packages I currently have installed
  2. Remove those from /user/local/opt
  3. Reinstall them under /opt/homebrew

I kind of assumed Homebrew would be clever enough to do this automatically but apparently it needs some manual maintenance.

Here's my Homebrew config if it helps:

HOMEBREW_VERSION: 2.7.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: dad7dc6a1498b80770d98f2d7cd6fb927c300bbb
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2b1d79d038bffdbfcee93283051d48919a4caf3d
Core tap last commit: 16 hours ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.30.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.1-arm64
CLT: 12.3.0.0.1.1607026830
Xcode: N/A
Rosetta 2: false

Thanks in advance!

0

2 Answers 2

86

According to https://docs.brew.sh/Installation, /usr/local is for Intel binaries, /opt/homebrew for ARM. So you may want to reinstall instead of just migrating.

You can dump the list of currently installed packages with brew bundle dump. To duplicate your current installation, you'll need to

  • run brew bundle dump to create a Brewfile

  • install ARM Homebrew into /opt/homebrew by following the instructions in https://docs.brew.sh/Installation

    cd /opt
    sudo mkdir -p homebrew
    sudo chown -R $(whoami) homebrew
    curl -L https://github.com/Homebrew/brew/tarball/master |\
        tar xz --strip 1 -C homebrew
    
  • make sure that the ARM version is at the beginning of your PATH

    PATH=/opt/homebrew/bin:$PATH
    
  • Reapply the brew file created in step one

    hash -d brew
    brew bundle install --file /path/to/Brewfile
    
  • Optionally run brew analytics off to turn off the tracking/analytics gathering done by Homebrew

PS: Some formulae don't seem to work on ARM yet

PPS: /usr/local/Cellar and any symlinks from /usr/local/bin into it can be removed afterwards.

1
  • Thanks for the advise! As I've used the migration assistant to migrate all applications, I had to include --force when running brew bundle install, but then everything worked fine
    – Nico Haase
    Commented Mar 17 at 10:43
17

Here's the approach I ultimately took.

First, I took note of my installed brew packages:

brew list

I just kept this as a text file so that I could refer to it later. I then uninstalled the old version of Homebrew and all its packages:

cd ~/Desktop
wget https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
chmod +x ./uninstall.sh
sudo ./uninstall.sh --path=/usr/local

and removed the file once that was done:

rm uninstall.sh

I then installed Homebrew with M1 support:

cd /opt; sudo mkdir homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

Added the following to my ~/.zshrc file:

export PATH=/opt/homebrew/bin:$PATH

and sourced it with:

source ~/.zshrc

I then referred to the list from my first step and began installing the necessary packages one by one :) Most packages I was using seem to already have ARM support which is awesome!

4
  • Ah. I did‘t think about removing the old installation :-)
    – nohillside
    Commented Jan 11, 2021 at 20:21
  • @DaniG2k I am getting the below error brew list Warning: your HOMEBREW_PREFIX is set to /usr/local but HOMEBREW_CELLAR is set to /opt/homebrew/Cellar. Your current HOMEBREW_CELLAR location will stop you being able to use all the binary packages (bottles) Homebrew provides. We recommend you move your HOMEBREW_CELLAR to /usr/local/Cellar which will get you access to all bottles."
    – sejn
    Commented Nov 2, 2021 at 7:32
  • 2
    Running sudo ./uninstall.sh --path=/usr/local actually tries to delete the entire /usr/local directory!: rmdir: /usr/local: Operation not permitted. Is it safe to run anyway?
    – Seb
    Commented Jun 14, 2022 at 13:26
  • This is an easier option for uninstalling brew, as outlined in the repo: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)".
    – Jakob
    Commented Mar 7, 2023 at 22:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .