How to install Homebrew on macOS package manager
Naturally, you need a Mac. Requirements are as follows:
- A 64-bit Intel CPU or Apple Silicon CPU
- macOS Mojave (10.14) (or higher)
- Command Line Tools (CLT) for Xcode
- A Bourne-compatible shell for installation
Always install Homebrew in the following directory as per your CPU architecture:
- /usr/local on macOS Intel
- /opt/homebrew on macOS ARM (M1)
Open the Terminal application on your nacOS and then type the following commands.
Step 1 – Installing xcode
Xcode is Apple’s IDE for macOS. We can use Xcode to produce apps for macOS, iOS, iPadOS, watchOS, and tvOS. We need Xcode for Homebrew for installation and compiling apps. Type the following command at bash/zsh prompt:
xcode-select --install
Confirm Xcode installation:
The installation will begin and wait for some time:
After sometimes we will see the final confirmation:
Step 2 – Installing Homebrew on macOS
Now that we installed Xcode, it is time to grab the Homebrew installer shell script. Use the wget command or download a file with curl as follows:
curl -O https://raw.githubusercontent.com/Homebrew/install/master/install.sh
We can see and review source code using vim/emacs for security reasons:
vim install.sh
Finally install Homebrew by setting up permission on install.sh script as follows:
chmod +x install.sh
./install.sh
## OR directly execute install.sh ##
bash install.sh
When prompted, enter your sudo (account) password and press [RETURN]/[ENTER] to continue installation on macOS:
Wait for some time as install.sh will download many files from the Internet. It took two minutes on a 100Mbps FTTH connection. Here is the final confirmation regarding Homebrew installation on my MBP:
Step 4 – Installing homebrew on a Mac and turning off analytics
By default Homebrew collects information and send analytics to developers. If you want you can disable analytics as follows:
brew analytics off
## add to your shell startup ##
export HOMEBREW_NO_ANALYTICS=1
Once executed the following information is no longer collected:
- Homebrew user agent
- Google Analytics
- Homebrew analytics tracking ID and user ID
Display the current state of Homebrew’s analytics:
brew analytics
Step 3 – Searching for application
The syntax is:
brew search {package} brew search nginx brew search bash
We will see available options:
==> Formulae apm-bash-completion bash-git-prompt bashish bash bash-preexec calabash bash-completion bash-snippets checkbashisms bash-completion@2 bashdb dhall-bash
Want to see detailed information about package, run:
brew info {package} brew info nginx brew info bash
Sample outputs:
bash: stable 5.1.4 (bottled), HEAD Bourne-Again SHell, a UNIX command interpreter https://www.gnu.org/software/bash/ Not installed From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/bash.rb License: GPL-3.0-or-later ==> Options --HEAD Install HEAD version
Step 4 – Using brew to install or remove 3rd party applications
Let us install an updated version of bash on macOS. Type:
brew install {package} brew install bash
Installing Homebrew on a Mac and bash package
brew pin bash
To allow bash formulae to update again:
brew unpin bash
I often lock down programming languages such as PHP and Python to continue on a specific version. Hence, I thought it is crucial to mention the pin/unpin option.
Step 5 – Update all your installed apps with brew
First update the formulae and Homebrew itself:
brew update
List outdated packages/formulae:
brew outdated
Now, all you have to do is type the following command and it will upgrade all installed formulas/packages:
brew upgrade
Step 6 – Say hello to Homebrew casks
On Mac, we use Homebrew Cask to installs macOS apps, fonts and plugins, and other non-open source software collections. Search for casks:
brew search --casks {keyword}
brew search --casks google
brew search --casks docker
brew search --casks aws
Let us install google-chrome, dropbox, and docker:
brew install --cask {package}
brew install --cask dropbox google-chrome docker
Step 7 – Reclaiming your disk space
We can remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae. This will free up disk space on your Mac for sure:
brew cleanup
brew cask cleanup
See “How to remove all old and outdated brew packages on MacOS” for more info.
Step 8 – Uninstalling Homebrew if the need arises
To uninstall Homebrew, run the uninstall script from the Homebrew/install repository as follows:
curl -O https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
bash uninstall.sh --help
Quick help:
Usage: uninstall.sh [options] -p, --path=PATH Sets Homebrew prefix. Defaults to /usr/local. --skip-cache-and-logs Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS. -f, --force Uninstall without prompting. -q, --quiet Suppress all output. -n, --dry-run Simulate uninstall but don't remove anything. -h, --help Display this message.
Summing up
See Homebrew documentation online or type the following command:
man brew
🐧 3 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
FYI, wget command is not installed on macOS by default. Hence, we always end up using curl.
These days I like MacPorts. May I suggest macports tutorial too?
Excellent page. I got an Intel baed Macbook air for school and light video editing for my YouTube and this page was so useful.