Homebrew 安装旧版本软件包,macOS 安装特定版本软件包

Homebrew 安装旧版本软件包,macOS 安装特定版本软件包

mac OS中使用Homebrew安装软件包时,默认是安装最新稳定版本,有些情况下我们需要使用特定的历史版本软件包,此时我们通过以下方式来安装。

1. 搜索软件包可用版本

brew search

2. 安装历史版本

如上图所示,postgresql提供了历史版本,此时可以可以直接安装指定版本的包。如brew install postgresql@9.5jpeg则没有直接提供历史版本,我们可以通过以下方式安装其历史版本。

brew info

通过上图可以看到Homebrew安装jpeg使用是https://github.com/Homebrew/homebrew-core/blob/master/Formula/jpeg.rb文件。那我们就可以在Github提交历史记录中找到该文件特定历史版本进行软件包安装即可,思路清楚之后下面来逐步执行。

Github历史版本

如上图所示,直接访问jpeg的安装源文件时可以看到当前版本为9c。点击History查看该文件提交历史记录。

Github版本

由于homebrew-core库较大无法直接列出其提交历史记录,按照提示我们可以clone库到本地后再搜索其提交记录。

git clone https://github.com/Homebrew/homebrew-core.git
cd homebrew-core
git log master -- Formula/jpeg.rb

Git log

根据实际情况选择特定版本的历史提交记录,如这里我们选择jpeg 8d的最后一次提交,访问该commit的安装文件https://github.com/Homebrew/homebrew-core/blob/b23146936a3abb57aabb39017561e7b0c750abbf/Formula/jpeg.rb,如下图所示可以看到jpeg版本为8d。点击Raw获取其原始文件URL并安装。

旧版本提交记录

安装旧版本 至此,brew安装特定版本的软件包就成功完成了。

3. 多版本切换

使用brew info package可以查看软件包的安装版本,如:

brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb

使用brew switch package version可以切换软件包版本。如:

brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5

切换完成后可以再次查看确认。

brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb

*项表示当前使用的版本。