LoginSignup
12
9

More than 5 years have passed since last update.

【Homebrew】旧バージョンのFormulaでbrew installする

Last updated at Posted at 2018-03-10

普段Rubyで開発を行っているが、別言語の開発環境を一時的に作る必要があり、
その際にbrew upgradeとかHomebrew周りのコマンドをたくさん打った。
その後、自分のRailsプロジェクトを弄ろうと思ったらこんなエラーが出た。

$ rails s

/Users/hogehoge/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require': dlopen(/Users/hogehoge/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-16/2.1.0-static/charlock_holmes-0.7.3/charlock_holmes/charlock_holmes.bundle, 9): Library not loaded: /usr/local/opt/icu4c/lib/libicudata.57.1.dylib (LoadError)
  Referenced from: /Users/hogehoge/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-16/2.1.0-static/charlock_holmes-0.7.3/charlock_holmes/charlock_holmes.bundle
  Reason: image not found - /Users/hogehoge/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-16/2.1.0-static/charlock_holmes-0.7.3/charlock_holmes/charlock_holmes.bundle

なんかLibrary not loadedでicu4cの57.1がないって言ってる。

とりあえずbrew info icu4cで今のバージョンを見てみると、60.2が入っていた。
これをダウングレードすればいけそう...?

1.brew log icu4cで過去のコミットから辿れないか見てみる

commit d976c0e4f2d3b977f5b9d7cf5995af1d0f687859
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Fri Oct 27 14:52:45 2017 +0000

    icu4c: update 59.1_1 bottle.

59.1_1までしかコミットログがない。Homebrewの仕様で全部のコミットは取ってきていないらしい。
(https://github.com/Homebrew/install/pull/8)

2.Formulaのあるディレクトリに移動して過去のコミットを取得する

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

これでHomebrewの全コミットが取得できたので、目当てのバージョンのicu4cのコミットを探す。

3.必要なバージョンのコミットの状態にgit check outする

$ brew log icu4c --oneline | grep 57.1
$ git checkout <ハッシュ値> icu4c.rb

必要なバージョンのコミットのハッシュ値を手動でもgrepでもなんでも良いので取ってくる。
取れたら、そのハッシュ値を使ってgit checkoutで欲しいバージョンのあるコミットの状態まで戻す。

4. 改めてbrew installする

今入っているバージョンのicu4cは必要ないのでアンインストールする。

$ brew uninstall icu4c

最新版を勝手にインストールされないように、オプションをつけて、icu4cを再インストールする。

$ HOMEBREW_NO_AUTO_UPDATE=1 brew install icu4c

インストール後、icu4cのバージョンを念のため確認


$ brew info icu4c
icu4c: stable 57.1, HEAD [keg-only]

57.1が入っている...!
その後rails sしたらエラーなく起動ができました。
最後にgit reset HEADで巻き戻した分を元に戻してひとまず終了です。

12
9
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
12
9