26

Does Homebrew offer anything similar to pip's pip install -r requirements.txt feature? I have a new MacBook Pro arriving today, so one of the first tasks will be to migrate my brew installations. I've already performed a brew list > brew.txt command. Will I be able to use this to install all the packages it lists in one command on the new machine?

Chuck
  • 1,780

3 Answers3

43
brew leaves > my_brew.txt
xargs brew install < my_brew.txt

Use xargs instead of a for loop to avoid IFS.

nohillside
  • 100,768
grg
  • 201,078
24

You can do brew leaves > my_brews.txt and then on the new machine do for i in $(cat brew_leaves); do; brew install "$i"; done. You can use newlines where there are semicolons above. [assuming bash]

anki
  • 11,753
MERM
  • 689
  • 1
  • 7
  • 12
15

MERM provided a working answer, but others may be interested in a solution that, while not included with Homebrew, is published by the same people. Homebrew bundle is a brew package that is designed for this purpose, also handling casks and, I think, Mac App Store apps (with the mas package).

Chuck
  • 1,780
  • 8
    Just an addition to this, you can use brew bundle dump to create a file of everything that you have installed currently, transfer the output file to another computer, and run brew bundle to install everything. – Mike Lewis Apr 08 '17 at 22:13
  • 1
    This comment should be the answer: brew bundle dump and brew bundle are just what I needed! – silvansky Apr 10 '18 at 09:52
  • 1
    I concur that brew bundle is now the way to go. I switched to this method myself. – MERM Apr 24 '20 at 02:22