996

Is it possible to and how do I get a list of all the packages installed on my Mac using Homebrew? I am not interested in packages installed outside of Homebrew.

bmike
  • 235,889
amphibient
  • 11,833

11 Answers11

1159

brew list and brew list --cask

Running brew list will show a list of all your installed Homebrew packages.

In addition, brew list --cask will provide the items installed using Homebrew Cask.

brew list

grg
  • 201,078
  • 4
    If you had this list in a txt file. How would you go about installing all of them? brew install < list.txt doesn't seem to work. – Jonathan Nov 04 '14 at 14:19
  • 62
    @Jonathan xargs brew install < list.txt Feel free to ask a separate question for more details or clarification. – grg Nov 04 '14 at 19:33
  • 4
    @grgarside - love ur terminal prompt. would you be willing to share your config files for getting my prompt to look like that? – KG - Dec 09 '14 at 20:21
  • 3
    @Kaushik I've finally written a blog post about my terminal/shell setup—feel free to ask any questions there. – grg Dec 14 '14 at 12:56
  • 10
    also added the --versions flag at the end to get the list with the versions installed – H A Mar 03 '21 at 00:22
  • 2
    brew list -1 to "Force output to be one entry per line" (see man brew). However, please note that if you want to re-install everything you asked from brew before, it's better to generate your list using brew leaves --installed-on-request (short: brew leaves -r) …so once you install from that list you will get only your tools incl. the dependencies that matter at that moment—v.s. using the output of brew list that will include dependencies that might have become obsolete by the time you wish to re-install your tools. – PDK Nov 19 '21 at 11:45
642

brew leaves shows you all top-level packages; packages that are not dependencies. This should be the most interesting if you are using the list to re-install packages.

To include formula descriptions, use

brew leaves | xargs brew desc --eval-all

To include cask descriptions, use

brew ls --casks | xargs brew desc --eval-all
Rafo
  • 108
Jonathan
  • 6,580
  • 36
    Only list leaves that were manually installed: brew leaves --installed-on-request | xargs -n1 brew desc – Pablo Bianchi Oct 26 '21 at 03:08
  • 7
    brew leaves is missing any casks – Carl Walsh Dec 19 '21 at 18:14
  • 14
    At least since brew 3.5.10 (August 2022), brew desc is deprecated; brew desc --eval-all should be used.

    Also, this allows fetching descriptions for more than one package in one call. This is quicker by a factor of roughly the number of descriptions requested. This modified xargs command will make use of that: brew leaves | xargs brew desc --eval-all

    – Carl Sep 06 '22 at 16:26
  • @PabloBianchi what leaves would not have been installed on request? – minseong Feb 15 '24 at 14:20
165

brew bundle may also be interesting if you are asking because you want to manage your brew installation. This includes casks, which brew list does not. It is aimed at having reproducible Homebrew setups.

# creates Brewfile in the current directory from currently-installed packages
brew bundle dump
# edit Brewfile
# install everything from the Brewfile
brew bundle

You can use the --global flag to operate on your ~/.Brewfile and -f/--force to force overwriting of your existing file (for installation, this will force uninstallation of not-listed packages).

pR0Ps
  • 103
  • 9
    A recent dump of mine suggests that bundle now excludes dependencies. There are some other changes like quote style and ordering that are making it harder to understand the diff, but overall it looks like at least some libraries are missing from Brewfile but installed. – Sam Brightman May 16 '17 at 05:04
  • • My desired effect is to have the same brew based software at my disposal on machine B like I now have at machine A. But to freshly configure the individual apps there to have a save fresh start and get rid of any cruft I may accumulated over the years on machine A.

    • Is "brew bundle dump" on machine A, moving ~/Brewfile to machine B and there running "brew bundle" the right command sequence for this purpose?

    • After installation on the new machine B will brew there install the correct architecture (i.e. Apple Silicon instead of Intel x64) and install all necessary dependencies?

    – porg Oct 24 '21 at 10:46
  • 2
    You can check brew bundle --help for specifics and examine the Brewfile. I believe this answer is more complete and idiomatic way to do it than the accepted answer - for example, it includes taps and casks. It is architecture-independent and will install dependencies. If you want machine B to also uninstall packages which are not in the Brewfile, you'll need to provide --cleanup or do a separate brew bundle cleanup. – Sam Brightman Oct 24 '21 at 11:05
  • That's probably the best option I have seen. It also works with optional software mas-cli that manages App Store installations, so you can not only save the brews and casks but also software installed through App Store! Sweet; thanks for sharing. – Rafael Jan 22 '23 at 16:01
