Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install multiple homebrew formulas at the same time

You can install multiple homebrew formulas by brew install package1 package2. But if you have a text file with all the packages that you would like to install. How would you do it?

brew install < packages.txt doesn't work. It gives me the response: This command requires a formula argument

like image 423
Jonathan Avatar asked Nov 04 '14 14:11

Jonathan


People also ask

Can I brew install multiple packages?

You can install multiple homebrew formulas by brew install package1 package2 . But if you have a text file with all the packages that you would like to install.

What happens if you install homebrew twice?

There should be no problem doing that. Homebrew will just download the files needed to brew the formula, then run the configuration and compilation by itself.


2 Answers

Like this:

brew install $(cat packages.txt)

or even just

brew install $(<packages.txt)
like image 150
Mark Setchell Avatar answered Oct 14 '22 10:10

Mark Setchell


Here's an alternative one-line approach, which bypasses the need to create a file as an in-between step:

Syntax:

brew install $( brew search my-search-term | grep my-filter-term | tr '\n' ' ' )

vs.

brew search x | grep y > install_list.txt
brew install $( < install_list.txt )

Alternative (using awk):

brew search x | awk '/inclusion string/ && !/exclusion string/' | tr '\n' ' ' )

Example:

Suppose I wanted to install all the Nerd Fonts not currently on my machine in one go.

brew search fonts will give multiple rows in results – similar to the default output from ls:

brpro ➜ ~ brew search font
==> Partial Matches
birdfont                       font-hack-nerd-font
dfontsplitter                  font-hack-nerd-font-mono
font-3270 font-halant          font-noto-sans-tibetan
font-3270-nerd-font ✔          font-hammersmith-one
font-3270-nerd-font-mono ✔     font-han-nom-a
font-abeezee font-hanalei      font-noto-sans-vai
(...)

Piping the output to grep -i nerd gives a single line-separated list of only the taps we want.

brpro ➜ ~ brew search font | grep -i nerd
font-3270-nerd-font
font-3270-nerd-font-mono
font-anonymouspro-nerd-font
font-anonymouspro-nerd-font-mono
font-arimo-nerd-font
font-arimo-nerd-font-mono
font-aurulentsansmono-nerd-font
(...)

We can use tr to convert this output to a whitespace-separated single line:

brpro ➜ ~ brew search font | grep nerd | tr '\n' ' '
font-3270-nerd-font font-3270-nerd-font-mono font-anonymouspro-nerd-font font-anonymouspro-nerd-font-mono (...)

Now we just need to pass the result to brew install:

brew install $( brew search font | grep nerd | tr '\n' ' ' )

Pipes! Composition! Joy!

La voie Unix!

like image 36
Benjamin R Avatar answered Oct 14 '22 09:10

Benjamin R