6

我安装了 rbenv 并尝试按照此处的说明在 Debian 9 上安装 ruby​​ 1.9.3 https://github.com/rbenv/ruby-build/wiki

Debian 上的 OpenSSL 绑定
由于 Debian(7.5 及更高版本)中的 OpenSSL 不兼容,Ruby 可能无法在不先打补丁的情况下编译:

curl -fsSL https://github.com/ruby/ruby/commit/1e7a929c1d44d7a368fbe379211183ac6c972920.patch | \
rbenv install --patch 1.9.3-p484

我得到的回应是

Installing ruby-1.9.3-p484...
patching file ChangeLog
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file ChangeLog.rej
patching file ext/openssl/ossl_ssl.c
Hunk #1 succeeded at 1985 (offset -244 lines).

BUILD FAILED (Debian 9.4 using ruby-build 20160913)

好吧,对于 ruby​​ 的工作或当然不需要更改日志中的更改。然后我发现了这个https://github.com/mathbruyen/computers/blob/master/computers/AspireOne.md

curl -fsSL https://github.com/ruby/ruby/commit/1e7a929c1d44d7a368fbe379211183ac6c972920.patch | filterdiff --strip=1 -i a/ext/openssl/ossl_ssl.c | rbenv install -p 1.9.3-p484

从中我能够找到一种仅将大块应用于 OpenSSL 相关文件的方法。Filterdiff 可以安装在 Debian 上:apt install patchutils.
安装 Ruby 1.9.3-p484 的结果

BUILD FAILED (Debian 9.4 using ruby-build 20160913)

Inspect or clean up the working tree at /tmp/ruby-build.4890
Results logged to /tmp/ruby-build.4890.log

Last 10 log lines:
     ossl_ssl_def_const(OP_ALL);
     ^~~~~~~~~~~~~~~~~~
Makefile:269: recipe for target 'ossl_ssl.o' failed
make[2]: *** [ossl_ssl.o] Error 1
make[2]: Leaving directory '/tmp/ruby-build.4890/ruby-1.9.3-p484/ext/openssl'
exts.mk:126: recipe for target 'ext/openssl/all' failed
make[1]: *** [ext/openssl/all] Error 2
make[1]: Leaving directory '/tmp/ruby-build.4890/ruby-1.9.3-p484'
uncommon.mk:178: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2

现在我注意到仍然存在与 openssl 相关的错误。所以我尝试了另一个 libssl-dev-package:

sudo apt install libssl-dev

现在安装 ruby​​ 1.9.3-p484 没有错误,太棒了!!但是即使安装现在没有错误,openssl 在 ruby​​ 中仍然不可用。

user@debian:~$ rbenv rehash
user@debian:~$ rbenv versions
  system
  1.9.3-p484
user@debian:~$ rbenv local 1.9.3-p484
user@debian:~$ irb
irb(main):001:0> require 'openssl'
LoadError: cannot load such file -- openssl
        from /home/user/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/user/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from (irb):1
        from /home/user/.rbenv/versions/1.9.3-p484/bin/irb:12:in `<main>'
irb(main):002:0>

编辑: 对于 ruby​​ 1.9.3-p484,它在日志中说:

Failed to configure openssl. It will not be installed.

这就是安装成功但 openssl 无法正常工作的原因。在日志中寻找“错误”一词,我还发现“错误:'SSLv3_method' undeclared”,它已在单独的补丁中修复。

Wiki 还说以下所有内容:

Ruby 2.4 之前版本的 openssl 扩展与 OpenSSL 1.1.x 不兼容。目前,大多数带有 OpenSSL 1.1.0 的 Linux 发行版都有一个单独的 OpenSSL 1.0.x 包。

在 Debian 9 (stretch) 上,它是 libssl1.0-dev(注意安装它会删除 libssl-dev)。

OpenSSL “SSLv3_method undeclared” 错误
对于较旧的 Ruby 版本,如 1.9.3,上述补丁将不起作用,请改用:

curl -fsSL https://gist.github.com/FiveYellowMice/c50490693d47577cfe7e6ac9fc3bf6cf.txt | \
 rbenv install --patch 1.9.3-p551

所以,在我的设置中,有效的步骤是:
1. sudo apt install libssl1.0-dev
2. curl -fsSL https://gist.github.com/FiveYellowMice/c50490693d47577cfe7e6ac9fc3bf6cf.txt | rbenv install --patch 1.9.3-p551

现在它工作正常:

user@debian:~$ rbenv rehash
user@debian:~$ rbenv versions
  system
* 1.9.3-p484 (set by /home/user/.ruby-version)
  1.9.3-p551
user@debian:~$ rbenv local 1.9.3-p551
user@debian:~$ irb
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0>

希望这会对某人有所帮助!

4

0 回答 0