Homebrew Package Manager 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 run an installation script to install the software on the Mac. Applications that will be installed this way are installed into the Application folder of your Mac.
Macbook Pro:~ user$ ls -l /Applications
total 0
drwxr-xr-x@ 3 root wheel 96 11 Jul 19:10 App Store.app
drwxr-xr-x@ 3 root wheel 96 21 Jun 18:48 Automator.app
drwxr-xr-x@ 3 user admin 96 14 Jun 09:32 Brackets.app
drwxr-xr-x@ 3 root wheel 96 21 Jun 18:48 Calculator.app
drwxr-xr-x@ 3 root wheel 96 21 Jun 18:48 Calendar.app
drwxr-xr-x@ 3 root wheel 96 11 Jul 19:10 Chess.app
drwxr-xr-x 3 user admin 96 2 Okt 07:18 CleanMyMac 3.app
drwxr-xr-x 3 user admin 96 19 Feb 2018 ClipGrab.app
drwxr-xr-x@ 3 root wheel 96 11 Jul 19:10 Contacts.app
drwxr-xr-x@ 3 root wheel 96 21 Jun 18:48 DVD Player.app
........
An alternative way to install software in your Mac is using a package manager like Homebrew. With Homebrew you have access to a large number of free software packages developed by developers for the installation via Homebrew.
Homebrew installation
Check if xcode command line tools are installed.
Macbook Pro:~ user$ xcode-select -p
/Library/Developer/CommandLineTools
Macbook Pro:~ patrick$
The above command return that xcode command line tools for xcode (CLT) are installed on your Mac and show the directory path where xcode command line tools are installed.
In case xcode command line tools are not installed run the following command in shell:
xcode-select --install
Check if Homebrew is (already) installed.
Macbook Pro:~ user$ brew --version
Homebrew 1.7.7
Homebrew/homebrew-core (git revision 45d56; last commit 2018-10-08)
Homebrew/homebrew-cask (git revision 33e4d; last commit 2018-10-09)
Macbook Pro:~ user$
The above output show Homebrew 1.7.7.
In case Homebrew is not istalled run the follwoing command from shell to install Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
If you run the above shown ruby script you will be asked to run the following command.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Check the Homebrew installation.
Macbook Pro:~ user$ brew --version
Homebrew 1.7.7
Homebrew/homebrew-core (git revision 02721; last commit 2018-10-21)
Homebrew/homebrew-cask (git revision 4bcf; last commit 2018-10-22)
Macbook Pro:~ user$ brew doctor
Your system is ready to brew.
Macbook Pro:~ user$
The shell output show that Homebrew version 1.7.7 is installed on the system and that you are ready to brew which means that you are ready to install software.
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.
In principle, Homebrew differentiates between Core Software Packages, Non-Core Software Packages and so-called Cask(s). These Software Packages are available in GitHub Repositories or so called Tap(s).
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 basic package definition and tell Homebrew i.e. how a package should be installed. This mean a formula of a certain software package 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-Tap Homebrew/homebrew-core into /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
on your machine.
It is also possible that Software can be installed with Homebrew but the formula is not available on Homebrew’s GitHub Core-Repository-Tap. Then we speak of Non-Core Software Packages because these Software Packages are not tap(ed)
into the Homebrew Core-Repository-Tap. In this case you must first tap
the Non-Core-Repository-Tap to let Homebrew know from where it should load the formula to install the software package.
Cask software or Casks
are native Mac OS Apps like Google Chrome, Firefox or other native Mac OS Apps that can be also installed using the Homebrew Package Manager. All available Casks to install Mac OS native Apps have been loaded from Homebrew’s GitHub Profile Homebrew/homebrew-cask into /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks
.
To get an overview which tap(s) are currently linked to your Homebrew Installation use th efollowing command.
Patricks-MBP:~ patrick$ brew tap
homebrew/cask
homebrew/core
homebrew/services
mongodb/brew
Where is Homebrew on your System
Homebrew create symlinks for each installed package in /usr/local/bin
and symlink the relevant binary. Usually this symlink will point to /usr/local/Cellar/<package_name>/<version>/bin
but it can also be anywhere else on your system.
So lets ls -l /usr/local/bin
:
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
.......
Homebrew package manager binary is named brew and symlinked to /usr/local/Homebrew/bin/brew
. The Homebrew package is installed in /usr/local/Homebrew
This is the place on your system where Homebrew is installed.
Macbook Pro:~ user$ ls -l /usr/local/Homebrew
total 64
-rw-r--r-- 1 user admin 98 16 Dez 2016 CHANGELOG.md
-rw-r--r-- 1 user admin 3161 1 Nov 2017 CODE_OF_CONDUCT.md
-rw-r--r-- 1 user admin 827 9 Okt 07:38 CONTRIBUTING.md
-rw-r--r-- 1 user admin 1334 1 Nov 2017 LICENSE.txt
drwxr-xr-x 7 user admin 224 9 Okt 07:38 Library
-rw-r--r-- 1 user admin 8471 9 Okt 07:38 README.md
-rw-r--r-- 1 user admin 899 9 Okt 07:38 azure-pipelines.yml
drwxr-xr-x 3 user admin 96 9 Okt 07:38 bin
drwxr-xr-x 5 user admin 160 1 Nov 2017 completions
drwxr-xr-x 49 user admin 1568 9 Okt 07:38 docs
drwxr-xr-x 5 user admin 160 9 Okt 07:38 manpages
Where are Core Software Packages on your System
Also the symlinks from other packages that you install with Homebrew have been created in /usr/local/bin
directory and symlinked into /usr/local/Cellar/...
. 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, node but also hugo which is my static website genrator.
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
Install and Uninstall Core Software
To install formula with Homebrew to your system use the command.
brew install <formula>
To uninstall a formula from your system simply use the command.
brew uninstall <formula>
After installation the software package exist in the Cellar.
/usr/local/Cellar/<formula>/<version>
Update and Upgrade Core Software packages
First you update all formulae and Casks using the following command.
brew update
or if you want to update only a specific formula
brew update <formula>
Then you upgrade all your software packages using the following command.
brew upgrade
or if you want to upgrade only a specific formula
brew upgrade <formula>
The upgrade command installs newer software versions of all packages in the Cellar. Depending on the amount of packages you have installed this might take some time.
Where are Cask Software Packages on your System
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
From the output above you can see that I installed a GUI software package with the help of Homebrew. It is the Opera browser.
The installation takes place in the following path /usr/local/Caskroom/<package_name>/<version>/<symlink>
. The symlink point to the /Applications directory where Homebrew copy the app.
Patricks-MBP:~ patrick$ ls -l /usr/local/Caskroom/opera
total 0
drwxr-xr-x@ 3 patrick admin 96 11 Jun 09:00 68.0.3618.165
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 and uninstall Cask GUI Software Packages
When you install GUI Software the app must be copied into your Applications Directory. Here you need to provide your user password.
drwxr-xr-x 4 patrick admin 128 9 Aug 2018 java
Patricks-MBP:~ patrick$ brew cask install opera
==> Downloading https://get.geo.opera.com/pub/opera/desktop/68.0.3618.165/mac/Opera_68.0.3618.165_Setup.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'opera'.
==> Installing Cask opera
==> Moving App 'Opera.app' to '/Applications/Opera.app'.
Password:
🍺 opera was successfully installed!
To uninstall GUI Software Packeges you simply provide the uninstall command like this.
Patricks-MBP:~ patrick$ brew cask uninstall java
==> Uninstalling Cask java
==> Removing launchctl service com.oracle.java.Helper-Tool
==> Removing launchctl service com.oracle.java.Java-Updater
==> Uninstalling packages:
com.oracle.jdk-10.0.2
com.oracle.jre
==> Removing files:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Java/Home
/Library/Java/MacOS
==> Removing directories if empty:
/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk
==> Purging files for version 10.0.2,13:19aef61b38124481863b1413dce1855f of Cask java
Update Cask GUI Software Packages
To update Casks you can check if some Casks are outdated using the following command brew cask outdated
. Outdated Casks can be updated using the brew cask upgrade
command.
More detailed information regarding the brew cask usage can be found on Homebrew-Cask.