LoginSignup
26

More than 5 years have passed since last update.

Homebrewでformulaを特定のバージョンに切り替える方法まとめ

Last updated at Posted at 2014-10-21

Homebrewでインストールしたfomulaはbrew upgradeすると最新のバージョンを引っ張ってきてくれますが、過去の特定のバージョンのformulaを使用したいときというのはままあります。

そこでHomebrewでバージョン違いのformulaをインストールする方法をまとめました。

参考:http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula

brew versionsコマンドを使う

brew versionsコマンドを使います。

$ brew versions autoconf
Warning: brew-versions is unsupported and will be removed soon.
You should use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions

2.69     git checkout b9926f1 /usr/local/Library/Formula/autoconf.rb
2.68     git checkout 023faf6 /usr/local/Library/Formula/autoconf.rb

Homebrewのformulaは通常/usr/local/Library/Formula/xxx.rbというスクリプトをもとにインストールをおこないますが、このスクリプトをチェックアウトして過去のバージョンに戻すということです。

autoconf-2.69が既にインストールされていて、2.68が欲しいとき、

$ brew unlink autoconf
Unlinking /usr/local/Cellar/autoconf/2.69... 21 symlinks removed
$ git checkout 023faf6 /usr/local/Library/Formula/autoconf.rb
$ brew install autoconf

という手順で過去のバージョンをインストールすることができます。

Warning

brew versionsコマンドはdeprecatedとなっていて、

$ brew versions autoconf
Warning: brew-versions is unsupported and will be removed soon.
You should use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions

と、実際にコマンドを走らせるとこのようなWarningが表示されます。
将来的に削除されるということなのでこのやり方は使わないのが賢明でしょう。

homebrew-versionsリポジトリをtapする

homebrew-versionsは、複数のバージョンを別々のformulaeとして提供しているリポジトリです。

$ brew search autoconf
autoconf      autoconf-archive
homebrew/versions/autoconf213   homebrew/versions/autoconf264

brew searchしたときにhomebrew/versions/...となっているformulaeがhomebrew-versionsに存在するformulaeです。
brew tapコマンドを使うことでリポジトリを追加することができます。

$ brew tap homebrew/versions
$ brew search autoconf
autoconf      autoconf-archive  autoconf213       autoconf264
$ brew install autoconf246

リポジトリを足さずにinstallすることもできます。

$ brew install homebrew/versions/autoconf246

Warning

homebrew-versionsのformulaは、上のようにバージョンを示すsuffixがつくので、/usr/local/bin/autoconf264のようにsuffixがついたままリンクが貼られてしまいます。

$ ls -la /usr/local/bin | grep autoconf
lrwxr-xr-x    1 xxthermidorxx  admin    42B 10 21 20:09 autoconf264 -> ../Cellar/autoconf264/2.64/bin/autoconf264
lrwxr-xr-x    1 xxthermidorxx  admin    44B 10 21 20:09 autoheader264 -> ../Cellar/autoconf264/2.64/bin/autoheader264
lrwxr-xr-x    1 xxthermidorxx  admin    42B 10 21 20:09 autom4te264 -> ../Cellar/autoconf264/2.64/bin/autom4te264
lrwxr-xr-x    1 xxthermidorxx  admin    44B 10 21 20:09 autoreconf264 -> ../Cellar/autoconf264/2.64/bin/autoreconf264
lrwxr-xr-x    1 xxthermidorxx  admin    42B 10 21 20:09 autoscan264 -> ../Cellar/autoconf264/2.64/bin/autoscan264
lrwxr-xr-x    1 xxthermidorxx  admin    44B 10 21 20:09 autoupdate264 -> ../Cellar/autoconf264/2.64/bin/autoupdate264
lrwxr-xr-x    1 xxthermidorxx  admin    41B 10 21 20:09 ifnames264 -> ../Cellar/autoconf264/2.64/bin/ifnames264

なので、自分でln -s /usr/local/bin/autoconf264 /usr/local/bin/autoconfのようにリンクを貼るなどするしかないと思われますが、
もしかしたら他にも上手いやり方があるかもしれません。

brew switchコマンドを使う

brew switchコマンドは外部コマンドなのでhelpには載っていませんが、バージョン切り替えのためにリンクの張り替えをおこなってくれます。

既にautoconfの2.68と2.69がローカルに存在する場合、

$ brew info autoconf
autoconf: stable 2.69 (bottled)
http://www.gnu.org/software/autoconf
/usr/local/Cellar/autoconf/2.68 (70 files, 4.0M)
  Built from source
/usr/local/Cellar/autoconf/2.69 (69 files, 2.0M) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/autoconf.rb

$ brew switch autoconf 2.68
Cleaning /usr/local/Cellar/autoconf/2.68
Cleaning /usr/local/Cellar/autoconf/2.69
23 links created for /usr/local/Cellar/autoconf/2.68

$ brew info autoconf
autoconf: stable 2.69 (bottled)
http://www.gnu.org/software/autoconf
/usr/local/Cellar/autoconf/2.68 (70 files, 4.0M) *
  Built from source
/usr/local/Cellar/autoconf/2.69 (69 files, 2.0M)
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/autoconf.rb

のようにしてバージョン切り替えをおこなうことができます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26