Homebrew

Updated: February 11, 2024

Homebrew is a package manager for macOS.


Table of Contents


tldr

# install a formula
brew install faas-cli

# get options for a command ie cleanup
brew options --command cleanup

# show installed formulae
brew leaves

# show installed casks
brew list --cask

Homebrew adds apps to the command line. Be sure to install XCODE and accept license agreement first!

Brewfile

Merely using the brew bundle command will autoinstall itself. (basically included with brew)

# Create a Brewfile and lock.json
brew bundle dump
    --no-lock           # won't generate a lock.json
    --describe          # add comments

# Install from Brewfile
brew bundle -v

# List brew items
brew bundle list
    --all               # list everything
    --formula, brews    # list cli apps
    --cask(s)           # list casks
    --tap(s)            # list taps
    --mas               # list apps from mac store
    --whalebrew         # list whalebrew
    --vscode            # list vscode extensions

A good scriptable command with Brewfile could be something like:

sudo softwareupdate -ia; brew bundle -v; brew cleanup; brew doctor --verbose

FAVORTIES

# Casks
alfred
audacity
balenaetcher
calibre
cheatsheet
discord
dropzone
firefox
gitter
google-backup-and-sync
handbrake
iina
iterm2
kindle
makemkv
moom
mullvadvpn
plex
raspberry-pi-imager
send-to-kindle
signal
soundsource
starship
tradingview
transmission
vlc
warp

# Formulae
ansible
cmatrix
cmus
git
gnupg
go
hugo
inxi
tldr
tree
youtube-dl

# Taps
brew tap
homebrew/cask-fonts     # tap for nerdfonts
brew install --cask font-jetbrains-mono-nerd-font
brew install --cask font-fira-mono-nerd-font
brew install --cask font-ubuntu-nerd-font

INSTALL

https://brew.sh/

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

SETUP

# turn on/off spying
brew analytics [on|off]

ENVIRONMENT

export
    HOMEBREW_NO_ANALYTICS=1
    HOMEBREW_DISPLAY_INSTALL_TIMES=1
    HOMEBREW_NO_ENV_HINTS=1
    HOMEBREW_VERBOSE=1

TERMINOLOGY

formula     - package built from upstream sources
bottle      - pre-built keg => cask/rack instead of upstream source
cask        - package that installs native applications
keg         - installation destination directory of formula version
rack        - directory containing kegs
cellar      - directory containing racks
caskroom    - directory containing casks
tap         - directory of [formulae|casks|externals] - usually a repository

COMMANDS

brew install                    # --cask for casks
    uninstall, remove, rm       # remove a formula
        --zap                   # remove all files associated, even shared with other apps
    reinstall                   # uninstall and then install formula
    fetch                       # download a bottle or source package
        --bottle-tag            # download bottle for given tag
        --deps                  # download deps for formula
    home                        # go to homepage of formula
    leaves                      # shows only installed formulae, no dependencies
    list                        # shows list of all installed formulae and dependencies
        --formula               # only list installed formula
        --cask                  # only list installed casks
    formulae                    # shows all installable formulae
    casks                       # shows all installable casks
    tap                         # lists all installed taps
    untap                       # remove an installed tap
    search                      # find a formula
    desc                        # description of formula
        -s, --search            # search both names and descriptions
    deps                        # list dependencies for a formula or cask
        -n                      # sort deps in topological order
        --1                     # tree dependencies only one level down
        --union                 # show which formulae are dependent
        --full-name             # list dependencies by their full name
        --include-build         # include build dependencies for formula
        --include-optional      # include optional dependencies for formula
        --tree                  # show dependencies in a tree
        --graph                 # show dependencies in a graph
        --annotate              # list deps as [build, test, optional, recommended]
        --installed             # list installed dependencies
        --formula               # treat all named arguments as formulae
        --cask                  # treat all named arguments as casks
    info                        # give information about application including dependencies
        --analytics             # list global analytics data
        --github                # open a browser to the GitHub History page
    options                     # show install options
        --installed             # show options for formulae currently installed
        --command               # show all options for the specified command
    outdated                    # what’s due for upgrades?
    update                      # refresh formulae versions with repository
    upgrade                     # upgrade formulae out of sync with repository versions
        --display-times         # show how long to install
    pin                         # stop something from being updated/upgraded
    unpin                       # allow formula to update again
    doctor, dr                  # checks the intergrity of program
    prune                       # remove dead symlinks
    cleanup                     # remove stale lock files and outdated downloads
        --prune=all             # remove all cache files
        -s                      # scrub the cache of downloads for latest versions
        -n                      # list forumlas that can be cleaned up
        -r                      # only list manually installed
        -p                      # only list dependencies
    autoremove                  # uninstall zombie dependencies
        -n                      # list what would be removed
    uses                        # list what formulae it is a dependent for
    log                         # show git log
        -p, --patch             # also print patch from commit
        --stat                  # also print diffstat
        --oneline               # print one line per commit
        -1                      # print only one commit
    analytics                   # telemetry
        state                   # list if analytics is on or off
        on|off                  # turn analytics on or off
        regenerate-uuid         # make new id for analytics
    completions                 # control if homebrew links to shell completion files
        state                   # list if completions is on or off
        link|unlink             # turn completions on or off

    --cache                     # show homebrews download cache path
    --env                       # summarize homebrews build environment
    --prefix                    # display homebrews install path
    --caskroom                  # show caskroom path
    --cellar                    # show cellar path

BREW ALIASES

alias brewup='brew update; brew upgrade; brew cleanup; brew autoremove'
# just a neat alias to have with apple or just remember cmd+shift+.
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'

INSTALL CASK

Find Homebrew Formulae
Find Homebrew Casks

*brew install –cask installs GUI programs like Atom, Firefox, GIMP etc.
Cask focuses on developer type applications and not video games - Steam ain’t going anywhere.

brew tap caskroom/cask    # to install external sources

Create Installer Script

Really should just be using Brewfile instead, but here in case Brewfile eol. Use vi or nano to create a new file anything.sh

#!/bin/zsh

brew install cmatrix
brew install gnupg2
brew install go
brew install lolcat
brew install --cask firefox
brew install --cask google-chrome
brew install --cask iina
brew install --cask bitwarden
brew install --cask signal
brew install --cask spotify
brew install --cask vlc

As an example of the file. You can add applications to this list as you find new ones in cask. Don’t forget to save this file in a cloud so you can use this file for installing all programs in the list to quickly setup a new machine!! To run this file place it in the home directory machine you want to run it. Use the following command:

chmod +x anything.sh
sh anything.sh

That’s it! All those programs should now be installed on your machine \ ( ^ . ^) /