【问题标题】:Setup RVM, Ruby on Mac OS X Sierra: Unable to require openssl在 Mac OS X Sierra 上设置 RVM、Ruby:无法要求 openssl
【发布时间】:2020-04-23 14:53:17
【问题描述】:

我遇到了在新 Mac 笔记本电脑上设置 RVM + Rubies 的问题,在安装 RVM 和 Homebrew 后,安装 Rails 时遇到错误:

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

背景与环境

  • Mac OS X 10.12.3。 (塞拉)
  • 自制 1.1.8。安装了 OpenSSL
  • RVM 1.28.0
  • Ruby 2.3.3 Rails(尝试安装最新版本)
  • 环境变量(在OpenSSL crate fails compilation on Mac OS X 10.11之后)Shell环境中已设置以下变量
  • LDFLAGS = -L/usr/local/opt/openssl@1.1/lib
  • CPPFLAGS = -I/usr/local/opt/openssl@1.1/include
  • PKG_CONFIG_PATH = /usr/local/opt/openssl@1.1/lib/pkgconfig

发现与故障诊断

从一台干净的笔记本电脑开始,我按照通常的路径安装 Homebrew、Xcode 命令行工具、MySQL(用于 Rails 开发)、Git,然后是 RVM。即使设置了环境变量并卸载和重建 RVM,在 Homebrew 中删除和重新添加 OpenSSL,在尝试安装 Rails 时,我还是收到了错误:

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

另一个需要注意的是,在安装 RVM 时,我确保 RVM 知道 Homebrew:

rvm autolibs enable
ram autolibs homebrew

安装 ruby​​-2.3.3 的输出如下:

Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/osx/10.12/x86_64/ruby-2.3.3.tar.bz2
Checking requirements for osx_brew.
Updating Homebrew...
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
ruby-2.3.3 - #configure
ruby-2.3.3 - #download
ruby-2.3.3 - #validate archive
ruby-2.3.3 - #extract
ruby-2.3.3 - #validate binary
Libraries missing for ruby-2.3.3: /Users/travis/.rvm/rubies/ruby-2.3.3/lib/libruby.2.3.0.dylib. Refer to your system manual for installing libraries
Mounting remote ruby failed with status 10, trying to compile.
Checking requirements for osx_brew.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/grantsayer/.rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...
ruby-2.3.3 - #extracting ruby-2.3.3 to /Users/grantsayer/.rvm/src/ruby-2.3.3

后续步骤

目前我陷入困境 - 无法通过此步骤或通过查看其他帖子进行验证以获得有效的解决方案。

【问题讨论】:

  • 你能显示你正在使用/用于安装 ruby​​-2.3.3 和 rails 的命令吗?只是预感,但我不建议通过 rvm 安装 rails。通过rvm安装ruby比较可靠,然后通过gem install rails --no-ri --no-rdoc安装rails
  • 尝试检查 rvm 正在使用的证书的状态:rvm osx-ssl-certs status all。这将输出每个证书的状态。如果不是Up to date,可以用rvm osx-ssl-certs update all更新。
  • 同意使用 gem 安装导轨 - 这是我通常做的 - 描述中可能不清楚。
  • 检查了 rvm 正在使用的证书,运行该命令没有输出。

标签: ruby-on-rails macos openssl rvm homebrew


【解决方案1】:

好吧,我找到了解决前面描述的问题的方法。以下步骤概述了它是如何解决的。

清理

  1. 删除了通过ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"安装 Homebrew

  2. 删除了通过rvm implode安装RVM

重建

  1. 使用 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 安装 Homebrew

  2. 使用brew upgrade 后跟brew doctor 对Brew 进行完整性检查

  3. 使用\curl -sSL https://get.rvm.io | bash -s stable 安装 RVM(再次!)
  4. 使用rvm autolibs homebrew 确保RVM 通过autolibs 选项了解自制软件
  5. 设置环境变量,以便我们知道 openssl 的安装位置:

    导出 LDFLAGS=-L/usr/local/opt/openssl/lib

    导出 CPPFLAGS=-I/usr/local/opt/openssl/include

    导出 PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

  6. 通过rvm install 2.3.3 --autolibs=homebrew安装ruby

检查它是否有效

  1. 检查 rvm 空间是否知道使用 rvm osx-ssl-certs status all 的 OpenSSL 证书。运行此命令会产生以下输出:Certificates for /usr/local/etc/openssl/cert.pem: Up to date.

  2. 通过gem install rails安装导轨

在最后一步安装成功,Rails 工作正常(终于!)

【讨论】:

  • 非常感谢,这实际上是唯一对我有用的解决方案,..并尝试了其中的一些。
  • 很高兴它有帮助。另一项 - 我发现我不需要导出环境变量。我想重置所有内容并重新安装都可以解决问题。
  • 是的,也不必导出环境变量。
  • 我在安装自编译 Ruby 时遇到了类似的问题。使用 Homebrew 安装 OpenSSL,然后重新编译 Ruby 后的环境变量对我有用。谢谢!
  • 我遇到了另一个问题:rvm 版本是最新的稳定版 (v1.29.3),并且由于rvm issue #4410,此版本的 rvm 强制通过自制软件安装 openssl@1.1。自 2017 年 9 月以来,这个问题是 fixed in the rvm master branch,但还没有新的稳定版本。此外,我在此答案中的exports 中添加的另一个步骤是export RUBY_CONFIGURE_OPTS=--with-openssl-dir="$(brew --prefix openssl)",但我不知道是否需要这样做。
【解决方案2】:

如果这对其他读者不起作用 - 试试这个:

rvm get branch /bugfix/3923_set_osx_brew_openssl_compiler_config
rvm install 2.4.0

如果这对您有用,go to the rvm issue 并告诉开发人员您对他的努力有多感激 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-07
    • 2011-03-30
    • 2015-08-29
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    相关资源
    最近更新 更多