How to install and use homebrew! A Mac OSX Package Manager
What is Homebrew?
homebrew is known as “The Missing Package Manager for macOS”.
It is used to install the UNIX tools Apple didn’t include with macOS in an extremely easy and flexible manner.
Prerequisites
- A 64-bit Intel CPU or Apple Silicon CPU
- macOS Mojave (10.14) (or higher)
- Command Line Tools (CLT) for Xcode:
xcode-select --install,
developer.apple.com/downloads or Xcode 3
How to install it on MacOSX?
Install xcode developer tools.
rakesh_jain@my-mac ~ % xcode-select --install
Now install homebrew:
rakesh_jain@my-mac ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
You will be prompted to enter sudo password a few times during the installation process.
Verify the installation:
rakesh_jain@my-mac ~ % brew --versionHomebrew 3.2.13Homebrew/homebrew-core (git revision 753dedc193; last commit 2021-09-22)
Homebrew Shell Completion — BASH / ZSH
Homebrew comes with completion definitions for the brew
command.
zsh
, bash
and fish
are currently supported.
If you have zsh shell ->
rakesh_jain@my-mac ~ % echo $SHELL
/bin/zsh
To make Homebrew’s completions available in zsh
, you must get the Homebrew-managed zsh site-functions on your FPATH
before initialising zsh
’s completion facility. Add the following to your ~/.zshrc
file:
rakesh_jain@my-mac ~ % cat .zshrc
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"autoload -Uz compinit
compinit
fi
If you have bash shell ->
To make Homebrew’s completions available in bash
, you must source the definitions as part of your shell’s startup. Add the following to your ~/.bash_profile
(or, if it doesn’t exist, ~/.profile
):
rakesh_jain@my-mac ~ % cat .bash_profileif type brew &>/dev/null
then
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]
then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*
do
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
done
fi
fi
If you install the bash-completion
formula, this will automatically source the completions’ initialisation script (so you do not need to follow the instructions in the caveats).
How to install unix tools with homebrew ?
The homebrew is now installed on you system and you can use it to install various unix tools.
Syntax:
rakesh_jain@my-mac ~ % brew install <package_name>
For example here I will be installing ansible configuration management tool on my Mac Book:
rakesh_jain@my-mac ~ % brew install ansible
How to search package with homebrew?
You can search or list available packages by running following commands :
Syntax:
rakesh_jain@my-mac ~ % brew search <package_name>
Example:
rakesh_jain@my-mac ~ % brew search docker
==> Formulae
docker docker-credential-helper-ecr docker-machine-driver-vmware docker-squash
docker-clean docker-gen docker-machine-driver-vultr docker-swarm
docker-completion docker-ls docker-machine-driver-xhyve docker2aci
docker-compose docker-machine docker-machine-nfs dockerize
docker-compose-completion docker-machine-completion docker-machine-parallels lazydocker
docker-credential-helper docker-machine-driver-hyperkit docker-slim mockery
==> Casks
homebrew/cask-versions/docker-edge homebrew/cask/docker homebrew/cask/docker-toolbox
That’s all!
Hope you like the tutorial. Stay tuned and don’t forget to provide your feedback in the response section.
Happy Learning!