Most importantly, run ./bin/brew lgtm to verify any file edits before prompting for input to run all style checks and tests.
This is a Ruby based repository with Bash scripts for faster execution.
It is primarily responsible for providing the brew command for the Homebrew package manager.
Please follow these guidelines when contributing:
When running commands in this repository, use ./bin/brew (not a system brew on PATH).
- Run
./bin/brew typecheckto verify types are declared correctly using Sorbet. Individual files/directories cannot be checked../bin/brew typecheckis fast enough to just be run globally every time. - Run
./bin/brew style --fix --changedto lint code formatting using RuboCop. Individual files can be checked/fixed by passing them as arguments e.g../bin/brew style --fix Library/Homebrew/cmd/reinstall.rb - Run
./bin/brew tests --online --changedto ensure that RSpec unit tests are passing (although some online tests may be flaky so can be ignored if they pass on a rerun). Individual test files can be passed with--onlye.g. to testLibrary/Homebrew/cmd/reinstall.rbwithLibrary/Homebrew/test/cmd/reinstall_spec.rbrun./bin/brew tests --only=cmd/reinstall. - Shortcut:
./bin/brew lgtm --onlineruns all of the required checks above in one command. - All of the above can be run via the Homebrew MCP Server (launch with
./bin/brew mcp-server).
- When working in a sandboxed environment e.g. OpenAI Codex, copy the contents of
$(./bin/brew --cache)/api/to a writable location inside the repository (for example,tmp/cache/api/) andexport HOMEBREW_CACHEto that writable directory before running./bin/brew tests. This avoids permission errors when the suite tries to write API cache or runtime logs.
- Write new code (using Sorbet
sigtype signatures andtyped: strictfor new files, but never for RSpec/test/*_spec.rbfiles) - Write new tests (avoid more than one
:integration_testper file for speed). Write fast tests by preferring a singleexpectper unit test and combine expectations in a single test when it is an integration test or has non-trivialbeforefor test setup. - Keep comments minimal; prefer self-documenting code through strings, variable names, etc. over more comments.
bin/brew: Homebrew'sbrewcommand main Bash entry point scriptcompletions/: Generated shell (bash/fish/zsh) completion files. Don't edit directly, regenerate with./bin/brew generate-man-completionsLibrary/Homebrew/: Homebrew's core Ruby (with a little bash) logic.Library/Homebrew/bundle/: Homebrew'sbrew bundlecommand.Library/Homebrew/cask/: Homebrew's Cask classes and DSL.Library/Homebrew/extend/os/: Homebrew's OS-specific (i.e. macOS or Linux) class extension logic.Library/Homebrew/formula.rb: Homebrew's Formula class and DSL.docs/: Documentation for Homebrew users, contributors and maintainers. Consult these for best practices and help.manpages/: Generatedmandocumentation files. Don't edit directly, regenerate with./bin/brew generate-man-completionspackage/: Files to generate the macOS.pkgfile.
- Follow Ruby and Bash best practices and idiomatic patterns.
- Maintain existing code structure and organisation.
- Write unit tests for new functionality.
- Document public APIs and complex logic.
- Suggest changes to the
docs/folder when appropriate - Follow software principles such as DRY and YAGNI.
- Keep diffs as minimal as possible.
- Prefer shelling out via
HOMEBREW_BREW_FILEinstead of requiringcmd/ordev-cmdwhen composing brew commands. - Inline new or existing methods as methods or local variables unless they are reused 2+ times or needed for unit tests.