Skip to content

Instantly share code, notes, and snippets.

@Skeeg
Forked from ChristopherA/brew-bundle-brewfile-tips.md
Last active February 3, 2024 00:37
Show Gist options
  • Save Skeeg/ba95f14bd3fad31ceb169801127ab797 to your computer and use it in GitHub Desktop.
Save Skeeg/ba95f14bd3fad31ceb169801127ab797 to your computer and use it in GitHub Desktop.
Brew Bundle Brewfile Tips
==> Caveats
==> dotnet@6
For other software to find dotnet you may need to set:
export DOTNET_ROOT="/opt/homebrew/opt/dotnet@6/libexec"
dotnet@6 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have dotnet@6 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/dotnet@6/bin:$PATH"' >> ~/.zshrc
zsh completions have been installed to:
/opt/homebrew/opt/dotnet@6/share/zsh/site-functions
==> llvm
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++"
llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have llvm first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
For compilers to find llvm you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"
==> libpq
libpq is keg-only, which means it was not symlinked into /opt/homebrew,
because conflicts with postgres formula.
If you need to have libpq first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
For compilers to find libpq you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
For pkg-config to find libpq you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/libpq/lib/pkgconfig"
==> pipenv
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> gh
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> cmake
To install the CMake documentation, run:
brew install cmake-docs
Emacs Lisp files have been installed to:
/opt/homebrew/share/emacs/site-lisp/cmake
==> redis
To start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/redis/bin/redis-server /opt/homebrew/etc/redis.conf
==> saml2aws
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> awscli
The "examples" directory has been installed to:
/opt/homebrew/share/awscli/examples
zsh completions and functions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> terraform-docs
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> yarn
yarn requires a Node installation to function. You can install one with:
brew install node
==> nvm
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
You can set $NVM_DIR to any location, but leaving it unchanged from
/opt/homebrew/Cellar/nvm/0.39.7 will destroy any nvm-installed Node installations
upon upgrade/reinstall.
Type `nvm help` for further information.
==> platformio
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> k9s
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> checkov
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> docker-compose
Compose is now a Docker plugin. For Docker to find this plugin, symlink it:
mkdir -p ~/.docker/cli-plugins
ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
==> jc
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> zsh-syntax-highlighting
To activate the syntax highlighting, add the following at the end of your .zshrc:
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
If you receive "highlighters directory not found" error message,
you may need to add the following to your .zshenv:
export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/opt/homebrew/share/zsh-syntax-highlighting/highlighters
==> ripgrep
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> fzf
To install useful keybindings and fuzzy completion:
/opt/homebrew/opt/fzf/install
To use fzf in Vim, add the following line to your .vimrc:
set rtp+=/opt/homebrew/opt/fzf
==> asdf
To use asdf, add the following line (or equivalent) to your shell profile
e.g. ~/.profile or ~/.zshrc:
. /opt/homebrew/opt/asdf/libexec/asdf.sh
e.g. ~/.config/fish/config.fish
source /opt/homebrew/opt/asdf/libexec/asdf.fish
Restart your terminal for the settings to take effect.
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> infracost
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> powershell
To use Homebrew in PowerShell, set:
Add-Content -Path $PROFILE.CurrentUserAllHosts -Value '$(/opt/homebrew/bin/brew shellenv) | Invoke-Expression'
~/repo/identity/terraform/identity IN-360-Add-Gitlab-Files* 1d 5h 22m 20s identity-staging-us-west-2 is-app-eks-okta/default 17:25:34

Brew Bundle Brewfile Tips

Copyright & License

