Reputation: 1073
Is there a way or a special command in brew to freeze the installed packages into a requirements.txt file, just like you can with pip in python? And then to quickly reinstall them all from that file?
Upvotes: 13
Views: 6389
Reputation: 19830
Use Homebrew-bundle; it’s designed for that.
# generate a Brewfile
$ brew bundle dump
$ ls
Brewfile
# check everything is installed
$ brew bundle check
The Brewfile's dependencies are satisfied.
It works with both local formulae files and a global one for the current user. It allows you to install everything specified in a Brewfile
(that’s the default you can use whatever name you like) as well as uninstall what’s installed but not listed in the file. The file not only list installed formulae but also installed taps (e.g. homebrew/versions
, homebrew/php
, etc) and casks (if you use Homebrew Cask).
Upvotes: 21
Reputation: 13779
Edit to answer question w/o version freezing.
brew list >brew.txt
<brew.txt xargs brew install
--
Homebrew is designed to give you the latest versions of packages. Freezing versions is not its strong point.
There are two features that get you part of the way. brew list --versions
will print a list of packages with their installed version numbers (separated by spaces, which requires reformatting to be useful. And brew tap homebrew/versions
gives you access to some old versions of packages.
Unfortunately, the naming scheme does not quite work. For example, I have the node
package installed, which is currently 5.5.0
. Then I brew install homebrew/versions/node4-lts
. What ends up in brew list --versions
?
node 5.5.0
node4-lts 4.3.1
In short, doing what you're asking would require some scripting (which may or may not exist, but doesn't appear to be built into Homebrew) which tried to map major version numbers to entries in homebrew/versions
and was able to handle weird cases such as 4 -> node4-lts
. It would be limited to major or in certain cases major and minor versions because that's what homebrew/versions
has. And it would have to check in brew info
for each package what the current version is, because the current version is just the package name with no number.
Upvotes: 15