使用 RVM 在 OSX 10.15.2 Catalina 中安装 Ruby 2.3.8 时出错;未找到 OpenSSL

Error installing Ruby 2.3.8 in OSX 10.15.2 Catalina using RVM; OpenSSL not found

错误

Error running 'env GEM_HOME=/Users/john/.rvm/gems/ruby-2.3.8@global

我在 MacOs Catalina 10.15.2

中尝试安装 ruby 2.3.8 时遇到此错误
$ rvm install 2.3.8


Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.15/x86_64/ruby-2.3.8.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/john/.rvm/rubies/ruby-2.3.8, this may take a while depending on your cpu(s)...
ruby-2.3.8 - #downloading ruby-2.3.8, this may take a while depending on your connection...
ruby-2.3.8 - #extracting ruby-2.3.8 to /Users/john/.rvm/src/ruby-2.3.8 - please wait
ruby-2.3.8 - #configuring - please wait
ruby-2.3.8 - #post-configuration - please wait
ruby-2.3.8 - #compiling - please wait
ruby-2.3.8 - #installing - please wait
ruby-2.3.8 - #making binaries executable - please wait
ruby-2.3.8 - #downloading rubygems-3.0.8
ruby-2.3.8 - #extracting rubygems-3.0.8 - please wait
ruby-2.3.8 - #removing old rubygems - please wait
ruby-2.3.8 - #installing rubygems-3.0.8 - please wait

Error running 'env GEM_HOME=/Users/john/.rvm/gems/ruby-2.3.8@global GEM_PATH= /Users/john/.rvm/rubies/ruby-2.3.8/bin/ruby -d /Users/john/.rvm/src/rubygems-3.0.8/setup.rb --no-document',

please read /Users/john/.rvm/log/1583757882_ruby-2.3.8/rubygems.install.log

日志输出

$ cat /Users/john/.rvm/log/1583757882_ruby-2.3.8/rubygems.install.log


...skipping...
Exception `LoadError' at /Users/john/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/rubygems.rb:1242 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/john/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/rubygems.rb:1251 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /Users/john/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- did_you_mean
/Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- openssl (LoadError)
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/specification.rb:2481:in `to_ruby'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/commands/setup_command.rb:405:in `install_default_bundler_gem'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/commands/setup_command.rb:167:in `execute'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/command.rb:321:in `invoke_with_build_args'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/command_manager.rb:184:in `process_args'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/command_manager.rb:148:in `run'
        from /Users/john/.rvm/src/rubygems-3.0.8/lib/rubygems/gem_runner.rb:59:in `run'
        from setup.rb:41:in `<main>'

要点是

`require': cannot load such file -- openssl (LoadError)

我试过了

深入挖掘,我发现 OSX 的较新版本已弃用 OpenSSL,导致许多依赖项被破坏。您需要重新安装 ruby,但要准确指定 OpenSSL 库的位置。如果您使用的是 RVM,那么它看起来像:

$ brew install openssl
$ rvm reinstall 2.3.8 --with-openssl-dir=`brew --prefix openssl`

但是没有成功,错误没有改变。

然后我试了

$ rvm reinstall 2.3.8 --rubygems 2.6.6 --with-openssl-dir=`brew --prefix openssl`


Error running '__rvm_with ruby-2.3.8@myapp gemset_pristine',
please read /Users/john/.rvm/log/1583758650_ruby-2.3.8/gemset.pristine-ruby-2.3.8@myapp

说,nokogiri 没有安装,

$ gem install nokogiri -v=1.10.4

ERROR:  While executing gem ... (Gem::Exception)
    Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

知道如何解决这个问题吗?

我尝试了一切,得出的结论是 ruby 2.3.8 RVM 的二进制文件有问题。我从我的系统中删除了 RVM 并开始使用 rbenv.

使用自制软件

$ brew install rbenv
$ rbenv init
# Do as it says
$ rbenv install 2.3.8

还要确保您使用了遗留代码 Gemfile.lock

中指定的 bundler

看起来旧 ruby 版本需要旧版本的 openSSL,并且必须使用指向 --with-openssl-dir

的版本进行构建

你可以试试这个:

brew install rbenv/tap/openssl@1.0

PKG_CONFIG_PATH=/usr/local/Cellar/openssl@1.0/1.0.2t/lib/pkgconfig \
rvm install 2.3.7 \
--with-openssl-dir=/usr/local/Cellar/openssl@1.0/1.0.2t \
--with-openssl-lib=/usr/local/Cellar/openssl@1.0/1.0.2t/lib \
--with-openssl-include=/usr/local/Cellar/openssl@1.0/1.0.2t/include --rubygems ignore

Copied from