Keywords: Homebrew | Version Management | brew search
Abstract: This article provides a comprehensive guide on how to list available package versions in Homebrew following the deprecation of the homebrew/versions tap and the adoption of the new formula@version format. It explains the background of this transition and demonstrates the primary method using the brew search command with practical examples. Additionally, it covers advanced techniques involving brew info --json combined with jq for precise version extraction. Based on highly-rated Stack Overflow answers and supplemented with in-depth technical analysis, the content offers developers practical operational guidance for effective version management.
Evolution of Homebrew's Version Management Mechanism
Homebrew, the widely-used package manager for macOS, has recently implemented significant changes to its version management system. The traditional homebrew/versions tap has been deprecated in favor of integrating versioned packages into the main homebrew/core repository using the new formula@version format. This change streamlines the repository structure but also alters how users query available versions.
Querying Available Versions with brew search
Under the new version management system, the brew search command serves as the primary tool for querying available versions. This command searches all available formulae, including versioned ones. For example, to check available PostgreSQL versions, execute:
brew search postgresqlThe output will display something like:
postgresql ✔ postgresql@9.4 postgresql@9.5Here, postgresql represents the latest stable version, while postgresql@9.4 and postgresql@9.5 are specific historical versions. This query method is straightforward and provides quick access to all installable versions.
Practical Application Scenarios for Version Queries
In real-world development, different projects may depend on specific package versions. For instance, a legacy project might require PostgreSQL 9.5 instead of the latest version. After confirming version 9.5 is available via brew search postgresql, you can install it using brew install postgresql@9.5. It's important to note that not all packages offer multiple versions; if a queried version doesn't exist, the system returns an "Error: No formulae found in taps" message.
Advanced Query Techniques: JSON Format Output
For users requiring precise version control, the brew info --json command combined with the jq tool enables advanced queries. The specific command format is:
brew info --json PACKAGE_NAME | jq -r '.[].versioned_formulae[]'Using Node.js as an example:
brew info --json node | jq -r '.[].versioned_formulae[]'This command outputs:
node@10
node@12
node@8This method accurately extracts the list of versioned formulae, making it particularly suitable for scripting scenarios. Note that the jq tool must be installed first (via brew install jq), and this technique only works with formulae, not casks.
Best Practices for Version Management
To enhance workflow efficiency, it's recommended to set up commonly used version query commands as shell aliases or functions. For example, add the following to ~/.bashrc or ~/.zshrc:
alias brew-versions='brew info --json $1 | jq -r ".[].versioned_formulae[]"'This allows quick queries like brew-versions node to check available Node.js versions. Additionally, regularly update the local formula index with brew update to ensure access to the latest version information.
Conclusion and Future Outlook
The evolution of Homebrew's version management mechanism reflects broader trends in package management. Although the new formula@version format changes query methods, tools like brew search and brew info --json enable efficient version management. As Homebrew continues to develop, more convenient version management features are expected to emerge, providing developers with an improved user experience.