Conditionally bundle apps with environment variables

Brew bundle allows for conditional loading of dependencies, using environmental variables.

As an examples, I use different versions of node on my work and personal machines.

If want, I can always install the latest version of Node. But also install the LTS version on my work machine.

Terminal window
brew "node"
brew "node@20" if [[ $MACHINE != "work" ]]

To proc this, I need to set an environment variable when running the command:

Terminal window
MACHINE=work brew bundle

Inverting the command with unless

The Brewfile DSL also offers an unless keyword.

This is identical to != above.

Use unless, if you think natural language reads better than code.

Terminal window
cask "arc" unless [[ $MACHINE == "work" ]]

Next steps

I have a strong opinions about how to manage machine-specific environment variables. See the appendix on environment variables in the paid material for details.

Next chapters to write

  • understanding brewfile
  • mas
  • docker (whale)