新手问题 编译的 Ruby 2.3.0 缺少 openssl 支持的解决方法 (已解决)

arth · 2015年12月31日 · 最后由 bingo8671 回复于 2019年09月13日 · 46081 次阅读

按:mac 升级 10.11 后,关于 openssl 的问题出现了很多。按下面方法编译前,需要确认由 openssl 目录。今天我在一台全新 mac 上安装,发现只有 openssl 可执行文件而没有对应目录。可到 openssl.org 下载安装后执行以下方法,即可解决。

前两天在 osx 10.11 上编译安装了 ruby2.3.0。然后安装 gem 时,会有错误提示: ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

重新编译发现,make 的输出中有 configuring openssl Failed to configure openssl. It will not be installed. 如上字样。

然后重新配置,在运行 configure 时加上了 openssl 路径信息即可。正确编译的姿势如下:

$ cd ruby-2.3.0
$ ./configure  --with-openssl-dir=/usr/local/ssl
$ make
$ sudo make install

再次安装 gem,无报错信息。编译成功。

为什么不用 Ruby 的版本管理工具,比如 rbenv 或者 rvm,有什么特别的原因么?

https://gorails.com/setup/osx/10.11-el-capitan

要更新系统自带的 ruby 版本吧,版本管理工具只能是当前用户

#1 楼 @lgn21st 为了更新系统 ruby 版本。rvm 在需要使用多版本 ruby 的情况下确实很方便。但使用 rvm 更新的话,经常会出现各个应用软件的 ruby 版本不同的情形,配置带来的成本大于使用 rvm 带来的方便。

开这个帖子是发现以前也有很多人遇到过相似问题,就提供一个简单直接的解决办法

不需要全部重新编译吧,cd ext/openssl;ruby extconf.rb;make;make install

#4 楼 @africwildman 你提供的这个方法在我的全新 mac 上无法使用。其中 ruby extconf.rb 的作用是什么?

想我这种没有环境维护洁癖的人 直接 brew install openssl 然后 brew link --force openssl 虽然 mac 并不推荐这么做,但是省心

#5 楼 @arth 需要下载、解压 ruby 的源码,然后里面有个 ext/openssl 文件夹,里面有 extconf.rb 这个文件,执行 ruby extconf.rb 可以生成编译 openssl 扩展的 Makefile

楼主请教一下 我在替换 gem sources -a https://gems.ruby-china.org/镜像的时候也是报了这次 请问你是怎么解决的,搞了好几天了还是一直这样 10.11.4 的系统一直装不上 cocoapods 泪崩 ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

楼主忘了说 openssl 的源文件是哪个版本呀,现在 1.1.0 的版本并不是把 openssl 这个命令安装在/usr/local/ssl 文件夹下了。我装了很久,后来试了 1.0.2h 的版本才正常安装。

希望后面遇到这个问题的同学可以看到。

按照楼主的提示,仍然错误;搞了两天一直报 ERROR: While executing gem ... (Gem::Exception)

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

操作环境:mac10.11.3;目的搭建 gitlab 服务时遇到的奇葩问题如下:

  1. Ruby Note: The current supported Ruby versions are 2.1.x and 2.3.x. 2.3.x is preferred, and support for 2.1.x will be dropped in the future.

The use of Ruby version managers such as RVM, rbenv or chruby with GitLab in production, frequently leads to hard to diagnose problems. For example, GitLab Shell is called from OpenSSH, and having a version manager can prevent pushing and pulling over SSH. Version managers are not supported and we strongly advise everyone to follow the instructions below to use a system Ruby. Remove the old Ruby 1.8 if present:

sudo apt-get remove ruby1.8 Download Ruby and compile it:

mkdir /tmp/ruby && cd /tmp/ruby

curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz echo 'c39b4001f7acb4e334cb60a0f4df72d434bef711 ruby-2.3.1.tar.gz' | shasum -c - && tar xzf ruby-2.3.1.tar.gz

cd ruby-2.3.1 ./configure --disable-install-rdoc make sudo make install

安装完这一步后, 执行 ruby -v iMac$ ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15.3.0] gem -v iMac$ gem -v 2.5.1

接下出现错误的地方: Install the Bundler Gem: sudo gem install bundler --no-ri --no-rdoc 一直报下面错误;💀

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

求大神们指点一下;查询 openssl version 时,结果:OpenSSL 0.9.8zg 14 July 2015

相关链接:https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

#8 楼 @AgnesT 我跟你一样的问题,怎么解决呢

以下经过测试

1, 去 ruby 官网下载 ruby-2.3.3

2,安装 openssl,一般用 brew install openssl 安装后路径为/usr/local/Cellar/openssl/1.0.2j

3,安装 ruby:解压 ruby-2.3.3 后 (我解压之后直接放到桌面的),进入其目录,执行: ./configure --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2j

make

sudo make install

#12 楼 @CoderJin 你好,请问进入其目录是什么意思呀

#12 楼 @CoderJin 按照你的方法搞好啦,谢啦

#14 楼 @sanster 您好,我现在还是会出现这个错误,我想安装 sudo gem install cocoapods

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

然后执行./configure --with-openssl-dir=/usr/local/Cellar/openssl/1.1.0d

会出现-bash: ./configure: No such file or directory

想问下您是如何解决的??(ToT)/~~~

#6 楼 @IChou 您好,我执行了此操作,有装上 openssl 但还是会报楼主那个错误是为啥呢?

nothroo 回复

你是在哪个目录执行 ./configure 的?目录错了吧,要在 ruby 源码文件夹里

执行./configure --with-openssl-dir=/usr/local/Cellar/openssl/1.1.0d 之后 显示 Permission denied😫

已按@liuliangsir 提供的方法解决,赞一个!

gazeldx 回复

还是你这个最简单,谢谢

需要 登录 后方可回复, 如果你还没有账号请 注册新账号