How to Install Packages with Homebrew on macOS

Take your Mac a step closer to Linux!

by: - Last updated on: July 6th, 2021
Key Takeaways
  • A package manager is a set of utilities that streamline the process of installation, updation, and uninstallation of computer programs on an operating system.
  • Apple’s macOS uses Homebrew as its default package manager to facilitate the installation of all kinds of packages, including both command-line utilities and GUI-based apps, on the Mac.
  • Using Homebrew, you can install and manage packages efficiently on your Mac right from the Terminal.

A package manager or package management system is a set of utilities that facilitate the process of installing, updating, and removing computer programs on an operating system. It is very prevalent among Unix and Unix-like operating systems, and the Linux operating system is its greatest proponent of all time.

install packages with Homebrew on macOS

Unlike Linux, though, macOS, which also has its roots in the Unix family, has never been particularly advanced in terms of package managers. The only option it ever had was Homebrew, which has become the de-facto package management system for macOS.

Here’s a guide explaining what Homebrew is and how you can use it to install programs on your Mac.

What is Homebrew?

Homebrew is a free and open-source package manager for macOS and Linux operating systems. It allows you to install, update, and remove programs (apps/utilities) on your Mac right from the command-line and provides access to various command-line utilities, including git, wget, nvm, and openssl.

Not just that, Homebrew also has an extension, called Cask (or Homebrew Cask), to help you with the management of GUI-based apps. So you can use it when you want to install, update, or remove graphical apps on your Mac, such as Google Chrome, VLC, Spotify, Atom, etc.

All your installed Homebrew packages live under /usr/local/Cellar and are linked to /usr/local/bin to make it easier for you to find and launch GUI-based apps right from the Applications directory, just like any other GUI app on your Mac.

Advantages of Using Homebrew

There are several advantages to using Homebrew for managing utilities and apps on your Mac. The following list highlights some of its advantages over the traditional method of installing, updating, and uninstalling apps:

  • Homebrew offers an easy app installation, updation, and deletion process that relies on using just the macOS Terminal app and a bunch of Homebrew commands.
  • It gives you the ability to bulk install, update, and delete apps at once to save you time and effort.
  • The package manager reduces unnecessary clutter on your storage by removing all the associated files related to a program when you uninstall it on your Mac. [There are certain exceptions where the related files may not entirely be deleted from the system.]
  • Homebrew facilitates device transferability, which makes migrating Homebrew packages from your current machine to a new machine quick and easy.

Prerequisites for Using Homebrew

Homebrew comes preinstalled on macOS, so unless you’ve uninstalled it yourself, you should have it on your Mac. To verify if Homebrew is present on your system, open the Terminal app and run:

which brew

If it returns a path, it means Homebrew is available on your system. In this case, make sure to update it to the latest version by running:

brew update && brew upgrade

However, if you don’t have Homebrew on your system, use the following commands to install it:

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

Next, make sure you have Xcode installed on your Mac. If you’re running low on disk space or don’t wish to install the full app, you can install only its essential (command-line) utilities that are required by Homebrew by running:

xcode-select --install

How to Install Packages With Homebrew

Once the Homebrew prerequisites are addressed, you’re now ready to install packages (utilities and apps) on your Mac.

Note: Homebrew packages are referred to as formulae, whereas Homebrew Cask apps are called casks.

Depending on what package you want to install on your Mac — command-line utility or graphical app — you’ll need to either use Brew or Brew Cask for the installation.

1. Installing Command-Line Utilities With Homebrew

If you want to install a command-line utility/formulae on your Mac with Homebrew, you’ll need to use brew. To do this, open the Terminal app and run your commands using the following syntaxes.

For finding a package, run:

brew search package_name

Eg:

brew search git

If you want to learn more about any package, check out Homebrew Formulae.

To install a package:

brew install package_name

Eg:

brew install git

When you want to upgrade a package to its latest version:

brew upgrade package_name

To remove a package from your system:

brew uninstall package_name

2. Installing Graphical Apps With Homebrew

Unlike installing regular packages (or command-line tools), installing graphical apps with cask requires you to use a slightly different set of commands. Below are some Homebrew Cask commands to help you with installing and uninstalling GUI apps/casks.

For a simple app lookup in the Homebrew Cask library, run:

brew cask search app_name

To install an app:

brew cask install app_name

Eg:

brew cask install google-chrome

If you want to see an entire list of Homebrew Cask apps, check out Homebrew Cask Formulae.

For upgrading an existing Homebrew package:

brew cask upgrade package_name

When you want to remove an app:

brew cask uninstall package_name

3. Installing Packages from Other Repositories

Even though Homebrew covers a wide range of packages, there are several other packages (command-line tools and GUI apps) that the package manager doesn’t offer.

For such instances, it does, however, provide the tap functionality, which lets you tap into (or access) other repositories so you can install packages on them to your Mac.

To install a package from another repository, use the following syntax:

brew tap repository_name

or

brew tap URL

Once you’ve tapped into the repository, you can install the package using either the brew command or the brew cask command, depending on whether it’s a command-line utility or a GUI app.

When you want to remove a tap you’ve added, run:

brew untap repository_name

Other Useful Homebrew Commands

Besides the commands listed so far, which deal with installation, updation, and deletion of packages, the following are a few other Homebrew commands that can help you manage its packages on macOS.

1. brew outdated

If you’ve got outdated Homebrew formulae/packages on your Mac that haven’t been updated in a while, brew outdated will show a list of all such packages so you can upgrade them to their latest version.

2. brew pin

Whenever you run the brew update and brew upgrade commands, Homebrew updates its packages and upgrades those installed on your system. However, sometimes, there are certain packages that you might not want to be updated automatically to avoid running into compatibility issues.

To deal with such situations, Homebrew offers the brew pin command to pin a package that you don’t want to be upgraded unless you explicitly upgrade it yourself. For this, simply use the following syntax:

brew pin package_name

To unpin:

brew unpin package_name

3. brew doctor

As you can guess by the name, the brew doctor command checks your system for any potential problems that could hamper the functioning of Homebrew.

4. brew cleanup

As you use Homebrew to install new packages, you collect a lot of unnecessary (old or redundant) files that might end up occupying a lot of the disk space on your Mac. To deal with this, there’s the brew cleanup command, which removes old versions of packages and frees up some of your storage space.

Managing Mac Programs Efficiently Using Homebrew

Homebrew makes the entire package management experience on Mac a lot easier than the traditional method. And with the help of our guide above, you should be able to use it effectively to perform pretty much all kinds of operations — everything from installing and updating packages to uninstalling them — in one place.

Weekly Newsletter

Sign up for a specially curated Tech Newsletter.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *