Why Was ‘brew switch’ Removed as a Subcommand?

Why Was ‘brew switch’ Removed as a Subcommand?

Homebrew, a widely used package manager for macOS, introduced significant changes in its version 2.0.0 release, which was released in December 2018. Among these changes was the removal of the brew switch command. This article explores the reasons behind the removal of this command and how Homebrew's package management capabilities have evolved since.

Background and Purpose of brew switch

Before the removal of brew switch, this command was primarily used to switch between different versions of a formula that a user had installed. For instance, if a user had multiple versions of Node.js installed, they could use brew switch node 11.15.0 to activate the specific version they wanted to use.

Evolution of Homebrew's Package Management Capabilities

The decision to remove brew switch was driven by several factors, with homebrew's evolving package management capabilities being the primary one. Homebrew introduced more robust mechanisms for handling versions, primarily through the combination of the brew link and brew unlink commands, coupled with the use of versioned formulae.

Version Management with brew link and brew unlink

The introduction of brew link and brew unlink commands offered a more intuitive way to manage multiple versions of a formula. With these commands, users could switch between different versions of a formula without the need for the brew switch command. For example, to link a specific version of a formula, one could use:

brew link --force /path/to/formula-version

Meanwhile, to unlink a version, one would use:

brew unlink formula

Versioned Formulae in Homebrew

Another major change was the adoption of versioned formulae, which are installed with version suffixes, such as These versioned formulae are designed to coexist with other acceptable versions, making the package manager more flexible and user-friendly. The main formula, for example, , has its files linked into the Homebrew hierarchy, while other versions remain keg-only and are installed in their own directories. These directories can be accessed via the default /usr/local/opt/formula symlinks, such as /usr/local/opt//bin/node.

Homebrew's "Single Version Policy"

In line with these changes, Homebrew adopted a "single version of each formula" policy, allowing a limited number of acceptable versions to coexist as top-level formulae with version suffixes. This policy simplified the overall interface and led to a more structured and user-friendly process for managing package versions.

Dispelling the Need for brew switch

With the introduction of these new mechanisms, the sole purpose of brew switch was no longer necessary. The removal of this command thus streamlined the functionality of Homebrew and encouraged users to rely on the official, versioned formulae rather than switching between multiple installed versions of the same formula.

Managing Multiple Versions with Node.js and Python

For users seeking to manage multiple versions of certain packages such as Node.js or Python, Homebrew now recommends the use of tools like:

brew install for specific version installations. Using third-party version managers specifically for handling multiple versions, such as Docker for Node.js or Python virtual environments.

These alternative methods provide more control and flexibility, aligning with the evolving capabilities of Homebrew and ensuring a better user experience.

Conclusion

The removal of brew switch was a result of Homebrew's continuous evolution towards a more streamlined, user-friendly, and robust package management system. By integrating advanced version management and versioned formulae, Homebrew has addressed the need for a command like brew switch, simplifying the overall functionality for users.