• SIS Lab
    • >
    • Blog
    • >
    • Homebrewで過去バージョンのパッケージをインストールする方法

Homebrewで過去バージョンのパッケージをインストールする方法

更新日:2021.01.30 作成日:2019.12.03

Homebrewで入れたHugoを、「brew upgrade hugo」でv0.60.1にアップグレードしたところ、まともにビルドできなくなってしまった。これでは困ると思い、前のバージョンをインストールしようと思ったがやり方が分からなかったので、調べてみました。

まず試してみたのは、「brew install [email protected]」とバージョン指定してインストールを試みましたがダメ・・・。

諦めてちゃんと調べてみると、下記の方法で過去バージョンをインストールできることがわかりました。

1. まずはbrew info hugoで状況を確認する

$ brew info hugo
hugo: stable 0.60.1 (bottled), HEAD
Configurable static site generator
https://gohugo.io/
/usr/local/Cellar/hugo/0.58.3 (41 files, 57.8MB)
  Poured from bottle on 2019-12-03 at 21:20:38
/usr/local/Cellar/hugo/0.60.1 (41 files, 67.6MB) *
  Poured from bottle on 2019-12-03 at 21:14:47
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/hugo.rb
==> Dependencies
Build: go ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 20,043 (30 days), 64,846 (90 days), 207,747 (365 days)
install-on-request: 19,478 (30 days), 62,833 (90 days), 199,830 (365 days)
build-error: 0 (30 days)

2. 過去のバージョンが残っているのであれば、brew switchで切り替え可能

brew install hugoなどで最新版のバージョンと一緒に過去バージョンを残している場合は、brew switch hugo {version}でバージョンの切り替えが可能です。

$ brew switch hugo 0.58.3
Cleaning /usr/local/Cellar/hugo/0.60.1
Cleaning /usr/local/Cellar/hugo/0.58.3
37 links created for /usr/local/Cellar/hugo/0.58.3
$ brew info hugo
hugo: stable 0.60.1 (bottled), HEAD
Configurable static site generator
https://gohugo.io/
/usr/local/Cellar/hugo/0.58.3 (41 files, 57.8MB) *
  Poured from bottle on 2019-12-03 at 21:20:38
/usr/local/Cellar/hugo/0.60.1 (41 files, 67.6MB)
  Poured from bottle on 2019-12-03 at 21:14:47
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/hugo.rb
==> Dependencies
Build: go ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 20,043 (30 days), 64,846 (90 days), 207,747 (365 days)
install-on-request: 19,478 (30 days), 62,833 (90 days), 199,830 (365 days)
build-error: 0 (30 days)
$ hugo version
Hugo Static Site Generator v0.58.3/extended darwin/amd64 BuildDate: unknown

これで、*マークがついているバージョンに切り替わりました。

3. 最新版のバージョンしかない場合はFormulaのファイルをgit checkoutで対象のバージョンに戻す

新規インストールした場合、もしくはbrew upgrade hugoなどで既存のパッケージを上書きしてしまった場合などはこの状況になる可能性が高いです。私もこのパターンでした。

まずは以下の通り、Formulaファイル格納場所へ移動し、対象のライブラリ(ここではhugo.rb)の任意のバージョンのコミットハッシュ値を調べます。

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
$ git log hugo.rb
...
...
commit 1eb598bac6dbd3e9234e50d7ab208074f5fcaac8
Author: BrewTestBot <[email protected]>
Date:   Sat Sep 28 22:21:54 2019 +0000

    hugo: update 0.58.3 bottle.
...
...
git checkout 1eb598bac6dbd3e9234e50d7ab208074f5fcaac8 hugo.rb

この状態で、以下の通り再びHugoをインストールする。

$ brew install hugo

*怒られた場合はbrew unlink hugoします。

$ hugo version
Hugo Static Site Generator v0.58.3/extended darwin/amd64 BuildDate: unknown

任意のバージョンに変更されていることを確認した後は、変更したhugo.rbを元に戻しておきます。

$ git reset --hard

4. 番外編

公式ドキュメントを確認すると、以下の通り対象バージョンのFormuraを指定して直接インストールできるようです。

Installing directly from pull requests You can browse pull requests and install through their direct link. For example, Python 3.7.0 from pull request Homebrew/homebrew-core#29490:
$ brew install https://raw.githubusercontent.com/sashkab/homebrew-core/176823eb82ee1b5ce55a91e5e1bf2f50aa674092/Formula/python.rb

1.https://github.com/Homebrew/homebrew-core/ から、hugo.rbを探す。2.そのHistoryを確認し、対象となるコミット時のrawを取得する。3.以下のコマンドを叩くことで、同じ結果が得られました。

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1eb598bac6dbd3e9234e50d7ab208074f5fcaac8/Formula/hugo.rb

参考

B! Pocket

Related contents

TECH

2019.10.11

AMPページの最適化〜ぼくのAMPサイトがこんなに遅い訳がない〜

TECH

2019.10.06

AMP向けのミニマルCSSフレームワーク「1BX」をHugoに導入した

TECH

2023.02.03

Hugo v0.109.0でパンくずリストをシンプルに実装する

TECH

2022.09.03

【Hugo】Render Hooks for Code Blocksを利用してコードブロックにファイル名を表示する

TECH

2022.08.29

Hugoでブログカードを作成する(resources.GetRemote利用)

TECH

2022.08.14

GitHub PagesからCloudflare Pagesへの移行

TECH

2022.06.29

AMP Service WorkerでPrefetch Linksを実現する

TECH

2021.02.11

Git pre-commitフックでFrontmatterの「更新日時」を自動更新する