问题 在Mac OS X Sierra上安装RVM,Ruby:无法使用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

背景与环境

  • Mac OS X 10.12.3。 (塞拉利昂)
  • 自制1.1.8。安装OpenSSL
  • RVM 1.28.0
  • Ruby 2.3.3 Rails(尝试安装最新版本)
  • 环境变量(以下 OpenSSL包在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 dev),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

下一步

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


11172
2018-01-30 22:37


起源

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


答案:


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

清理

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

  2. 删除了RVM的安装 rvm implode

重建

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

  2. 使用Brew进行完整性检查 brew upgrade 其次是 brew doctor

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

    export LDFLAGS = -L / usr / local / opt / openssl / lib

    export CPPFLAGS = -I / usr / local / opt / openssl / include

    export PKG_CONFIG_PATH = / usr / local / opt / openssl / lib / pkgconfig

  6. 通过安装红宝石 rvm install 2.3.3 --autolibs=homebrew

检查它是否有效

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

  2. 通过安装导轨 gem install rails

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


15
2018-02-01 03:01



非常感谢,这实际上只是对我有用的解决方案,并且尝试了一些来自各地的解决方案。 - remo
很高兴它有所帮助。另一项 - 我发现我不需要导出环境变量。我想重置一切并重新安装让它全部排序。 - Grant Sayer
是的,也没有出口env vars。 - Anton Kuzmin
我在自编译Ruby安装时遇到了类似的问题。用Homebrew安装OpenSSL之后的环境变量,然后重新编译Ruby为我工作。谢谢! - Lars Gyrup Brink Nielsen
我遇到了另一个问题: rvm 版本是最新的稳定版(v1.29.3),这个版本的rvm强制openssl@1.1由自制软件安装,由于 rvm问题#4410。那个问题是 修复了rvm master分支 自2017年9月以来,尚未出现新的稳定版本。另外,我在其中添加了另一个步骤 export在这个答案中是 export RUBY_CONFIGURE_OPTS=--with-openssl-dir="$(brew --prefix openssl)",但我不知道是否需要。 - erik.weathers


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

rvm get branch /bugfix/3923_set_osx_brew_openssl_compiler_config
rvm install 2.4.0

如果这对你有用, 转到rvm问题 并告诉开发人员你多么欣赏他的努力:)


0
2018-02-15 18:41