LoginSignup
113
73

More than 5 years have passed since last update.

Homebrewで旧バージョンのパッケージをインストールしたい

Last updated at Posted at 2016-11-16

はじめに

Homebrewを使ってインストールしたパッケージで、旧バージョンのパッケージを利用したい場合に少々面倒だったのでメモを残します。

前提

Homebrewのバージョン1.0.0で、インストール先やディレクトリ構成が変わりました。
以前の構成での旧バージョンのインストールについて書かれている記事はありますが、大変参考にさせてもらいつつ現在のバージョンにあった形で書かせていただきました。

この記事はHomebrewのバージョン1.1.0の時点で書かれています。(※1.3.1でも確認&更新済)
また、古いprotobufのインストールを行うことを目的にしています。

ローカルに旧バージョンがある場合

brew infoで確認できます。

$ brew info protobuf
protobuf: stable 3.1.0 (bottled), HEAD
Protocol buffers (Google's data interchange format)
https://github.com/google/protobuf/
/usr/local/Cellar/protobuf/3.0.2 (250 files, 15.8M)
  Poured from bottle on 2016-11-16 at 21:33:15
/usr/local/Cellar/protobuf/3.1.0 (253 files, 16M) *
  Poured from bottle on 2016-11-16 at 21:32:14
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/protobuf.rb
==> Dependencies
Build: autoconf ✔, automake ✔, libtool ✔
==> Options
--c++11
    Build using C++11 mode
--universal
    Build a universal binary
--with-test
    Run build-time check
--without-python
    Build without python support
--HEAD
    Install HEAD version
==> Caveats
Editor support and examples have been installed to:
  /usr/local/Cellar/protobuf/3.1.0/share/doc/protobuf

*印のものが現在利用しているバージョンです。
brew switchでバージョンの切り替えが可能です。

$ brew switch protobuf 3.0.2
Cleaning /usr/local/Cellar/protobuf/3.0.2
Cleaning /usr/local/Cellar/protobuf/3.1.0
15 links created for /usr/local/Cellar/protobuf/3.0.2

ローカルに旧バージョンがない場合

Formulaのバージョンを遡ってインストールします。
まずhomebrew-core/Formulaに移動します。

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula

コミットログを確認します。

$ git log protobuf.rb

目的のバージョンのコミットを探します。例えばprotobuf2.6.1をインストールしたい場合。

commit a7df562c5f84dc26218055fc5a7bbcc839c17319
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Sun Apr 17 13:40:27 2016 +0100

    protobuf: update 2.6.1 bottle.

上記のログがそれっぽいので、チェックアウトします。

$ git checkout a7df562c5f84dc26218055fc5a7bbcc839c17319 protobuf.rb

インストールの前に、現在のパッケージをunlinkしておきます。

$ brew unlink protobuf
Unlinking /usr/local/Cellar/protobuf/3.0.2... 15 symlinks removed

パッケージをinstallします。
HOMEBREW_NO_AUTO_UPDATE1を設定しないと、勝手にhomebrewがアップデートしてしまって古いバージョンのパッケージをインストールすることができません。詳しくはこちら

$ HOMEBREW_NO_AUTO_UPDATE=1 brew install protobuf
==> Downloading https://homebrew.bintray.com/bottles/protobuf-2.6.1.el_capitan.bottle.5.tar.gz
######################################################################## 100.0%
==> Pouring protobuf-2.6.1.el_capitan.bottle.5.tar.gz
==> Caveats
Editor support and examples have been installed to:
  /usr/local/Cellar/protobuf/2.6.1/share/doc/protobuf
==> Summary
🍺  /usr/local/Cellar/protobuf/2.6.1: 121 files, 6.8M

うまく行ったらバージョンを確認。

$ protoc --version
libprotoc 2.6.1

Formulaのバージョンはもとに戻しておきます。

$ git reset --hard
HEAD is now at af33827 mlt: update 6.4.1 bottle.

バージョンを戻したい場合はbrew switchを使います。

$ brew switch protobuf 3.1.0
Cleaning /usr/local/Cellar/protobuf/2.6.1
Cleaning /usr/local/Cellar/protobuf/3.0.2
Cleaning /usr/local/Cellar/protobuf/3.1.0
15 links created for /usr/local/Cellar/protobuf/3.1.0

参考にさせてもらった記事

Homebrewで旧バージョンをインストールする方法(brew verionsはもう使えない)

113
73
0

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
113
73