RVM和OpenSSL的问题

50

我尝试为同事设置新的MacBook。进展不顺利。

首先,我安装了OpenSSL:

Heathers-MacBook-Pro:~ heather$ rvm pkg install openssl
Fetching openssl-1.0.1c.tar.gz to /Users/heather/.rvm/archives
######################################################################## 100.0%
Extracting openssl to /Users/heather/.rvm/src/openssl-1.0.1c
Configuring openssl in /Users/heather/.rvm/src/openssl-1.0.1c.
Compiling openssl in /Users/heather/.rvm/src/openssl-1.0.1c.
Installing openssl to /Users/heather/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Updating openssl certificates

然后我尝试使用openssl安装ruby...

Heathers-MacBook-Pro:website heather$ rvm install 1.9.3 --with-openssl-dir=$HOME/.rvm/usr
Fetching yaml-0.1.4.tar.gz to /Users/heather/.rvm/archives
Extracting yaml to /Users/heather/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/heather/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/heather/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/heather/.rvm/usr
Installing Ruby from source to: /Users/heather/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)...
ruby-1.9.3-p392 - #downloading ruby-1.9.3-p392, this may take a while depending on your connection...
ruby-1.9.3-p392 - #extracting ruby-1.9.3-p392 to /Users/heather/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #extracted to /Users/heather/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #configuring
ruby-1.9.3-p392 - #compiling
ruby-1.9.3-p392 - #installing 
Removing old Rubygems files...
Installing rubygems-1.8.25 for ruby-1.9.3-p392 ...
Installation of rubygems completed successfully.
Saving wrappers to '/Users/heather/.rvm/bin'.
ruby-1.9.3-p392 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p392 - #importing default gemsets, this may take time ...
Install of ruby-1.9.3-p392 - #complete 

Heathers-MacBook-Pro:website heather$ bundle update
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for
compiling with OpenSSL using RVM are available at rvm.io/packages/openssl.

顺便说一下,gem文件中写着“source https://rubygems.org

有什么想法吗?

17个回答

87

OP 真的救了我的一天!在我的情况下:

$ rvm pkg install openssl
$ rvm remove 2.4
$ rvm install 2.4 --with-openssl-dir=$HOME/.rvm/usr
$ gem install bundler

2
事实证明,在Debian上你不需要安装libssl-dev,而是需要安装libssl1.0-dev。运行您的命令序列突出了这种差异并解决了我的问题,现在2.1.10已成功安装。谢谢。 - dimitarvp
1
在我的情况下,这是唯一有效的解决方案。我试图安装 Ruby 2.3.6,但在升级 homebrew 包 brew upgrade pyenv 和其他 brew 更新后,它崩溃了,而 brew list 显示了 openssl & openssl@1.1。那时我的问题开始了。 - lacostenycoder
在 Fedora 36 上为我解决了这个问题。 - Dmitrii Kharlamov
1
谢谢!针对使用 Ubuntu 22.04 的解决方案是因为它使用了 OpenSSL@3.0,而旧版本的 Ruby 不支持它。 - Santiago Ceron
谢谢!这对我很有帮助,在 Linux 升级(可能是 SSL 库)后,我不知道如何通过 RVM 安装。在找到你的解决方案之前,我搜索了一个多小时。你让我的一天变得美好! - sumskyi
显示剩余2条评论

26

ArchLinux维基百科中有很好的描述:

早于2.4版本的Ruby需要使用OpenSSL 1.0,但RVM将尝试使用OpenSSL 1.1进行构建。

因此,您可以执行以下操作(最简单):

$ rvm pkg install openssl
$ rvm reinstall 2.3.5 --with-openssl-dir=$HOME/.rvm/usr

你可以在ArchLinux维基上看到更多的解决方案。


你的命令中缺少一个破折号:--with-openssl-dir=... - Railsana
它对我起作用了。我想了解它是如何起作用的。有什么要注意的吗? - jaspreet21anand
@jaspreet21anand 我现在使用rbenv:https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F - noraj
你说rvm使用了错误的版本,但是你只指定了openssl目录。你怎么知道它会是1.0而不是1.1呢? - jaspreet21anand
仍然完美 - Ubuntu 22,ruby 2.3 - Alexey

21

试试这个:

rvm get head
rvm pkg remove
rvm requirements run  # if brew gives you warnings about formulas to install, run "brew install" for each before moving on.

rvm reinstall [the version you need (i.e: 2.0.0)]

