Sling Academy
Home/DevOps/How to install/upgrade/remove Homebrew on Mac OS

How to install/upgrade/remove Homebrew on Mac OS

Last updated: January 28, 2024

Introduction

Homebrew is a popular package manager for macOS that simplifies the process of installing, upgrading, and removing software on the Mac operating system. Whether you’re a developer needing to install various tools, or just an enthusiast looking to manage software outside of the App Store, Homebrew can be an indispensable part of your workflow. In this tutorial, you will learn the basics of managing Homebrew, including its installation, upgrade process, and removal.

Installation of Homebrew

To install Homebrew, you must have the command line tools for Xcode installed, which include git and other important utilities. You can install these by running the following command in your terminal:

xcode-select --install

Once you have the command line tools, you can install Homebrew by pasting the following command into the Terminal, which will download and execute the installation script:

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

This will run the installation script, which first checks for system requirements, then installs Homebrew by creating the necessary directories and downloading the Homebrew repository to /usr/local/Homebrew. Here is an example output of a successful installation:

==> This script will install: /usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /opt/homebrew
==> The following new directories will be created: /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /opt/homebrew
... Installation successful!

Upgrading Homebrew

It’s important to regularly update Homebrew to get the latest versions of software. To update Homebrew itself, you run:

brew update

This command will fetch the newest version of Homebrew and all of its formulas from GitHub. The output looks like this:

Updated Homebrew from abc123 to 123abc.
Updated 3 taps (homebrew/core, homebrew/cask, and another tap).
==> New Formulae
formula1 formula2
==> Updated Formulae
updated_formula

You can then upgrade all installed software with:

brew upgrade

If you only want to upgrade a specific package, use:

brew upgrade 

This command attempts to upgrade the software without losing your custom configurations. Output example for a specific package upgrade:

==> Upgrading 1 outdated package:
some_package 1.2.3 -> 2.0.0
==> Upgrading some_package
==> Downloading https://homebrew.bintray.com/bottles/some_package-2.0.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring some_package-2.0.0.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/some_package/2.0.0: 1,234 files, 12.3MB

Removing Software with Homebrew

To remove a package you installed using Homebrew, execute:

brew uninstall 

If you want to also remove all data associated with the package, you can run:

brew uninstall --zap 

This is the output when uninstalling a package:

Uninstalling /usr/local/Cellar/some_package/2.0.0... (1,234 files, 12.3MB)

Diagnosing Issues with Homebrew

Should you experience any issues with Homebrew or if you need to check on the health of your installation, you can use the brew doctor command:

brew doctor

This will provide you with warnings, potential issues, and recommended steps to ensure Homebrew will function properly. Typical output might include messages advising you of unlinked kegs, outdated software, or potential conflicts.

Removing Homebrew

If you decide that you no longer require Homebrew, it can be uninstalled by executing the following script:

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

The uninstall script will remove Homebrew and all data related to it from your system. Here is what you can expect to see:

==> Running Homebrew Uninstaller
==> Removing Homebrew-installed packages ...
==> Removing Homebrew-related files ...
==> Homebrew uninstalled!

Advanced Homebrew Usage

Once you have the basics down, you may want to explore more advanced Homebrew functionality such as:

  • Managing multiple versions of a package using brew switch
  • Creating a Homebrew bundle to back up or migrate your installs with brew bundle dump and restoring it with brew bundle install
  • Exploring the dependencies of a given package with brew deps
  • Cleaning up unnecessary files and older versions with brew cleanup

Conclusion

This guide has provided you with the necessary steps and commands to install, upgrade, and remove Homebrew on your macOS system. As a versatile package manager, Homebrew is integral for easy software management on your Mac. With its removal just as straightforward as its installation, you can use Homebrew with the confidence that it is always under your control.

Next Article: Ubuntu: How to Delete a Folder and Its Contents

Previous Article: How to check CPU/RAM/Disk usage in Ubuntu

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