macOS | Installing and Using the Homebrew Package Manager
What Is Homebrew?
Installing Homebrew makes package version management easier.
Ubuntu and CentOS provide package managers such as apt-get and yum, but macOS does not provide this kind of package manager by default, so you need to install one yourself.
The Missing Package Manager for macOS — Homebrew
Installing Homebrew
Run the following command in a terminal.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
New installation command:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Successful Installation
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 95726, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 95726 (delta 3), reused 8 (delta 3), pack-reused 95717
Receiving objects: 100% (95726/95726), 21.86 MiB | 127.00 KiB/s, done.
Resolving deltas: 100% (69501/69501), done.
From https://github.com/Homebrew/brew
* [new branch] master -> origin/master
* [new tag] 0.1 -> 0.1
* [new tag] 0.2 -> 0.2
... omitted ...
* [new tag] 1.4.0 -> 1.4.0
HEAD is now at b4d43e950 Merge pull request #3401 from DomT4/vendor_or_na
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4673, done.
remote: Compressing objects: 100% (4415/4415), done.
remote: Total 4673 (delta 62), reused 1098 (delta 46), pack-reused 0
Receiving objects: 100% (4673/4673), 3.81 MiB | 116.00 KiB/s, done.
Resolving deltas: 100% (62/62), done.
Tapped 4445 formulae (4,720 files, 12.0MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/sanghopark/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics.html
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
Installation Failure
Problem Caused by Installing Xcode but Not Accepting the License
During installation, the following error may appear and the installation may fail.
Press RETURN to continue or any other key to abort
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
sudo xcodebuild -license
This happens when Xcode is installed but the license agreement has not been accepted. Start Xcode for the first time and click Agree.
Warning: /opt/homebrew/bin is not in your PATH
During installation, the following message may appear and brew may not run.
==> Downloading and installing Homebrew...
HEAD is now at 98999cc51 Merge pull request #13754 from Rylan12/cask-artifacts-hash
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
As the message /opt/homebrew/bin is not in your PATH indicates, this occurs because /opt/homebrew/bin has not yet been registered in PATH. Add /opt/homebrew/bin to PATH.
Enter the following command in the terminal.
echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.zshrc
How to Use Homebrew
Check the Version
$ brew -v
Homebrew 1.3.1
Homebrew/homebrew-core (git revision d6b4; last commit 2017-08-16)
Install a Package
$ brew install {program name}
Disable and Enable a Package
$ brew unlink {program name} # Temporarily disable
$ brew link {program name} # Enable
Update the Package List
$ brew update # Update formulae
$ brew upgrade # Rebuild updated packages
List Installed Packages
$ brew list
Remove a Package
$ brew remove {program name}
Homebrew Configuration List
$ brew --config
HOMEBREW_VERSION: 1.3.1
ORIGIN: https://github.com/Homebrew/brew
HEAD: 69799d97b1e7314912b2ee234dec2c179c5fb969
Last commit: 9 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: d6b4b6ba05bbff6a3731f80580ebee7574bf6494
Core tap last commit: 2 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: quad-core 64-bit sandybridge
Homebrew Ruby: 2.0.0-p481
Clang: 7.0 build 700
Git: 2.4.9 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.8.0_121
macOS: 10.10.5-x86_64
Xcode: 7.1.1
CLT: N/A
X11: N/A
Removing Homebrew
$ cd `brew --prefix`
$ rm -rf Cellar
$ brew prune
$ rm `git ls-files`
$ rmdir Library/Homebrew Library/Aliases Library/Formula Library/Contributions
$ rm -rf .git
$ rm -rf ~/Library/Caches/Homebrew