How to Pin an Homebrew Dependency
Sometime you need to pin a dependency to a specific version, but if the dependency has not all the version listed it can be tricky.
The formula
Homebrew knows how to install packages by looking at the package formula
. A formula
is is a package definition, written in Ruby.
Formulas for packages are located in the homebrew-core repository; so if you want to look at the information for a formula (for example wget
) you can simply go in the repository and look at the formula definition.
In there you can find all the info for the package like dependencies, how to install it, if there are precompiled binaries (called bottles) already available for the operating system brew
is running on.
Pin a package to a version
To pin a package (locking it to a specific version) you can use the pin
subcommandto prevent Homebrew from updating. From the command line, you can write (using again wget
as example:
brew pin wget
After this, Homebrew will not update the wget
package unless you remove the pin, thus preventing unwanted updates.
Unpin a package
After a package is pinned Homebrew prevents it from being upgrade. Usually you want to prevent updates for a limited amount of time and update it at a later time.
To update a pinned package you will need to use the unpin
command; this instructs Homebrew to remove the lock on the version of the package and treat it as a normal package.
Bonus: Install (and pin) a specific version of a package
Write about how to install a version:
- by using
brew install [email protected]
- by downloading and older version of a formula from GitHub
How to update
To update our pinned formula we need to remove the lock that fixes the version. It is only a matter of running brew unpin wget
(continuing to use wget
as example).
Now we can run our usual brew install [email protected]
to update to the newer desired version and the run brew pin wget
again.