How do I safely replace brew on Big Sur?
I'm still trying to solve my problem with installing Ruby on a new Mac, and some discussions are saying that I need to reinstall brew
because of the change from the old chipset to the M1. (I'm just repeating what I've heard; I don't understand the issue.) I'm willing to try this, but it looks like uninstalling brew
also removes everything I installed with it, and that would be bad if I can't assemble a manifest and reinstall everything after.
How do I safely replace brew
?
Specifics: My new machine is an M1 Mac running Big Sur. I used Migration Assistant to move data from my previous machine, which was running Sierra. This migration carried along the old version of brew
, which apparently is not the version Big Sur wants.
First question: can I get a list of "top-level" things I've installed with brew
? I see that brew list
shows me a long list of packages, many of which I didn't explicitly install but are presumably dependencies installed on my behalf. If I'm going to have to reinstall stuff after I uninstall and reinstall brew
, I'd like to be able to figure out what I specified before I nuke anything. Or should I just save that list and feed it all to brew install
after the replacement, and let duplicate dependencies and obsolete packages sort themselves out?
Second question: what else could go wrong that I should anticipate and defend against? "Back everything up" isn't the complete solution I thought it was; I recently discovered (the hard way) that Time Machine doesn't back up everything on the disk, because apparently MacOS thinks that some files should be hidden from users.
I've seen posts that recommend installing the new brew
alongside the old one and then changing some paths and other environment variables, but it sounds confusing.
4 answers
If you just want the minimal set of top-level packages to install on your new system, brew leaves
is less verbose than CodeFarmer's brew deps --installed
.
You get a nice concise list of the packages that are not needed as dependencies by any other package.
Edit: This is mentioned in the comments on the Question.
0 comment threads
Since asking this question I've updated to 12.2 (Monterey), but it's the same problem on either.
I was nervous about blowing away my existing brew
installation, even if I first captured a list of packages that I'd need to reinstall. I found a blog post about installing the M1 version of brew
alongside my existing one. It turns out to be straightforward: the older version installed into /user/local/bin
while the new one installs into /opt/homebrew
, so they don't compete with each other. After updating PATH I can use the new one by default but still have access to the old one if I should need it. I defined an oldbrew
alias, in part for the convenience and in part as a reminder to future-me that I still have that lying around. If, in the future, I go through old-brew's packages and install them all using new-brew, then it'll be safe to remove the old one. Until then, as far as I can tell, nothing's broken.
(Unfortunately, updating brew
did not solve the Ruby problem that led me to replace brew
in the first place. So this might have been a red herring, but it's probably better to be on the version of brew
that's designed for my current hardware.)
0 comment threads
Brew's deps
command might help:
brew deps --installed
will list out top-level packages and their installed dependencies. Note that some of the top-level packages might be dependencies for other top-level packages. Still, if you were to do a fresh install of all of the top-level packages, I think Brew will also install all the dependencies and you should have the same set of packages as before.
Example:
$ brew deps --installed
/* Some top-level packages without dependencies */
aspell
bash
docbook
/* Some top-level packages with dependencies */.
docbook-xsl: docbook
fontconfig: freetype
freetype: libpng
...
$
brew deps --tree --installed
will do the same but the output will be in a tree display which can be helpful too.
$ brew deps --tree --installed
/* Some top-level packages without dependencies */
aspell
bash
docbook
/* Some top-level packages with dependencies */.
docbook-xsl
|_docbook
fontconfig
|_freetype
|_libpng
...
$
1 comment thread
You can try to search your shell's history for brew install
. Every shell has its own history command, but for example on fish I can do history | rg brew install
. (rg
is https://github.com/BurntSushi/ripgrep)
This should make it easy to figure out most things you explicitly installed, but it will miss things installed history entries being deleted (I think some shells default to a max of 1000 commands).
Brew does, of course, have a notion of "explicitly installed" packages and ways of displaying those. But then you have to look up how to do that...
1 comment thread