This tutorial provides a deep dive of Homebrew,
a package manager for Mac OSX (MacOS)
that’s like other package mangers for Linux:
Distribution
Package Manager
Format
GUI tools
Darwin (macOS)
Homebrew
-
brew
Debian, Ubuntu
dpkg
.deb
APT (Advanced Packaging Tool)
RedHat, Fedora, openSUSE
RPM
.rpm
Yum, apt4rpm, up2date, urpmi, ZYpp, poldek
Slackware
tgz
-
-
Arch Linux, Frugalware, DeLi Linux
Pacman
-
-
Puppy Linux
PETget
-
-
Windows
Chocolatey
-
choco
Step-by-step instructions are provided here to install Homebrew itself
and then install Homebrew packages based on the name of
formulae specified for installation
in a command such as:
brew install wget
DEFINITION: A formula provides instructions on how to install packages and
their dependencies, such as where to find tar.gzip files for download.
Brew installs packages in its own Cellar directory (folder)
and adds symlinks to the /usr/local folder.
Homebrew is the newest and most popular package utility on OSX.
Make a full backup of your system right before following these instructions.
Open the App Store to install XCode, Apple’s IDE for developing Swift and Objective-C to run on iPhones and iPads.
PROTIP: Apple’s App Store only installs .app files. So programs invoked from the command line Terminal (such as gcc) need to be installed a different way.
To verify XCode CLI install:
/usr/bin/xcodebuild -version
This message means that it’s not installed:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Open a Terminal to install XCode CLI:
xcode-select --install
If XCode is not already installed, you are prompted to install it:
Installation is to folder: /Library/Developer/CommandLineTools/.
Homebrew requires OS X 10.5+ and the Xcode command line tools.
To download the Command Line Utilities, go to https://developer.apple.com/download/more/
and look for your version of “Command Line Tools (macOS 10.14) for XCode 10”,
one that doesn’t say “beta”.
Since the El Capitan version of Mac OSX,
file permissions in /usr/local have changed,
causing error messages such as:
The linking step did not complete successfully
The formula built, but is not symlinked into /usr/local
There is no response if no brew package has been installed.
See one level below one of the above folders for a specific formula,
such as openssl:
ls /usr/local/Cellar/openssl/
It is usually a version number, such as:
1.0.2h_1
DEFINITION: A “Keg” is the installation prefix of a formula, such as:
openssl-1.0.2h_1.el_capitan.bottle.tar.gz
Packages
List brew package .rb (Ruby language) files installed:
ls /usr/local/Library/Taps/homebrew/homebrew-core/Formula
The response is a long list.
List brew package folders:
brew search
The response is a long list.
Troubleshoot Homebrew
Different ways to install weget.
The above is one of
several ways to install the wget command-line utility.
One way is to install Apple’s Xcode.
brew install --build-from-source wget
Test wget operating:
cd ~/Downloads
wget http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz
Verify brew installation:
brew doctor
If you see this message at the top of messages returned:
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
The above may occur if curl and nodejs were installed without using homebrew.
Remove them before installing node and curl using Homebrew:
rm -rf /usr/local/include/node/
Create symlinks to installations performed manually in Cellar.
This allows you to have the flexibility to install things on your own but
still have those participate as dependencies in homebrew formulas.
First, see what exactly will be overwritten, without actually doing it:
brew link --overwrite --dry-run openssl
The response is:
Warning: openssl is keg-only and must be linked with --force
Note that doing so can interfere with building software.
“Keg-only” refers to a formula installed only into the Cellar and not linked into /usr/local,
which means most tools will not find it.
This is to avoid conflicting with the system version of the same package.
Alternately, if aswcli is specified for dry-run, the response is, on an Intel x86 mac:
Warning: Already linked: /usr/local/Cellar/awscli/1.10.44
To relink: brew unlink awscli && brew link awscli
brew link
NOTE: Homebrew installs to the Cellar it then symlinks some of the installation into /usr/local
so that other programs can see what’s going on.
A symlink to the active version of a Keg is called an “opt prefix”.
Warning: Broken symlinks were found. Remove them with `brew prune`:
brew prune
A sample response:
Pruned 1598 symbolic links and 185 directories from /usr/local
List formula (package definitions):
brew edit $FORMULA
The above command brings you to your default text editor
(vim or whatever is specified in the $EDITOR variable).
Type :q to quit out.
Upgrade brew formulas
List brew packages that are obsolete:
brew outdated
To stop a specific package from being updated/upgraded,
pin it:
brew pin $FORMULA
$FORMULA is ???
To allow that formulae to update again, unpin it.
Download and update ALL software packages installed:
brew upgrade
To see which files would be removed as no longer needed:
brew cleanup -n
No response if there is nothing to clean. Otherwise, example:
Warning: Skipping awscli: most recent version 1.16.170 not installed
To really remove all files no longer needed:
brew cleanup
A sample response:
Removing: /Users/mac/Library/Caches/Homebrew/mariadb-10.1.14.el_capitan.bottle.tar.gz... (36.6M)
==> This operation has freed approximately 36.6M of disk space.
Remove/Uninstalll
PROTIP: Before deleting, identify its dependencies. For example:
brew deps python3</strong>
would yield:
gdbm
openssl
readline
sqlite
xz
Two delete commands does the same:
brew uninstall package
brew remove package
Additional flags:
`–force` or `-f` forcibly removes all versions of that package.
`–ignore-dependencies` ignore dependencies for the formula when uninstalling the designated package, which may cause other brews to no longer work correctly.
## Tap #
Brew tap adds repos not in the Homebrew master repo
from inside a larger package.
https://github.com/Homebrew/brew/blob/master/docs/brew-tap.md
says tap adds to the list of formulae that brew tracks, updates, and installs from.
0. List brew tap packages already installed:
brew tap
0. Install the ip tool included with iproute2 on Linux:
brew tap brona/iproute2mac
brew install iproute2mac
The command specififies the account and repo in GitHub, as in
https://github.com/brona/iproute2mac
or https://superuser.com/questions/687310/ip-command-in-mac-os-x-terminal
## brew install --cask #
Homebrew cask extends homebrew and brings its elegance, simplicity, and speed to
MacOS (OS X) GUI applications and large binaries.
https://caskroom.github.io
With Cask, you can skip the long URLs,
the "To install, drag this icon…", and manually deleting installer files.
0. Temporarily set the permissions on /usr/local:
sudo chown $USER /usr/local
0. Install brew cask:
brew tap caskroom/cask
brew install brew-cask
Applications are kept in their Caskroom under /opt and symblinked to $HOME/Applications
from
https://github.com/caskroom/homebrew-cask
0.
https://caskroom.github.io, the home page, said there are 3,197 casks as of June 5, 2016.
QUESTION: Is there a graph of growth in cask counts over time?
0. Install the cask extension to Homebrew:
PROTIP: One should see the cask definition before using it.
I would be suspicious of casks with sparse information.
The safe way to get the homepage URL of the programmer is from here (don't Google it and end up at a rogue site).
0. Look at some cask definitions:
https://github.com/caskroom/homebrew-cask/blob/master/Casks/google-chrome.rb
is a sample cask definition:
cask 'google-chrome' do
version :latest
sha256 :no_check
url 'https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
name 'Google Chrome'
homepage 'https://www.google.com/chrome/'
license :gratis
auto_updates true
app 'Google Chrome.app'
zap delete: [
'~/Library/Application Support/Google/Chrome',
'~/Library/Caches/Google/Chrome',
'~/Library/Caches/com.google.Chrome',
'~/Library/Caches/com.google.Chrome.helper.EH',
'~/Library/Caches/com.google.Keystone.Agent',
'~/Library/Caches/com.google.SoftwareUpdate',
'~/Library/Google/GoogleSoftwareUpdate',
'~/Library/Logs/GoogleSoftwareUpdateAgent.log',
],
rmdir: [
'~/Library/Caches/Google',
'~/Library/Google',
]
end
0. Install the cask:
brew install --cask google-chrome
Cask downloads then moves the app to the ~/Applications folder,
so it can be opened this way:
0. Open the installed cask from Terminal:
open /Applications/"Google Chrome.app"
0. Installing with cask enables you to cleanup:
brew cask cleanup
### Error prevention
If you get an error about "permissions denied":
0. Create a Caskroom folder
## Analytics off
Homebrew now defaults to retrieving behavioral analytics tracking. Although anonymized, you may not want to participate in that. To disable the extra network traffic:
brew analytics off
## Debian apt-get
Download Fink commander Fink Installer.pkg from
http://finkcommander.sourceforge.net/help/install.php
This explains:
Fink stores data in the directory “/sw” by default.
This goes against the Filesystem Hierarchy Standard’s recommendation to use “/usr/local”.
Within Fink’s directory, a FHS-like layout (/sw/bin, /sw/include, /sw/lib, etc.) is used.
## Documentation #
0. For more documentation on brew, look
here and:
man brew
## Social media #
Social media from
brew's readme:
* @MacHomebrew on Twitter
* IRC freenode.net#machomebrew
* Email homebrew-discuss@googlegroups.com
*
Read archive of emails at https://groups.google.com/forum/#!forum/homebrew-discuss
## More on OSX
This is one of a series on Mac OSX:
* [MacOS Setup step-by-step, with automation](/mac-setup/)
* [MacOS Hardware and accessories](/apple-macbook-hardware/)
* [MacOS dotfiles for System Preferences setup automation](/dotfiles/)
* [MacOS Homebrew installers](/macos-homebrew/)
* [MacOS Boot-up](/macos-bootup/)
* [MacOS Versions](/apple-mac-osx-versions/)
* [MacOS Keyboard tricks](/apple-mac-osx-keyboard/)
* [MacOS Terminal Tips and Tricks](/mac-osx-terminal/)
* [MacOS Find (files and text in files)](/find/)
* [Text editors and IDEs on MacOS](/text-editors/)
* [MacOS Xcode.app and CommandTools (gcc)](/xcode/)
* [MacOS Command-line utilities](/mac-utilities/)
* [Task Runners Grunt and Gulp](/task-runners/)
* [Applications on MacOS](/apple-mac-osx-apps/)
* [1password on MacOS](/1password/)
* [Data Backups on MacOS](/apple-mac-osx-backup/)
* [Manage Disk Space on MacOS](/mac-diskspace/)
* [Screen capture on MacOS](/screen-capture-apple-mac-osx/)
* [Printing from macOS or Linux](/printing/)
* [Ports open](/ports-open/)
* [MacOS iPhone integration](/mac-iphone/)
* [Windows on Apple MacOS](/windows-on-apple-mac-osx/)
* [Packer create Vagrant Windows image](/packer/)
* [Remote into Windows](/rdp/)
* [Python on MacOS](/python-install/)
* [Maven on MacOS](/maven-on-macos/)
* [Ruby on MacOS](/ruby-on-apple-mac-osx/)
* [Node on MacOS installation](/node-osx-install/)
* [PHP on MacOS](/php-on-apple-mac-osx/)
* [Java on MacOS](/java-on-apple-mac-osx/)
* [Scala ecosystem](/scala-ecosystem/)