Getty Images/iStockphoto

Tip

How to install Homebrew on macOS for software distribution

Organizations that want to automate software distribution can use package managers such as Homebrew to simplify their business software deployment process.

It's critical to use the right tool for the job, especially when it comes to OSes, and this is where tools such as Homebrew can be exactly what desktop administrators need.

Maintaining business applications across multiple disparate systems can be frustrating and time-consuming. The challenges that come with this include the following:

  • The built-in macOS graphical installer can be difficult to manage with many Macs.
  • Individual, per-system deployments introduce opportunities for version problems, inconsistencies and dependency issues.
  • Integration with other management techniques that use automation for standardization, version control and efficiency is essential.

However, software package managers mitigate these challenges for many administrators. Package managers inventory, add, update and remove applications from the system, offering an effective way to provide users with the software they need. Package managers also help with version control by restricting application availability in repositories.

Linux systems administrators regularly use package managers such as DNF and APT to keep systems current, and even Windows administrators have access to similar tools, including Microsoft's own Winget and third-party managers Chocolatey and Scoop.

What about macOS? The Homebrew package manager is the go-to manager for many users and IT professionals who are responsible for keeping dynamic macOS systems current.

What is Homebrew and when should you use it?

Homebrew is comprehensive, with many deeper capabilities for power users who want to delve into additional use cases, but its general capabilities include the following:

  • Installing new applications.
  • Updating or upgrading installed applications.
  • Removing installed applications.
  • Listing application information.

One of the biggest benefits of command-line package managers is scripting and automating software deployments. Doing so alleviates the need to touch each system -- a difficult prospect with today's modern work-from-home culture. It also prevents users from being interrupted by installations since they can be run at night.

One of the biggest benefits of command-line package managers is scripting and automating software deployments.

Homebrew also supports Linux and the Windows Subsystem for Linux. A Linux administrator who already maintains macOS and Linux can use Homebrew to manage both platforms rather than running different package managers for each.

A typical user probably requires a small and specific set of applications including a productivity suite such as Microsoft 365, web browsers and collaboration tools. Power users, such as developers and  administrators, might require greater control and deeper access to developer tools including Git, integrated development environments, code testers, automation utilities and dependencies. This category of user will get the most mileage out of Homebrew.

How to install Homebrew

Homebrew uses Git and Ruby under the hood, which are both reliable and strong platforms. There's nothing extra to install on Macs.

Homebrew's website makes the process easy by providing an installation command to copy. The deployment script explains its tasks and awaits approval to continue or abort the installation. The installation script automatically differentiates Silicon and Intel-based Macs and adds the correct prefix location for each. As a result, there is no need to use sudo to execute Homebrew installations.

The command is (all on one line) as follows:

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

If you're scripting the Homebrew installation or prefer an unattended or uninterrupted execution, add the noninteractive=1 parameter to the installation command.

Once you install Homebrew, the primary command is brew.

Homebrew itself does not require Apple's Xcode, but many of the packages you're likely to install might. This is a good time to add Xcode's Command Line Tools to your Mac by typing xcode-select --install.

Homebrew documentation

The Homebrew team provides detailed documentation. The first documentation set is a series of brew-related man pages. The Terminology area defines important Homebrew-specific vocabulary. It can be helpful to reference this section regularly while working with Homebrew. Second, the team offers more standard documentation, including FAQs, tips and tricks, and use cases. These pages may be a little overwhelming at first, but the additional documentation is very useful.

Type brew help <command> to display information about specific subcommands, as shown in Figure 1.

A screenshot of Homebrew with the details related to the subcommand to install software.
Figure 1. Use the 'brew help install' command to learn more about the 'install' subcommand.

Don't know what software to install? The brew search command helps you find applications. Consider adding the Vim text editor, Visual Studio Code and an old CLI game named NetHack to the Macs. Try using these as search targets (Figure 2).

A screenshot of Homebrew showing the proper name for Microsoft Visual Studio Code within the Homebrew service.
Figure 2. Use the 'brew search visual studio code' command to find the correct cask name for Microsoft's Visual Studio Code.

The search feature ensures you know the correct name of the application you want to install.

How to use Homebrew

The brew command's syntax is simple and similar to that of Linux-based package managers.

Syntax:

brew subcommand argument

For example, to install the nethack package, type the following:

brew install nethack

Other subcommands let you upgrade or remove applications. To upgrade all packages managed by Homebrew, type this command:

brew upgrade

To upgrade a specific package, such as the NetHack game installed above, type the following:

brew upgrade nethack

Removing NetHack with brew is as simple as typing this command:

brew remove nethack

If you need to remove Homebrew, type the following command, or find the script on the Homebrew page):

curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh

Note that the command is all on one line.

Homebrew manages both command-line and graphical applications. Graphical applications are more complex and often install different components in various directories. Homebrew handles this complexity by using Casks. If you install a GUI-based tool, you'll find a new icon for the tool in the applications directory. Launch the new program by double-clicking the icon.

Manage additional repositories

Many administrators prefer to define their own software repository. This approach provides a single location that maintains the applications versions their organization has approved. These repositories are Homebrew Taps, and they may be internal or maintained by third parties. Homebrew assumes you'll store your repository on GitHub, but it supports other options. You can manage internal repositories and software as Homebrew Formulae, too. You can create Homebrew Casks to add software to the official or internal repositories.

Well-controlled software sources and versions are critical to maintaining safe, reliable applications. Homebrew offers plenty of choices for managing these applications and integrates well with Git and GitHub.

Manage remote systems with Homebrew

The brew command is useful if you're already sitting at the Mac you're configuring, but what about remote environments? The most obvious choice is to connect to remote Macs with Secure Socket Shell (SSH) and then run your brew commands manually. You could also put your brew commands and package information into a script and execute that across the SSH connection.

Ansible is another alternative. Once you install Homebrew on a Mac, you can use Ansible to manage the system's packages by adding the Homebrew module. This approach effectively integrates the macOS package manager into your larger Ansible management environment.

Manage standardized deployments

Another approach is bundling multiple application installations into a single Brewfile. Run this file to deploy a set of programs on one or more Macs for a standardized configuration.

For example, you might configure a single Mac with 10 Homebrew-managed utilities all internal Mac users need. Next, use Homebrew to generate a Brewfile documenting those tools. Execute the Brewfile on the other Macs to duplicate the installations on each.

Begin by generating a Brewfile on your source computer:

brew bundle dump

Place the generated Brewfile on another system and run the brew bundle command from the same directory to duplicate the installations.

Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to TechTarget Editorial, The New Stack and CompTIA Blogs.

Dig Deeper on Application delivery