Homebrew is a popular package manager for macOS operating system. It allows you to download and install binaries, applications, and utilities using your terminal.
In this article, you'll learn how to install and use Homebrew on your macOS machine.
Homebrew requires the following:
- A 64-bit Intel CPU
- macOS Mojave (10.14) (or higher)
- Command Line Tools (CLT) for Xcode or Xcode (click here to download)
- A Bourne-compatible shell for installation (e.g.
Before we actually install Homebrew, you need to install Xcode's command-line tools package. Xcode is not required to use Homebrew, but some of the packages you install will need Xcode's command-line tools.
Execute the following command in your terminal to install Xcode's command-line tools package:
$ xcode-select --install
Follow the instructions on the screen to complete the installation of Xcode's command-line tools.
Now you can install Homebrew with the following command:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The above command executes the installer script provided by the Homebrew team. Follow the instructions printed on the screen to finish the installation.
To update Homebrew to its latest version, run the following command in your terminal:
$ brew update
Make sure you always update Homebrew before installing or updating any software.
Each package in Homebrew is called a Formula. To install new formula, you use the following command:
$ brew install <formula>
For example, to install Node.js default version with Homebrew, you execute the following command:
$ brew install node
Homebrew also provides an online package browser to browse all the available packages for macOS and Linux.
To upgrade an already installed package (formula), just execute the following command:
$ brew upgrade <formula>
To upgrade all packages, run the
upgrade command without specifying any package name as shown below:
$ brew upgrade
Downgrading a package is a little tricky with Homebrew.
First of all, you need to use the
search command to find the lower version of the package that you want to downgrade:
$ brew search node ==> Formulae libbitcoin-node node-build node@12 nodebrew llnode node-sass node@14 nodeenv node node@10 node_exporter nodenv ==> Casks nodebox nodeclipse
Let us say you want to downgrade Node.js from version 14 to 12. Run the following command:
$ brew install node@12
Next, you need to unlink the currently installed Node.js version:
$ brew unlink node
Finally, you need to link the newly installed version of Node.js:
$ brew link node@12 --force
That's all you need to do. To verify that Node.js downgraded version is linked successfully, use the following command:
$ node -v
To remove a package completely, you use the
$ brew uninstall <formula>
For example, to remove Node.js (don't do it unless required), execute the following command:
$ brew uninstall node
To clean up all the outdated downloads from your computer, use the following command:
$ brew cleanup
Installing Desktop Applications
Homebrew is not just limited to command-line tools. You can use Homebrew Cask to download and install desktop applications like Google Chrome, VS Code, Atom, and more.
Cask is already included in Homebrew, so you don't need to install anything.
To install a desktop application (cask), you use the
brew cask install command:
# install Visual Studio Code $ brew cask install visual-studio-code
To uninstall a cask, execute the following command:
$ brew cask uninstall visual-studio-code
By default, Homebrew contains two lists of formulae:
homebrew/core includes a list of command-line packages that you can install. All the GUI applications are included in
Homebrew also lets you install 3rd-party software. To do so, you first need to add the 3rd-party formulae to Homebrew and then use
brew install to install the formula.
For example, to install MongoDB with Homebrew, you need to tap into
$ brew tap mongodb/brew
Then you can install MongoDB like this:
$ brew install mongodb-community
To remove an already tapped repository, use the
$ brew untap mongodb/brew
To view all tapped repositories, you use the following:
$ brew tap
If you no longer need Homebrew, remove it with the following command:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
That's all folks! In this article, we learned how to install and use Homebrew on a macOS machine.
Homebrew is a package manager for macOS and Linux. It lets you download and install command line tools, desktop applications, and utilities.