Unless otherwise noted (either in this file or in a file's copyright section) the contents of this gist are Copyright ©️2020 by Christopher Allen, and are shared under spdx:Creative Commons Attribution Share Alike 4.0 International (CC-BY-SA-4.) open-source license.

Sponsor

If you more tips and advice like these, you can become a monthly patron on my GitHub Sponsor Page for as little as $5 a month; and your contributions will be multipled, as GitHub is matching the first $5,000! This gist is all about Homebrew, so if you like it you can support it by donating to them or becoming one of their Github Sponsors.

Intro to Brew, Bundle, and Brewfile

If you are using a Mac as your development environment, you really should be using Brew. You probably should be using it if you are a power user as well, as it isn't really that difficult.

A key feature of Brew is its ability to set up your Mac to a known configuration. It does this a feature called Bundle that uses Brewfiles. As doing development, or experimenting with new apps can break your system, I can easily restore back to a known configuration, both on my primary Macs, but also in VMware Fusion instances where I do more testing, including testing on old versions of MacOS and new beta versions of MacOS.

A version of Brew also is available on Linux, but I mostly use apt-get on Debian. I am considering some cross-platform development scripts to use Brew instead.

Installing Brew

Compete details are at Brew but fairly simple to install. Open terminal.app (command-space + "terminal") and paste this command on the command line.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

If you don't have a recent version of macOS, you may need to install the latest Xcode command tools first. I don't like downloading all of Xcode, so I use this trick to only install the latest command-line tools.

touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
softwareupdate -i -a
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

Another easy way to install all of this, along with some good basic security hardening practices, is to use Mike McQuaid's Strap tool by going to https://macos-strap.herokuapp.com/. If you have a github account, it will also install basic github permissions.

Basic Brew Bundle

The most basic command

brew bundle install

Looks for ~/Brewfile and installs its contents

Install a specific brewfile

If you want to use a brewfile from a non-standard place.

brew bundle --file=~/.private/Brewfile

Or more specifically:

brew bundle install --file=rs-brew-dump

Creating a Brewfile

You can dump a Brewfile of your current brew/cask/mas entries into your current directory with

brew bundle dump

or to a specific directory and file name.

brew bundle dump --file=~/.private/Brewfile

If a Brewfile already exists, you'll need to do

brew bundle dump --force

Cleaning up to match brewfile

If you want your current system configuration to match your brewfile

brew bundle --force cleanup

Best Practices: brew cask, mas and cu

A key practice is to install EVERYTHING possible using brew, brew cask, or mas. Even things like fonts!

Three tools that really make this work for more than just development tools is the ability to install a large number of macOS UI apps using brew cask install <appname>, Mac Apple Store apps using mas install <appnumber>, search for them using brew search <searchterm> & mas search <searchterm>. Not everything is avaiable this way, but the most important ones are.

To use this make sure that these entries are near the top of your Brewfile:

tap "homebrew/cask"
tap "buo/cask-upgrade"
brew "mas"

You even install many open source fonts this way. Do brew tap homebrew/cask-fonts" and Add this top the top of your Brewfile`:

tap "homebrew/cask-fonts"

On can search for fonts once tapped by

brew search font

Finally, there is a Cask-Update tool that works with brew cask to update all of your Mac apps.

Add this to your Brewfile:

tap "buo/cask-upgrade"

Then to upgrade all of you Mac apps, just do:

brew cu

Cask-Update details some other features. In particular, I like brew cu pin <caskname> which locks an app to a specific version.

Minimal Essential Bundle

My current minimal Brew on macOS is:

tap "homebrew/core"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "buo/cask-upgrade"
tap "homebrew/cask-fonts"
brew "github-keygen"
brew "gnupg"
brew "pinentry-mac"
brew "stow"
brew "mas"
brew "gh"
cask "atom"
cask "carbon-copy-cloner"cask "atom"
cask "typora"

Best Pracices: Using with .dotfiles

I have two brewfiles currently:

  • One in ~.private which I install right after installing brew and before setting up my basic .ssh and .gnupg files so that I can use GitHub. It is the minimal essential list above. I can install this manually with a script inside .private.

  • My standard in ~/Brewfile is actually a symlink to ~/.dotfiles/mac/Brewfile. I different ~/.dotfiles/ for different environments.

    • My primary Mac is a monster MacBook Pro is really more of a "desktop" for me. It has 64 GB RAM with an 8TB HD. It probably has my largest Brewfile.
    • That being said, it actually doesn't have many development tools in it. Instead, I mostly use VMware instances (mostly macOS but some Debian) for my development images. They use a different ~.dotfiles based Brewfile.
    • My smaller, older MacBook is mostly for travel. It has different set of ~/.dotfiles/ focused on just enough to work remotely. I'm always prepared to restore this Mac from scratch.
    • For a month or so each year, late summer early fall, my old MacBook also will run the latest beta of macOS, allowing me to test not just macOS, but also be prepared for changes to my development environments.

Advanced Topics & To Investigate

  • Instead of brew cask uninstall <caskname> you can do brew cask zap <caskname> which may also do additional removal of preferences, caches, updaters, etc. stored in ~/Library. See Zap

  • A pariculary powerful feature for Brew is that it attempts to install developer tools in ways that allow them to co-exist. However if you are using multiple versions of a tool, it can be difficult to understand dependencies. These links may help:

    • brew deps
      • brew deps --tree <brewformula>
      • brew deps --tree -1 <brewformula>
      • brew deps --include-build --tree $(brew leaves)
    • brew leaves
      • brew leaves | xargs brew deps --include-build --tree
      • brew leaves | xargs brew deps --installed --for-each | sed "s/^.*:/$(tput setaf 4)&$(tput sgr0)/"
      • brew leaves | sed 's/^/install /' > Brewfile
    • brew graph
    • A critique of brew leaves and brew graph
  • If you are a heavy Github user, or are creating brew formulae, there is an advanced wrapper for Homebrew that automates the creation of the Brewfile and can store it on Github, along with a many more features: https://homebrew-file.readthedocs.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment