Table of Contents
- Introduction
- Basic Understanding of Homebrew Installation
- Brew Commands and Package Management
- Finding the Exact Path of Installs
- Advanced: Understanding Symlinks and the Package’s Real Location
- Where Are Formulae and Casks Stored?
- Viewing Package Information and Dependencies
- Uninstalling Packages and Cleanup
- Implications of the Installation Directory
- Conclusion
Introduction
Homebrew is a highly popular package manager for macOS (and Linux), which allows users to easily install, manage, and uninstall software packages on their system, right from the command line. If you’re a developer or work extensively with command-line tools, you would know the convenience that Homebrew brings to the table. But once you begin installing various packages, you might start wondering where exactly Homebrew is storing them on your system. This article is aimed at unraveling the mystery of Homebrew’s package storage.
Basic Understanding of Homebrew Installation
The default installation of Homebrew goes into the /usr/local
directory on macOS and /home/linuxbrew/.linuxbrew
on Linux. Within this directory, Homebrew creates its own hierarchy to manage its operations.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
When the installation is complete, you’ll find Homebrew’s directory structure looks something like this:
/usr/local/Cellar
: This is where Homebrew stores installed packages./usr/local/Homebrew
: This directory contains Homebrew’s own source files./usr/local/bin
: Executable files for Homebrew packages are linked here./usr/local/share
: Architecture-independent data is stored here./usr/local/opt
: Symlinks to the active versions of installed packages reside here.
Brew Commands and Package Management
Commands like brew install
and brew uninstall
allow you to manage packages directly from the command line. When installing packages, Homebrew downloads and stores the package contents generally in the Cellar
directory and then symlinks the necessary files into the appropriate locations in the /usr/local
tree.
For example:
$ brew install wget
This command will install the wget
package, and the files will be placed in a subdirectory inside the Cellar
. Running:
$ ls /usr/local/Cellar/wget
Will show you a directory likely named after the version of wget
that has just been installed, for instance wget/1.21.1
.
Finding the Exact Path of Installs
If you need to find the exact install path for a package managed by Homebrew, you can use the brew --prefix
command:
$ brew --prefix
For example:
$ brew --prefix wget
This will output the path to the installed wget
package, which typically looks like this:
/usr/local/opt/wget
Here, /usr/local/opt/wget
is a symlink to the actual directory within the Homebrew Cellar
.
Advanced: Understanding Symlinks and the Package’s Real Location
Homebrew uses symbolic links to add packages to your system’s path without clutter. When you use the brew link
command after an installation, Homebrew creates symlinks that point from the Cellar
to the bin
, share
, and other directories within /usr/local
.
Let’s dive deeper and inspect these symlinks. You can do this using the ls -l
command:
$ ls -l /usr/local/bin/wget
This will show you where the symlink for wget
is pointing to:
lrwxr-xr-x 1 user admin 28 Mar 1 12:00 /usr/local/bin/wget -> ../Cellar/wget/1.21.1/bin/wget
Here, the ../Cellar/wget/1.21.1/bin/wget
part is the real directory location in the Cellar
where wget
resides.
Where Are Formulae and Casks Stored?
Under Homebrew, packages are handled as either ‘formulae’ or ‘casks’. A formula is for command-line software, while a cask is used for desktop applications. The way Homebrew stores these types of packages is slightly different.
Formulae are stored within the Cellar
as we’ve mentioned previously, but casks are installed into the /usr/local/Caskroom
, where each application lives in a subdirectory named after its version number.
$ brew install --cask firefox
This will end up creating a directory under:
/usr/local/Caskroom/firefox
Each version that has been installed (or used to be installed) will have its own subdirectory:
$ ls /usr/local/Caskroom/firefox
85.0.1
Viewing Package Information and Dependencies
Getting more information about where a package stores its executables, data, and configuration files is simple with the brew info
command:
$ brew info wget
Not only will it provide you with useful information about the package, such as where the files are located or what the installed versions are, but it also helps you understand the package’s dependencies and additional options.
Uninstalling Packages and Cleanup
Understanding package uninstallation is equally important; you can remove packages with brew uninstall
. All the symlinks and files related to the package are removed. However, to completely remove all unused files and clear cached downloads, it’s recommended to run brew cleanup
.
To remove old package versions:
$ brew cleanup
This ensures that your Cellar
doesn’t get cluttered with outdated packages.
Implications of the Installation Directory
The default Homebrew directory settings work great for most users, but knowing the installation directory is key if you’re dealing with file permissions, protecting certain directories, or working in an environment with multiple users. Be mindful that installing outside the default paths requires you to handle more setup, such as adjusting your PATH variable and potentially dealing with more permission issues.
Conclusion
In conclusion, Homebrew intuitively organizes its installed packages primarily within the /usr/local/Cellar
directory for macOS, with symlinks pointing from /usr/local/bin
and other directories for ease of use. Regardless of your proficiency with macOS or command-line tools, at one point or another, understanding where Homebrew stores its files can lead to smoother package management and a better grasp of your system’s organization.