When you run `brew bundle install` (or: just `brew bundle` for short), this will run `brew install ruby` to install Ruby if needed.
```console
$ brew bundle
Installing ruby
`brew bundle` complete! 1 Brewfile dependency now installed.
```
If it's outdated, this will run `brew upgrade ruby`.
If it's already installed, this will be a no-op.
```console
$ brew bundle install
Using ruby
`brew bundle` complete! 1 Brewfile dependency now installed.
```
### `brew bundle check`
You can check if a `brew bundle install` will do anything by running:
```console
$ brew bundle check
The Brewfile's dependencies are satisfied.
```
You can use this behaviour in scripts like so:
```bash
brew bundle check || brew bundle install
```
### Types
As well as supporting formulae (`brew "..."`), you can also use `brew bundle` with casks, taps, Mac App Store apps, VSCode extensions and to start background services with `brew services`.
```ruby
tap "apple/apple"
brew "apple/apple/game-porting-toolkit"
brew "postgresql@16", restart_service: true
cask "firefox"
mas "Refined GitHub", id: 1519867270
vscode "editorconfig.editorconfig"
```
Run `brew bundle` again and this outputs:
```console
$ brew bundle
Using apple/apple
Using apple/apple/game-porting-toolkit
Using postgresql@16
Using firefox
Using Refined GitHub
Using editorconfig.editorconfig
`brew bundle` complete! 6 Brewfile dependencies now installed.
```
### Projects
Adding a `Brewfile` to a project's repository (like you might a `package.json`, `Gemfile` or `requirements.txt`) is a nicer way of encoding project dependencies.
It allows you to tell users to run a single command to install all dependencies for a project and start any services.
As Homebrew supports both macOS, Linux and WSL: you can have this single command setup project dependencies on three operating systems and in continuous integration services like GitHub Actions (where it's installed by default on macOS and easily on Linux with [`Homebrew/actions/setup-homebrew`](https://github.com/Homebrew/actions/tree/master/setup-homebrew)).
### `brew bundle dump`
`Brewfile`s can also be used as a way of saving all supported packages into a single file.
You can do this with `brew bundle dump --global --force` to write to e.g. `~/.Brewfile` (check `man brew` for the exact path used in your configuration):
```console
brew bundle dump --global --force
```
If you also pass `--describe`, you can also get the `Brewfile` to contain descriptions of each of the packages:
```console
brew bundle dump --global --force --describe
```
might add something like the following:
```ruby
# Powerful, clean, object-oriented scripting language
brew "ruby"
```
You can then reinstall (and, by default, upgrade) all of these with:
```console
brew bundle --global
````
## Advanced Usage
### `brew bundle cleanup`
If you've used `brew bundle dump` to store all the software you use, you can quickly cleanup anything else with:
```console
$ brew bundle cleanup --global --force
Uninstalling gcc... (1,914 files, 459.8MB)
Uninstalled 1 formula
```
### `brew bundle list`
If you want to get a list of all the formulae in your `Brewfile`, you can use:
```console
$ brew bundle list
apple/apple/game-porting-toolkit
postgresql@16
```
You can get other types with e.g.:
```console
$ brew bundle list --cask
firefox
```
### `brew bundle edit`
To open your `Brewfile` in your text editor, run:
```console
$ brew bundle edit
Editing /some/project/Brewfile
```
### `brew bundle add` and `brew bundle remove`
You can add and remove entries to your `Brewfile` by running `brew bundle add` or `brew bundle remove`:
```console
brew bundle add wget
brew bundle remove wget
```
### `brew bundle exec`
`brew bundle exec` allows you to run a command in an environment customised by your `Brewfile`.
Homebrew is a [rolling release](https://en.wikipedia.org/wiki/Rolling_release) package manager so it does not support installing arbitrary older versions of software.