3
一个澄清的评论 - 运行 "rvm requirements run" 会给你一堆缺失的 homebrew 公式。为每个公式运行 "brew install"。 - phil swenson
2
对我来说,在 rvm get head 上失败了,出现了 Error running 'command gem install /Users/daniellizik/.rvm/gem-cache/rvm-1.11.3.9.gem --local --no-document' 的错误... ERROR: Loading command: install (LoadError) cannot load such file -- openssl - Daniel Lizik
除了“rvm pkg remove”现在已过时之外,我在运行“rvm requirements run”并重新安装我想要的版本之前,使用了“rvm autolibs enabled”,所以现在一切都正常工作。 - Adail Retamal

21

使用Homebrew在macOS Mojave(10.14.2)上安装Ruby 2.2。

安装Homebrew

brew install openssl
rvm install 2.2 --with-openssl-dir=/usr/local/opt/openssl

不要使用rvm pkg,它已被弃用,请使用rvm autolibs enabled


并非每个人都能使用brew,rvm pkg也可以解决Linux上的openssl问题,而Homebrew通常未安装且不鼓励使用。由于没有替代方案,因此可以放心使用rvm pkg。 - Gabor Garami

17

这是我在Catalina上的Mac上安装rvm和ruby 2.3的步骤。安装的rvm版本是1.29.9。必须安装OpenSSL 1.0.2(降级)。请注意gpg命令中的“ipv4”。

gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable

请在https://www.openssl.org/source/下载 OpenSSL 1.0.2。

tar -xzf openssl-1.0.2t.tar.gz
cd openssl-1.0.2t
./Configure darwin64-x86_64-cc --prefix=/usr/local/opt/openssl@1.0
make
make test
sudo make install

rvm install 2.3.3 --with-openssl-dir=/usr/local/opt/openssl@1.0
ruby -v
ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'              
>> OpenSSL 1.0.2t  10 Sep 2019

我有不同的项目正在进行。使用以上注释的 2.3.3 版本项目正常运行。请问在 Catalina 上,对于 Ruby 2.5.3 和 Rails 5.2.1,应该添加哪个版本的 openssl 才合适? - Minal Soni
这也适用于在OSX 10.14 Mojave上运行的ruby <2.4! - RunsnbunsN
非常感谢您的精彩解释。在Mac OS Catalina上运行良好。 - Surendra Rathore
如果出于任何原因您需要多个 Ruby 和 Gemset,这绝对是最干净的解决方法(即使是 <2.4 这样“旧”的版本)。 - Pipetus

9
在MacOS 10.12.2上通过brew安装openssl将无法工作。要修复它,请运行:
export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/lib/pkgconfig

然后通过rvm安装Ruby。

编辑: 有关问题原因的更多信息在此处


这对于较旧版本的Ruby尤其重要,因为它们可能无法与较新版本的openssl(例如1.1)正常工作。此设置对于使rvm的--with-openssl-dir选项正常工作至关重要。 - mastaBlasta

7

对于在Mac Mojave上通过RVM使用openssl 1.1和Ruby 2.3遇到问题的用户,可以尝试以下命令。问题在于Ruby 2.3不兼容openssl 1.1。

rvm pkg install openssl
PKG_CONFIG_PATH=$HOME/.rvm/usr/lib/pkgconfig rvm reinstall 2.3.3 --with-openssl-dir=$HOME/.rvm/usr

6

以下是我所采用的方法:

brew install rbenv/tap/openssl@1.0
rvm reinstall 1.9.3-p551 --with-openssl-dir='/usr/local/opt/openssl@1.0'
gem update --system

干杯!


这对我在Catalina、rvm、ruby 2.1.9上有效。现在我的古老测试工具再次可用了! - Jon V

6

对于在 MacOS High Sierra 10.13.6 上的旧版 Ruby 2.2.10,我唯一可行的解决办法是:

  1. 切换到旧版本的 OpenSSL
brew switch openssl 1.0.2s
  1. 与其重新安装 Ruby,不如使用 --with-openssl-dir 选项
rvm reinstall 2.2.10 --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2s

2
谢谢!这有助于在High Sierra 10.13.6上安装旧版本的Ruby 2.3.0。否则新的openssl 1.1.x是不兼容的。 - rilian
1
我遇到的问题是,如果我没有通过brew安装openssl 1.0.x(来自古老的残留物),那么这些kegs就不存在了,因此您无法直接通过homebrew安装openssl 1.0.x。您必须先弄清楚如何通过homebrew安装openssl1.0.x。请参阅Chris Hobbs或hernan的答案。 - Jon V
非常感谢,这有助于我在macOS Catalina 10.15.4上运行旧的Ruby 2.2.7项目。 - dutchstrider

5

使用homebrew的Mac用户可以使用以下命令,这对我有效:

rvm install 2.7.7 --with-openssl-dir=$(brew --prefix openssl)/lib


在我的情况下(通过brew安装了多个openssl),它是openssl@1.1:“rvm install 3.2.0 --with-openssl-dir=$(brew --prefix openssl@1.1)/lib”。 - nazar kuliyev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接