Email Facebook Twitter Reddit
AppleInsider may earn affiliate commissions for purchases made through links on our site.
Homebrew is a macOS package manager that allows users to install and manage UNIX tools and third party software. Here's how to get started.
Unlike most UNIX/Linux based systems, macOS does not have a standard mechanism for installing third-party command line tools beyond the standard Apple installer. On most UNIX/Linux based systems, the tools are installed by a package manager where packages can be downloaded, updated, synchronized, and removed. Most of these package managers include automation.
The best solution to this problem on macOS is a third party package manager called Homebrew.
Not only is Homebrew easy to use, but it also keeps Mac tools up to date with relatively little hassle. It is also possible to automate the installation of tools using scripts, but this is beyond the scope of this article. For now, we will use only the simplest examples, and more complex topics will be covered later.
What needed to get started with Homebrew on macOS
- Ruby Version Manager (RVM)
Setup is simple and requires 4 basic steps.
First, go to the GPGTools website, download and run the GPGTools installer. Exit the installer when you're done. This installs the GPG Keychain app, which allows you to create SSH keys that will later be used by the Homebrew installation script.
GPG is short for GNU Privacy Guard, but don't worry, it won't install VPNs or other networking software. GPGTools only installs the GPGTools application and a few additional UNIX tools it needs. It also installs the System Preferences Preference Panel.
After installing GPGTools, navigate to your Applications folder and launch the GPG Keychain Access application. Follow a very simple first invitation – provide a name, email address, password if you like (this is a good idea). This password is only used for SSH keys that the application creates. You won't need it anymore unless you access the keys manually in the Terminal.
After the GPGTools application generates your keys, it will store them in an invisible folder called “.ssh” in your user folder. Leading “.” makes the folder invisible unless you do something to make the Finder show invisible files. In most cases, you won't need direct access to the keys:
Public Key Infrastructure or PKI allows you to exchange information securely using encrypted signatures instead of passwords.
Note that the id_rsa file in the .ssh folder is your private key. Never share this key with anyone or allow access to it from your Mac. The other file, is_rsa.pub, is your public key and can be freely transferred or uploaded to public key servers. Other files are used by the system to set up SSH.
The GPGTools application will display a window showing your new public key and confirming that it is valid.
Next, you need to install a third-party Ruby version manager, the package manager for the Ruby language. This is necessary because most of Homebrew and its setup scripts (called Formulae) are written in Ruby. It also installs verified keys for GPG itself. It's pretty easy. The RVM website lists this step at the top. Open the Terminal app on your Mac from the /Applications/Utilities folder and copy and paste:
gpg2 — recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Press Return to execute the command.
This tells GPG to obtain official GPG keys from a trusted public key server. As the keys load, you will see several lines of text. This should complete fairly quickly:
Note that if you are logged into your Mac as a non-administrator user, you may need to prefix each terminal command with a sudo command. For example:
sudo gpg2 — recv keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
sudo or “do superuser” is a UNIX tool for running another command as the “superuser”, also sometimes referred to as the root user. The superuser has almost unlimited power to do anything on a UNIX system, so use it carefully. You may be prompted for the macOS administrator password. If you're logged into your Mac as an administrator user, you probably won't need to prefix terminal commands with sudo.
You can use all four arrow keys on your keyboard to move backward or forward in the Terminal.
Then run the second line of the script shown on the RVM website in the Terminal application by copying and pasting:
curl -sSL https://get.rvm.io | bash -s stable
and press Return.
This uses the curl UNIX download tool to install the Ruby Version Manager on your Mac. Ignore the warning that the key is not certified. When it finishes, the installation script will mention a few advanced UNIX setup items, but you can mostly ignore them if you don't plan to use Ruby directly. You can also re-run this same command in the future to update RVM to the latest version.
In the Terminal, you can cancel any running command by simultaneously pressing the Control-Option-Z keys.
You can check the installation of RVM + Ruby in the Terminal:
< p>Now that the preconfiguration is complete, you are ready to install Homebrew itself. As stated on the home page, copy and paste the following into the terminal:
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install . sh)”
and press Return.
This tells curl to fetch and execute the Hombrew installation script from its online GitHub repository. The first time you run the script, you may be asked to enter the macOS administrator system password in the Terminal. Enter it and press Return. Follow the rest of the prompts on the screen.
The Homebrew installation script will download and install everything Homebrew needs. Follow the instructions on the screen. It may ask for your Mac administrator password. This shouldn't take too long. When it finishes, you'll get a few notes from Homebrew, most of which you can safely ignore.
After installing Homebrew, you're ready to run your first Homebrew or just brew command in the Terminal:
brew install wget
wget is another GNU download tool similar to curl. wget is common on many Linux and UNIX systems.
Everything. That's all it takes to install Homebrew and the tool.
Every time you install a Homebrew-hosted tool, you type “brew install (formula name)” in the Terminal, where (formula name) is the name of the Homebrew formula that it recognizes. Each tool installs with a Ruby script (formula) that it knows how to download and run. He also knows how to install any formula dependencies.
You can search for any tool name on Homebrew right at the top of the main page. Just enter the name of the tool in the search box and it will show you a popup with all the matching formulas. Click the name of a formula to see its page and the brew install command. For example, if you want to search for a Perl package, go to www.brew.sh and type “perl” in the search box. You should see:
Also, most Homebrew packages are installed in an invisible /usr/local system directory, a subfolder of Cellar. symbolic links are created for each tool in the UNIX binary (bin) directory where they can be seen by the system. symbolic links in UNIX are equivalent to macOS desktop aliases.
The Homebrew team is pretty good at adding new tools as they become available and updating existing formulas. There is also extensive documentation and a forum.
Keeping Homebrew up to date
There are the last few commands, which you need to know to automatically update any formulas you have installed and Homebrew itself. These include:
- Brew Help – general help about Homebrew.
- brew commands – show general commands for cooking.
- brew list – shows all installed homebrew formulas.
- update brew – checks the Homebrew setup script for a new version and installs it if available.
- brew is deprecated – shows all formulas that need to be updated.
- brew uninstall – removes the specified formula from your Mac.
And finally, a very important formula update command that you'll want to run often, if not every day:
brew update – Update any outdated formulas on your Mac.
Be aware that if you have a lot of formulas installed, updating brew can take quite a while, even with a fast connection.
If you're really adventurous, you can check out the entire list of Homebrew essential formulas.
In addition to the UNIX command line tools, Homebrew also allows you to install some standard apps using the cask flag, which is very similar to the normal install command. For example, to install Mozilla Firefox, simply type:
weld install — cask firefox
The Homebrew website also has a complete list of casks available.
Most cask applications are installed in the usual Applications folder. It's also a good way to update multiple applications at the same time by running brew update.
Once the tool is installed with Homebrew and visible on macOS, you can find out where it lives on the system with the which command followed by the name of the tool. For example, in the Terminal, type:
and press Return.
You should see:
This works for all UNIX system tools.
If you know the version flag supported by the tool, you can also get its version in the Terminal. Most UNIX tools use either the tool name followed by the -v flag, or — version flag. For example:
wget — version
GNU Wget 1.21.3, built on top of darwin21.3.0.
Most tools contain a paragraph or so of information after the version information.
For the specific commands supported by each tool, use the UNIX help (or manual) system:
man (tool name)
< blockquote>man wget
Wget is a non-interactive network downloader.
wget [option]… [URL]…
followed by pages with commands and their options.
Press Control-Z to exit man.
There is so much more to homebrew
Now that you If you know how to install, update, and use Homebrew, you can install almost any popular UNIX tool package.
In the following articles, we'll look at some of the more advanced Homebrew commands. And we'll talk about how to use shell scripts to write the main install & update the script to automate all sets of installations at once.