Rails 环境部署,替换镜像源,不能用 https - Unable to require openssl

bighuzi · February 18, 2017 · Last by Itgo666 replied at May 23, 2019 · 1760 hits

gem sources -a https://gems.ruby-china.org/

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

在帖子中看到:https://ruby-china.org/topics/31352

./configure --with-openssl-dir=/usr/local/opt/openssl

但是执行出现找不到这个文件

./configure --with-openssl-dir=/usr/local/opt/openssl
zsh: no such file or directory: ./configure

你可能是 1.29.0 版 rvm 的受害者,降级一下 rvm get 1.28.0

Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

问题原因,你安装 Ruby 之前没有安装 OpenSSL,这个是 Ruby 的必要库,然后再重新安装 Ruby。

例如 Ubuntu Server:

sudo apt-get install openssl

对于不熟悉这类细节的同学,建议使用 RVM 或 ruby-build 之类的工具来安装(生产环境也是可以用的),他们会帮助你解决这类问题。

Reply to jasl

这个问题奇怪了,遇到同样的问题,rvm 版本为 1.29.8,gem 版本为 2.7.9 gem sources 为https://gems.ruby-china.com, 现在问题是,gem install rails 提示: ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources 这是什么情况啊?看到网上一大堆答案,一个一个都试过了,结果都不能解决

Reply to Itgo666

什么系统?尝试重装过 Ruby 么?

Reply to jasl

系统是:macOS Mojave 10.14 今天重装的用 rvm 重装的 ruby2.3.8

Reply to Itgo666

有没有安装 Xcode 和 Xcode command line tools?试试相同环境 2.5 能否安装呢?我 google 了下,比如 https://stackoverflow.com/questions/55525660/installing-ruby-2-3-1-on-mojave-osx-with-rbenv-or-rvm 看样子 ruby 2.3 跟 Mojave 的 openssl 有兼容问题

Reply to jasl

我刚刚用 rvm 安装了 ruby 2.5.5,一切回归正轨了,没有出现这个问题了 这个狗血的兼容问题。。。 抱歉,这么晚请教,请恕我打扰了,谢谢🙏

Reply to Itgo666

嗯,Ruby 几乎是完全向下兼容的(不过 2.4 是一道坎,有些太老的代码会出问题),除非发现问题,默认用最新版本就好。

Reply to jasl

嗯嗯,谢谢,2.4 版本发生了啥?我之前一直用的都是 2.4.0,还真没注意这正好是一道坎儿😆

Reply to Itgo666

2.4 之前 整数类型分成 Fixnum 和 Bignum,在 2.4 的时候合并成了 Integer,主要是这个改动导致很多老项目的代码挂掉

Reply to jasl

👍 专业

You need to Sign in before reply, if you don't have an account, please Sign up first.