17

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?

0
18

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]

5
  • 1
    brew leaves will list only packages you added, not others brought in as dependancies. – MERM Apr 8 '17 at 16:04
  • 7
    Would brew install $(cat my_brews.txt) not accomplish the same in one single invocation of brew, without the need of a for loop? – Synoli Apr 8 '17 at 16:36
  • I think the newlines in my_brews.txt would mess you up. Have you tried this? – MERM Apr 8 '17 at 16:39
  • 1
    Yes, works either way for me. Bash scans the results of the $(cat)parameter expansion and then uses either of the space, newline, and tab characters to split words as if they were all the same (unless you have set some weird value for IFS, in which case either approach would fail). – Synoli Apr 8 '17 at 16:52
  • @grg I suggest that edits shouldnt change code. brew leaves seems to be the way to do it. docs.brew.sh/Manpage#leaves I dont even have the said folder .machine on my Mac. apple.stackexchange.com/review/suggested-edits/281709 – anki Mar 6 '20 at 23:07
28
xargs brew install < brew.txt

No need to cat the file (see Useless Use of Cat Award) and xargs instead of a for loop to avoid IFS.

1
  • 1
    Currently the best answer bc it doesn't require any additional libs being installed to use. – jasonleonhard Apr 23 '19 at 22:42
12

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

3
  • 5
    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. – MPLewis Apr 8 '17 at 22:13
  • This comment should be the answer: brew bundle dump and brew bundle are just what I needed! – silvansky Apr 10 '18 at 9:52
  • I concur that brew bundle is now the way to go. I switched to this method myself. – MERM Apr 24 '20 at 2:22

You must log in to answer this question.

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