以安装apache-flink为例展开说明。

0x00 查看软件包安装来源

1
brew inso apache-flink

执行上面命令,我们得到如下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apache-flink: stable 1.15.0 (bottled), HEAD
Scalable batch and stream data processing
https://flink.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/apache-flink.rb
License: Apache-2.0
==> Dependencies
Required: openjdk@11
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 634 (30 days), 1,501 (90 days), 5,931 (365 days)
install-on-request: 634 (30 days), 1,504 (90 days), 5,926 (365 days)
build-error: 0 (30 days)

其中https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/apache-flink.rb以及apache-flink: stable 1.15.0 (bottled)这两条信息,这说明现在的apache-flink的版本是1.15.0,安装文件为.rb的文件。

brew的安装库是通过github托管的,那么一定是有提交信息可查询的。

0x01 在github中查看rb文件的提交版本信息

复制https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/apache-flink.rb在浏览器中,打开github提交页面,我们看到如下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class ApacheFlink < Formula
desc "Scalable batch and stream data processing"
homepage "https://flink.apache.org/"
url "https://www.apache.org/dyn/closer.lua?path=flink/flink-1.15.1/flink-1.15.1-bin-scala_2.12.tgz"
mirror "https://archive.apache.org/dist/flink/flink-1.15.1/flink-1.15.1-bin-scala_2.12.tgz"
version "1.15.1"
sha256 "9213f9e4bb087cbc6d3c9ab4ac4215fab4199bbfabf0a09f3c138f216d854c5b"
license "Apache-2.0"
head "https://github.com/apache/flink.git", branch: "master"

bottle do
sha256 cellar: :any_skip_relocation, all: "9a062793325af350899b8c96ed6302bb911019100a080c96e63074e73970769c"
end

depends_on "openjdk@11"

def install
rm_f Dir["bin/*.bat"]
libexec.install Dir["*"]
(libexec/"bin").env_script_all_files(libexec/"libexec", Language::Java.java_home_env("11"))
(libexec/"bin").install Dir["#{libexec}/libexec/*.jar"]
chmod 0755, Dir["#{libexec}/bin/*"]
bin.write_exec_script "#{libexec}/bin/flink"
end

test do
(testpath/"log").mkpath
(testpath/"input").write "foo bar foobar"
expected = <<~EOS
(foo,1)
(bar,1)
(foobar,1)
EOS
ENV.prepend "_JAVA_OPTIONS", "-Djava.io.tmpdir=#{testpath}"
ENV.prepend "FLINK_LOG_DIR", testpath/"log"
system libexec/"bin/start-cluster.sh"
system bin/"flink", "run", "-p", "1",
libexec/"examples/streaming/WordCount.jar", "--input", testpath/"input",
"--output", testpath/"result"
system libexec/"bin/stop-cluster.sh"
assert_predicate testpath/"result", :exist?
result_files = Dir[testpath/"result/*/*"]
assert_equal 1, result_files.length
assert_equal expected, (testpath/result_files.first).read
end
end

可以看到当前的版本为1.15.1

  1. 点击History: 查看历史提交列表
    Github History
  2. 查找apache-flink 1.14.4
  3. 点击 View:查看当前版本下的 apache-flink.rb完整文件
    Github History View
  4. 复制链接:浏览器当前的链接就是对应版本的安装链接。

https://github.com/Homebrew/homebrew-core/blob/3715b837cea78e8478433c2c9358d09e8190fe49/Formula/apache-flink.rb

1
brew install https://github.com/Homebrew/homebrew-core/blob/3715b837cea78e8478433c2c9358d09e8190fe49/Formula/apache-flink.rb

0x03 错误问题处理

Error: Non-checksummed download of apache-flink formula file from an arbitrary URL is unsupported! brew extract or brew create and brew tap-new to create a formula file in a tap on GitHub instead.

安装过程中出现如上的错误提示。解决方式如下:

1
2
touch apache-flink.rb
open -e apache-flink.rb

打开上面的链接,复制内容并粘贴到apache-flink.rb中保存,然后再次安装

1
brew install apache-flink.rb

如果再次出现其他错误,继续解决:

1
2
3
4
5
6
7
8
9
10
11
12
Error: Couldn't find manifest matching bottle checksum.
/usr/local/Homebrew/Library/Homebrew/software_spec.rb:399:in `github_packages_manifest_resource_tab'
/usr/local/Homebrew/Library/Homebrew/software_spec.rb:352:in `fetch_tab'
/usr/local/Homebrew/Library/Homebrew/software_spec.rb:322:in `rescue in fetch'
/usr/local/Homebrew/Library/Homebrew/software_spec.rb:317:in `fetch'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:1182:in `fetch'
/usr/local/Homebrew/Library/Homebrew/install.rb:305:in `block in install_formulae'
/usr/local/Homebrew/Library/Homebrew/install.rb:278:in `map'
/usr/local/Homebrew/Library/Homebrew/install.rb:278:in `install_formulae'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:222:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:93:in `<main>'