Homebrew Bundle を使って Brewfile でパッケージを管理する
Published Feb 5, 2025
⋅
Updated Feb 16, 2025
Requirements
- Homebrew (on macOS or Linux) for installing dependencies.
- Homebrew Cask is optional and used for installing Mac applications.
- mas-cli is optional and used for installing Mac App Store applications.
- Whalebrew is optional and used for installing Whalebrew images.
- Visual Studio Code is optional and used for installing Visual Studio Code extensions.
Homebrew Bundle は、 Homebrew や Homebrew Cask、 Mac App Store のためのバンドラ。
Brewfile というファイルに Homebrew 経由でインストールしたパッケージをリストアップし、そのファイルをもとに管理することができる。パソコンを新しくするときに、 Homebrew を使ってインストールしたパッケージを一括でインストールできるので便利。
すでに Homebrew を使ってパッケージをインストールしている場合、 brew bundle dump
を実行すると Brewfile を作成できる。
brew bundle dump
例えば、次のような内容の Brewfile
がカレントディレクトリに作成される。
tap "homebrew/bundle"
brew "node"
brew "git"
cask "figma"
cask "google-chrome"
この Brewfile
ファイルを使ってアプリを管理することができる。
例えば、 Brewfile
から特定のアプリ(この例では figma
)を削除し...
tap "homebrew/bundle"
brew "node"
brew "git"
cask "figma"
cask "google-chrome"
brew bundle --cleanup
を実行すると、そのアプリがアンインストールされる。
逆に、 Brewfile
に特定のアプリを追加し...
tap "homebrew/bundle"
brew "node"
brew "git"
cask "figma"
cask "google-chrome"
brew bundle
を実行すると、そのアプリがインストールされる。
このように Brewfile
にリストアップさえしておけば、一括でアプリをインストールできる。
ちなみに、Homebrew では、 macOS のアプリケーションや App Store のアプリケーションも管理できる。以下を参照。
Usage: brew bundle [subcommand]
Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask, Mac App Store
and Whalebrew.
brew bundle [install]:
Install and upgrade (by default) all dependencies from the Brewfile.
You can specify the Brewfile location using --file or by setting the
HOMEBREW_BUNDLE_FILE environment variable.
You can skip the installation of dependencies by adding space-separated values
to one or more of the following environment variables:
HOMEBREW_BUNDLE_BREW_SKIP, HOMEBREW_BUNDLE_CASK_SKIP,
HOMEBREW_BUNDLE_MAS_SKIP, HOMEBREW_BUNDLE_WHALEBREW_SKIP,
HOMEBREW_BUNDLE_TAP_SKIP.
brew bundle will output a Brewfile.lock.json in the same directory as the
Brewfile if all dependencies are installed successfully. This contains
dependency and system status information which can be useful in debugging brew
bundle failures and replicating a "last known good build" state. You can
opt-out of this behaviour by setting the HOMEBREW_BUNDLE_NO_LOCK environment
variable or passing the --no-lock option. You may wish to check this file into
the same version control system as your Brewfile (or ensure your version
control system ignores it if you'd prefer to rely on debugging information from
a local machine).
brew bundle dump:
Write all installed casks/formulae/images/taps into a Brewfile in the
current directory.
brew bundle cleanup:
Uninstall all dependencies not listed from the Brewfile.
This workflow is useful for maintainers or testers who regularly install lots of
formulae.
brew bundle check:
Check if all dependencies are installed from the Brewfile.
This provides a successful exit code if everything is up-to-date, making it
useful for scripting.
brew bundle list:
List all dependencies present in the Brewfile.
By default, only Homebrew dependencies are listed.
brew bundle exec command:
Run an external command in an isolated build environment based on the
Brewfile dependencies.
This sanitized build environment ignores unrequested dependencies, which makes
sure that things you didn't specify in your Brewfile won't get picked up by
commands like bundle install, npm install, etc. It will also add compiler
flags which will help find keg-only dependencies like openssl, icu4c, etc.
--file Read the Brewfile from this location. Use
--file=- to pipe to stdin/stdout.
--global Read the Brewfile from ~/.Brewfile.
-v, --verbose install prints output from commands as they
are run. check lists all missing
dependencies.
--no-upgrade install won't run brew upgrade on
outdated dependencies. Note they may still be
upgraded by brew install if needed.
-f, --force dump overwrites an existing Brewfile.
cleanup actually performs its cleanup
operations.
--cleanup install performs cleanup operation, same as
running cleanup --force.
--no-lock install won't output a
Brewfile.lock.json.
--all list all dependencies.
--formula, --brews list Homebrew dependencies.
--cask, --casks list Homebrew Cask dependencies.
--tap, --taps list tap dependencies.
--mas list Mac App Store dependencies.
--whalebrew list Whalebrew dependencies.
--vscode list VSCode extensions.
--describe dump adds a description comment above each
line, unless the dependency does not have a
description.
--no-restart dump does not add restart_service to
formula lines.
--zap cleanup casks using the zap command
instead of uninstall.
-d, --debug Display any debugging information.
-q, --quiet Make some output more quiet.
-h, --help Show this message.
参考