Sling Academy
Home/DevOps/Homebrew: How to List All Installed Packages

Homebrew: How to List All Installed Packages

Last updated: January 28, 2024

Introduction

Homebrew is a widely used package manager for macOS, though it’s also compatible with Linux. It simplifies the process of installing, updating, and managing software on your operating system by using simple command-line instructions. In this tutorial, we’ll explore how to list all packages installed on your system using Homebrew, with an emphasis on different methods and troubleshooting tips for a seamless Homebrew experience.

Getting Started with Homebrew

Before we dive into listing the installed packages, ensure that you have Homebrew installed on your system. If it’s not installed, run the installation command shown below in your macOS Terminal or Linux shell. Once you’ve done that, you can begin using Homebrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Listing Installed Packages

The simplest way to list all the installed packages with Homebrew is to use the brew list command. When you run this command, Homebrew will display all the packages you’ve installed without any additional information.

$ brew list

Output:

package1
package2
package3
...

Detailed Package Information

For a more detailed list, the brew list --verbose command can be used to display the installed files of each package.

$ brew list --verbose

Output:

/usr/local/Cellar/package1/...
/usr/local/Cellar/package2/...
/usr/local/Cellar/package3/...
...

Listing Package Dependencies

Homebrew packages often have dependencies. To see the dependencies of all installed packages, use:

$ brew deps --installed

Output:

package1: dependency1 dependency2
package2: dependency3
package3: dependency1 dependency4
...

Listing Packages as a Tree

To visually grasp the dependency structure, you can install and use the brew-graph utility:

$ brew install brew-graph
$ brew graph --installed --format=dot | dot -Tpng -o graph.png

This generates a graph saved as a PNG image that visually represents package dependencies.

Advanced Listing Techniques

For advanced users, Homebrew allows the use of formulae and casks for organizing software. We’ll explore how to list installed items for each.

Listing Formulas

A formula is a package defined by a Ruby script with instructions to install a piece of software. To list all installed formulas:

$ brew list --formula

Similarly, the brew info --installed command can be used to view detailed information about all installed formulas.

Listing Casks

A cask is an extension of Homebrew that allows the management of graphical applications through the Cask command. Use the following to list all installed casks:

$ brew list --cask

This command is helpful if you primarily use Homebrew to manage applications with a GUI.

Exporting and Sharing Your Package List

Sometimes it’s useful to export your list of installed packages, e.g., for setting up a new machine, version control, or sharing with others. To output the list to a file:

$ brew list > brew_packages.txt

Remember, you can combine flags to get tailored results, such as verbose outputs for both formulas and casks.

Pin and Unpin Packages

If you have packages that you do not want to update, you can pin them using brew pin. Conversely, you can use brew unpin to allow updates again.

$ brew pin package1
$ brew unpin package1

Troubleshooting Tips

If the brew list command is not behaving as expected, here are a few troubleshooting tips:

  • Verify your Homebrew installation by running brew doctor.
  • Make sure you have the latest version of Homebrew by updating it with brew update.
  • Check for any issues that may be posted on the Homebrew GitHub repository.

Conclusion

Homebrew’s package-listing capabilities are vital for managing the software on macOS and Linux systems. Whether it’s for a quick review, a comprehensive audit, or preparing for a system migration, knowing how to leverage the brew list command is an essential skill for any developer or power user.

Next Article: Homebrew: How to Start/Stop/Restart a Service

Previous Article: How to install/upgrade/remove Homebrew on Mac OS

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide