在 Mac OS X Sierra 上设置 RVM,Ruby:无法要求 openssl

Setup RVM, Ruby on Mac OS X Sierra: Unable to require openssl

我遇到了在一台新的 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

背景与环境

发现与故障诊断

从一台干净的笔记本电脑开始,我按照通常的路径安装 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

后续步骤

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

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

清理

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

  2. 删除了 Homebrew 安装
  3. 删除了通过rvm implode

  4. 安装的RVM

重建

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

  2. 安装 Homebrew
  3. 使用 brew upgrade 然后 brew doctor

  4. 对 Brew 进行完整性检查
  5. 使用 \curl -sSL https://get.rvm.io | bash -s stable
  6. (再次!)安装 RVM
  7. 确保 RVM 通过 autolibs 选项使用 rvm autolibs homebrew
  8. 了解自制程序
  9. 设置环境变量,以便我们知道openssl的安装位置:

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

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

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

  10. 通过rvm install 2.3.3 --autolibs=homebrew

  11. 安装ruby

检查它是否有效

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

  2. 通过gem install rails

  3. 安装rails

最后一步安装成功,Rails 开始工作(终于!)

如果这对另一个不起作用 reader - 试试这个:

rvm get branch /bugfix/3923_set_osx_brew_openssl_compiler_config
rvm install 2.4.0

如果适合您,go to the rvm issue 并告诉开发人员您非常感谢他的努力:)