28

Is there a way to list all the homebrew packages explicitly installed by the user (they they installed directly using brew install)?

Note brew leaves doesn't do this. Over time formula can change change their dependencies leaving orphaned leaves that were never explicitly installed by the user or adding dependencies on previously explicitly installed packages.

0

4 Answers 4

30

New answer

In short, here is an easy solution for latest brew versions

As noted in comments, brew leaves --installed-on-request does not show packages that you've installed manually, but there are not "leaves" anymore - which happens if you later install something that depends on that package

Old answer

I like @orlp's solution using jq, but I should mention that you can also use

brew leaves --installed-on-request

to exclude orphaned packages from brew leaves output. See docs

3
  • 2
    This gives the wrong answer if anything that you installed is no longer a leaf. This will happen if you install something that has a dependency on something you installed manually. Commented Dec 31, 2023 at 0:18
  • 1
    @Inigo That's right, solution usingbrew info is more correct Commented Feb 9, 2024 at 1:02
  • 3
    The Homebrew team has come to the rescue! Commented Dec 9, 2024 at 20:31
19

Simple mode using brew bundle

We can list all taps, formulae and casks that were added by the user on stdout:

brew bundle dump --file -

Or we can do it manually, without using brew bundle.

Listing all brew taps

brew tap

Listing all brew formulae installed on request

This ignores any formulae that were added automatically as dependencies, but unlike brew leaves will still show any packages that are dependencies if you installed them manually as well, and avoids listing 'orphaned' packages:

brew info --json=v2 --installed \
    | jq -r '.formulae[]|select(any(.installed[]; .installed_on_request)).full_name'

Listing all brew casks installed

At the time of writing (2022-03-20) brew doesn't keep track of which casks were installed on request, but few if any casks are dependencies for other casks/formulae, so we can simply list them all:

brew list --cask -l1
3
  • Nice. I prefer your info/jq method of finding formulas installed explicitly. Commented Mar 21, 2022 at 0:04
  • this doesn't work for me. It lists glib in all cases, although I didn't install glib explicitly. Where as brew leaves does not list it. Commented Jul 4, 2023 at 2:38
  • I include your solution to my Stack Overflow answer. Thank you for figuring this out! And today, I submitted a request that Homebrew provide a simple command for this. Commented Apr 19, 2024 at 19:24
8
brew list --installed-on-request

This new command, added in April 2024, does exactly what it says it does.

It was added in response to a request stemming from this question as well as the one on StackOverflow. Thank you Homebrew team!

brew desc $(brew list --installed-on-request)

If you forget why you installed something, this command will show the same list as above, but with the brew desc for each item.

You can make it easier to read with column:

brew desc $(brew list --installed-on-request) | column -t -s ":"
4

Seems that you can use brew bundle:

brew bundle dump --file /tmp/x
brew bundle list --file /tmp/x --formula

the temporary file can be avoided using pipes

brew bundle dump --file - | brew bundle list --file - --formula
1
  • Also doesn't work for me. It lists glib in all cases, although I didn't install glib explicitly. Where as brew leaves does not list it. Commented Jul 4, 2023 at 2:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.