13

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?

1
  • I've wanted to know this as well!
    – user2760103
    Commented Feb 22, 2016 at 0:36

2 Answers 2

21

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).

2
15

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.

7
  • I actually didn't mean versions - just the list of the packages installed
    – M.R.
    Commented Feb 22, 2016 at 0:53
  • Why not just brew list > stuff.txt ?
    – idjaw
    Commented Feb 22, 2016 at 0:54
  • Oh, yeah. brew list
    – Jason S
    Commented Feb 22, 2016 at 0:54
  • 3
    pip freeze gives you versions.
    – Jason S
    Commented Feb 22, 2016 at 0:55
  • @idjaw but then how to install from that file?
    – M.R.
    Commented Feb 22, 2016 at 1:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.