Help us understand the problem. What is going on with this article?

[2018/10]homebrewで過去バージョンのパッケージをインストールする

More than 1 year has passed since last update.

環境

macOS : High Sierra 10.13.6
Xcode : Version 10.0 (10A255)

手順

ローカルのFomulaのディレクトリに移動。

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

Terminalで現在インストールされているバージョンを確認。
*がついているのが今動いているバージョン。

$ brew info jpeg
jpeg: stable 8d
Image manipulation library
http://www.ijg.org
/usr/local/Cellar/jpeg/8d (20 files, 734.6KB)
  Built from source on 2018-10-10 at 11:11:05
/usr/local/Cellar/jpeg/9c (21 files, 724.5KB) *
  Poured from bottle on 2018-10-09 at 19:17:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/jpeg.rb
==> Options
--universal
    Build a universal binary
==> Analytics
install: 113,600 (30d), 535,050 (90d), 1,663,212 (365d)
install_on_request: 5,734 (30d), 31,458 (90d), 82,705 (365d)
build_error: 9 (30d)

A. 動かしたい過去バージョンが既にある場合

brew switchでいける。

$ brew switch jpeg 8d
Cleaning /usr/local/Cellar/jpeg/9c
Cleaning /usr/local/Cellar/jpeg/8d
17 links created for /usr/local/Cellar/jpeg/8d

B. 過去バージョンがない場合

git logで必要なバージョンのコミットを探す。
[q]キーで閲覧状態をエスケープ。

$ git log jpeg.rb
commit ae184c6fe491b63ab7624061f4078a1a2e9db3cd
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Wed Aug 15 21:51:17 2018 +0000

    jpeg: update 9c bottle.

commit 299fc3de1d9bcc4f04c303f0a0cec9921e4e2e8c
Author: Viktor Szakats <commit@vszakats.net>
Date:   Mon Jul 30 12:11:24 2018 +0000

    jpeg: secure/fix url(s)

commit a70cad368bc5a14be037d24018ec9114d6b32f90
Author: ilovezfs <ilovezfs@icloud.com>
Date:   Mon Jul 9 13:57:38 2018 +0100

    jpeg: mirror to Bintray and use Bintray as primary (#29885)

    also add fossies mirror

.
.
.

対象のものをcheckoutする

$ git checkout 7f16e5aa9451ea391cbb7822a59d2bf702c5b834 jpeg.rb

そしてinstall

$brew install jpeg

既に現行バージョンがはいってるよ、と言われるので縁を切る。

$ brew install jpeg
Error: jpeg 9c is already installed
To install 8d, first run `brew unlink jpeg`

$brew unlink jpeg
Unlinking /usr/local/Cellar/jpeg/9c symlinks removed

改めてbrew installで完了。

$brew install jpeg

brew infoで確認。

$ brew info jpeg
jpeg: stable 8d
Image manipulation library
http://www.ijg.org
/usr/local/Cellar/jpeg/8d (20 files, 734.6KB) *
  Built from source on 2018-10-10 at 11:11:05
/usr/local/Cellar/jpeg/9c (21 files, 724.5KB)
  Poured from bottle on 2018-10-09 at 19:17:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/jpeg.rb
==> Options
--universal
    Build a universal binary
==> Analytics
install: 115,661 (30d), 535,050 (90d), 1,663,212 (365d)
install_on_request: 5,859 (30d), 31,458 (90d), 82,705 (365d)
build_error: 3 (30d)

一度インストールをしていればbrew switchで好きなバージョンに簡単に切り替えられる。

$ brew switch jpeg 9c
Cleaning /usr/local/Cellar/jpeg/9c
Cleaning /usr/local/Cellar/jpeg/8d
18 links created for /usr/local/Cellar/jpeg/9c
nagahora-2:Formula nagahora$ brew info jpeg
jpeg: stable 8d
Image manipulation library
http://www.ijg.org
/usr/local/Cellar/jpeg/8d (20 files, 734.6KB)
  Built from source on 2018-10-10 at 11:11:05
/usr/local/Cellar/jpeg/9c (21 files, 724.5KB) *
  Poured from bottle on 2018-10-09 at 19:17:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/jpeg.rb
==> Options
--universal
    Build a universal binary
==> Analytics
install: 115,661 (30d), 535,050 (90d), 1,663,212 (365d)
install_on_request: 5,859 (30d), 31,458 (90d), 82,705 (365d)
build_error: 3 (30d)

参考

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

nghryuki
デロリアンが好きだ。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away