96

Executing brew list command shows a simple, alphabetically sorted list of all the installed formulae and Casks (GUI apps) into two separate sections.

enter image description here

However, other required formulae (dependencies) get automatically installed when installing a formulae. It is possible to view the list of all the installed packages as a nicely formatted dependency tree. To view it, execute the following command:

brew deps --tree --installed

An example output is as shown below:

enter image description here

The independently listed formulae (e.g. bash, brotli, ca-certificates etc.) have no dependencies. The formulae depicted as part of a tree structure have their dependency listed at an immediate lower level in the tree (e.g. cocoapods requires ruby which in tern requires libyaml to be installed). The formulae listed at the leaf nodes in the tree structures have no further dependencies.

Dependencies visualised in a tree structure like this can help in easily getting rid of the unnecessary packages.

Nimesh Neema
  • 51,809
  • 1
    Great answer. I'm getting my top-level packages with: brew deps --tree --installed --full-name | grep -v "└" | grep -e "^\w" | count. How to see the differences between formulae and casks – Highmastdon Dec 20 '21 at 09:57
18

Others have mentioned brew leaves, which lists things that aren't dependencies; and brew deps --tree --installed which lists the dependency tree for all installed packages.

I find the most useful output of any answers yet is the combination of these.

brew deps --tree $(brew leaves)

This will list a tree of your brew install.

Edit: This doesn't include packages that were installed as build dependencies (nor other optional dependencies). It also doesn't include casks.

Matthias
  • 295
  • 1
    doesn't show cask packages. brew bundle dump seems better https://apple.stackexchange.com/a/256269/48582 – rofrol Oct 04 '22 at 16:58
15

You may use brew list | grep 'package-name' or if are looking for specific package.
brew list 'package-name' also works and provides additional information.

9

To see brew packages :

brew list

To see cask packages :

brew list --cask

To see upgradable brew packages :

brew outdated

To see upgradable cask packages

brew outdated --cask
Sabrina
  • 390
8

You can use this snippet to list all installed packages and sort them by their size.

brew list --formula | \
    xargs -n1 -P8 -I {} \
    sh -c "
        brew info {} | \
        egrep '[0-9]* files, ' | \
        sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'
    " | \
    sort -h -r -k2 - | \
    column -t
5

Short and crisp

brew list --versions

MACBOOK:/ world.peace$ brew list --version apache-spark 3.2.1 openjdk 18 openjdk@11 11.0.14.1 sbt 1.6.2 scala 2.13.8 tree 2.0.2

Similarly, you can use:

brew list --cask
Giacomo1968
  • 5,623
3

This commands lists manually installed packages, cask or not, with versions:

cat \
    <(brew leaves --installed-on-request) \
    <(brew list --cask -1) |
brew ls --versions | sort | uniq

Also to see which packages are installed by both cask and not cask:

cat \
    <(brew leaves --installed-on-request) \
    <(brew list --cask -1) |
sort | uniq
rofrol
  • 163
-1

If you want to migrate the packages to another MacBook it's nice to know the different lists for formulae and casks:

List all top level installed packages (without casks)

comm -12 \
<(brew deps --tree --installed --full-name | grep -v "└" | grep -e "^\w" | sort) \
<(brew ls --full-name --formula | sort)

List all top level installed casks (without packages)

comm -12 \
<(brew deps --tree --installed --full-name | grep -v "└" | grep -e "^\w" | sort) \
<(brew ls --full-name --cask | sort)

Alternatively you can use sort and uniq:

sort \
<(brew deps --tree --installed --full-name | grep -v "└" | grep -e "^\w" | sort) \
<(brew ls --full-name --cask | sort) \
| uniq -d
nohillside
  • 100,768