How to setup Homebrew on Mac OS
Most of the Mac OS users install software via the Apple App store or download a .dmg file from the Internet and and copy the app into the Applications directory or run an installation script to install the software on the Mac. Another way to install software on your Mac is using a package manager like Homebrew. Homebrew is very easy to use and you have access to a large number of free software packages from developers around the world.
Homebrew Installation and Uninstallation
First check if Homebrew is (already) installed.
Macbook Pro:~ user$ brew --version
Homebrew 3.0.5
Homebrew/homebrew-core (git revision 4324a52c3e; last commit 2021-03-14)
Homebrew/homebrew-cask (git revision 16c4718ac7; last commit 2021-03-14)
Macbook Pro:~ user$
The above output show Homebrew 3.0.5.
In case Homebrew is not installed first check the requirements for Mac OS on the Homebrew Installation site. Here you find that Homebrew requires Command Line Tools (CLT) for Xcode. Therefore I first check if Command Line Tools are installed on my Mac.
Macbook Pro:~ user$ xcode-select -p
/Library/Developer/CommandLineTools
Macbook Pro:~ patrick$
The above command return that Command Line Tools for xcode (CLT) are installed on my Mac and show the path where the Command Line Tools are installed.
In case Command Line Tools for xcode are not installed run the following command before you start with the Homebrew installation.
:$ xcode-select --install
Then go to the Homebrew Website and check the actual installation instructions. At the time of writing this document you run the following script to install Homebrew.
:$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After the installation I check the Homebrew version and run brew doctor
.
Macbook Pro:~ user$ brew --version
Homebrew 3.0.5
Homebrew/homebrew-core (git revision 4324a52c3e; last commit 2021-03-14)
Homebrew/homebrew-cask (git revision 16c4718ac7; last commit 2021-03-14)
Macbook Pro:~ user$ brew doctor
Your system is ready to brew.
Macbook Pro:~ user$
The shell output show that Homebrew version 3.0.5 is installed on the system and that I am ready to brew which means that I am now ready to install software with Homebrew.
To uninstall Homebrew you run the following script.
:$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
Update Command Line Tools for xcode
Homebrew need Command Line Tools for xcode but sometimes Command Line Tools can be outdated. When you run brew doctor
and see the following message that Command Line Tools are outdated you must ensure that the latest version of Command Line Tools is installed on your Mac.
Patricks-Macbook Pro:~ patrick$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
softwareupdate --all --install --force
If that doesn't show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Alternatively, manually download them from:
https://developer.apple.com/download/more/.
Patricks-Macbook Pro:~ patrick$ ls -l /Library/Developer
total 0
drwxr-xr-x 5 root admin 160 15 Sep 07:18 CommandLineTools
drwxr-xr-x 4 root admin 128 9 Okt 2019 PrivateFrameworks
Patricks-Macbook Pro:~ patrick$
To update Command Line Tools for xcode they must first be uninstalled and then re- installed on the system. Pls. find additional information how to uninstall Command Line Tools for xcode and check the related Apple Developer Docs.
Patricks-Macbook Pro:~ patrick$ sudo rm -rf /Library/Developer/CommandLineTools
Patricks-Macbook Pro:~ patrick$ ls -l /Library/Developer
total 0
drwxr-xr-x 4 root admin 128 9 Okt 2019 PrivateFrameworks
Patricks-Macbook Pro:~ patrick$ sudo xcode-select --install
xcode-select: note: install requested for command line developer tools
Patricks-Macbook Pro:~ patrick$ ls -l /Library/Developer
total 0
drwxr-xr-x 5 root wheel 160 28 Feb 06:35 CommandLineTools
drwxr-xr-x 4 root admin 128 9 Okt 2019 PrivateFrameworks
Patricks-Macbook Pro:~ patrick$ xcode-select -p
/Library/Developer/CommandLineTools
Patricks-Macbook Pro:~ patrick$
Homebrew Software Repositories and Tap(s)
With Homebrew package manager you have access to a wide range of software that can be installed on your system. After Homebrew has been installed on your system you find Homebrew under /usr/local/Homebrew
on your system.
Homebrew differentiates between Core Software Packages and Cask Software or so-called Casks. All Software Packages are available in GitHub Repositories.
Homebrew Core Software Packages are free software developed from developers around the world to be installed on Mac OS platforms using Homebrew. Core software will be installed based on so called formulae. A formula contain the required information for the installation such as i.e. from where the installation files should be loaded, which dependencies exist and how the installation should be performed on the different Mac platforms. All formulae for Core Software Packages have been loaded from Homebrew’s GitHub Core-Repository Homebrew/homebrew-core into the core Tap on your machine. This Tap can be found on you machine in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew Cask Software Packages are native Mac OS Apps like Google Chrome, Firefox or other Mac OS Apps that can be installed using the Homebrew Cask extension of the Homebrew Package Manager instead of installing the software via the Apple App Store or drag and drop a dmg file into the Application folder. How to use Homebrew Cask can be read on the Homebrew Cask GitHub site. Casks will be loaded from the Homebrew’s GitHub Cask-Repository Homebrew/homebrew-cask into the cask Tap on your machine. This Tap can be found on you machine in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
.
It is also possible to install Software that is not available on Homebrew’s GitHub Core-Repository or Homebrew’s GitHub Cask-Repository. In this case you must first tap
the GitHub Repository to let Homebrew know, from where it should load the formula or cask to install the software package.
For example the formula for MongoDB has been removed from the GitHub Core-Repository. But fortunately the MongoDB Team is maintaining a custom GitHub-Repository mongodb/homebrew-brew from where you can tap the formulae on your local machine.
:$ brew tap mongodb/homebrew-brew
On GitHub, a Homebrew repository must be named homebrew-brew tap
with only one argument. When you use brew tap
you can leave out the homebrew- prefix.
:$ brew tap mongodb/brew
This brew tap <username>/brew
be used as a shortcut for the long version brew tap <username>/homebrew-brew
. Homebrew will automatically add back the homebrew– prefix whenever it’s necessary.
The command brew tap
without any arguments lists the GitHub repositories that are currently tapped on your local machine and available to install software from these sources.
Patricks-MBP:~ patrick$ brew tap
homebrew/cask
homebrew/core
homebrew/services
mongodb/brew
Where are Packages on your System
Homebrew create symlinks for each installed package in /usr/local/bin
and usually point to the binary in /usr/local/Cellar/<package_name>/<version>/bin
. This is the standard. Depending on the definitions in the formula of a certain package the binaries can be also linked somewhere else on your system.
Macbook Pro:~ user$ ls -l /usr/local/bin
total 0
lrwxr-xr-x 1 user admin 28 11 Nov 2016 brew -> /usr/local/Homebrew/bin/brew
lrwxr-xr-x 1 user admin 34 1 Nov 2017 ccmake -> ../Cellar/cmake/3.9.4_1/bin/ccmake
lrwxr-xr-x 1 user admin 33 1 Nov 2017 cmake -> ../Cellar/cmake/3.9.4_1/bin/cmake
lrwxr-xr-x 1 user admin 39 1 Nov 2017 cmakexbuild -> ../Cellar/cmake/3.9.4_1/bin/cmakexbuild
lrwxr-xr-x 1 user admin 33 1 Nov 2017 cpack -> ../Cellar/cmake/3.9.4_1/bin/cpack
lrwxr-xr-x 1 user admin 41 16 Dez 2016 cryptest.exe -> ../Cellar/cryptopp/5.6.5/bin/cryptest.exe
lrwxr-xr-x 1 user admin 33 1 Nov 2017 ctest -> ../Cellar/cmake/3.9.4_1/bin/ctest
lrwxr-xr-x 1 user admin 32 1 Nov 2017 evm -> ../Cellar/ethereum/1.7.2/bin/evm
.......
The Homebrew binary link named brew point to /usr/local/Homebrew/bin/brew
. Any other binary link point into the Cellar in /usr/local/Cellar/<package_name>/<version>/bin
. The Cellar is the place on your system where you usually find Homebrew installed software packages. As you see on my system I have installed a couple of software packages like boost, cmake and node.
Macbook Pro:~ user$ ls -l /usr/local/Cellar
total 0
drwxr-xr-x 4 user admin 128 1 Nov 2017 boost
drwxr-xr-x 4 user admin 128 1 Nov 2017 cmake
drwxr-xr-x 3 user admin 96 16 Dez 2016 cryptopp
drwxr-xr-x 5 user admin 160 1 Nov 2017 ethereum
drwxr-xr-x 4 user admin 128 1 Nov 2017 gmp
drwxr-xr-x 5 user admin 160 1 Nov 2017 go
drwxr-xr-x 4 user staff 128 6 Okt 07:16 hugo
drwxr-xr-x 3 user staff 96 3 Aug 06:48 icu4c
drwxr-xr-x 4 user admin 128 1 Nov 2017 jsoncpp
drwxr-xr-x 4 user staff 128 9 Okt 07:39 node
drwxr-xr-x 3 user admin 96 12 Nov 2017 openssl
drwxr-xr-x 4 user admin 128 1 Nov 2017 solidity
Cask software is installed in the following directory.
Patricks-MBP:~ patrick$ ls -l /usr/local/Caskroom
total 0
drwxr-xr-x 4 patrick admin 128 11 Jun 09:00 opera
Homebrew Cask create a symlink in /usr/local/Caskroom/<package_name>/<version>/<symlink>
and point it to the app in the Applications directory where the app will be copied.
Patricks-MBP:~ patrick$ ls -l /usr/local/Caskroom/opera/68.0.3618.165
total 0
lrwxr-xr-x 1 patrick admin 23 11 Jun 09:00 Opera.app -> /Applications/Opera.app
Install, Uninstall and Update Software Packages
To install a package using the brew install
command.
:$ brew install <formula>
To uninstall a package using the brew uninstall
command.
:$ brew uninstall <formula>
To update and upgrade all packages with Homebrew use the following commands.
:$ brew update
:$ brew upgrade
You can also update and upgrade only a certain package.
:$ brew update <formula>
:$ brew upgrade <formula>
The update command load the new formulae and the upgrade command installs the newer software versions in the Cellar. Depending on the amount of packages you have installed this might take some time.
When you install Cask Software the app must be copied into your Applications Directory. Here you need to provide your user password.
You can list the Casks installed on your Mac.
patrick@PatrickMBNeu ~ % brew list --casks
opera
patrick@PatrickMBNeu ~ %
You can search for packages
patrick@PatrickMBNeu ~ % brew search opera
==> Formulae
operator-sdk
==> Casks
opera ✔ opera-mobile-emulator operator
opera-gx opera-neon homebrew/cask-versions/opera-beta
opera-mail operadriver homebrew/cask-versions/opera-developer
patrick@PatrickMBNeu ~ %
You install a cask package using the brew install
command.
:$ brew install <cask-package>
You uninstall a cask package using the brew uninstall
command.
patrick@PatrickMBNeu ~ % brew uninstall opera
==> Uninstalling Cask opera
==> Purging files for version 68.0.3618.165 of Cask opera
patrick@PatrickMBNeu ~ % brew list --casks
patrick@PatrickMBNeu ~ %