おでーぶでおでーぶ

いろいろ書く。いろいろ。

Homebrewで特定バージョンのFormulaをインストールする

mongodb を 3.4.1 から 3.2.11 にしたかったのでやってみた。
homebrew-versionsはdeprecatedだし、あんまり使いたくないなーと思ってたので使わずに。

Env

brew -v
# Homebrew 1.1.8-64-gc507222                                                                    
# Homebrew/homebrew-core (git revision 35fb7; last commit 2017-01-29)

Workflow

# Try to find the commit id
brew log --author=brew-test-bot@googlegroups.com mongodb
# Search 3.2.11 and copy the commit id (COMMIT_ID_3_2_11)

# Move to formula manager
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

# Change the revision of the formula you wanna install
git checkout $COMMIT_ID_3_2_11 Formula/mongodb.rb

# Stop the service if needed
brew services stop mongodb

# Unlink the current formula
brew unlink mongodb

# Install the version you changed
brew install mongodb

# Check the installed formula
ls "$(brew --repo)../Cellar/mongodb/"

# Back to the latest commit
git reset -- Formula/mongodb.rb # To unstage the formula.
git checkout -- Formula/mongodb.rb

# Restart the service if needed
brew services start mongodb