程序员开发实例大全宝库

网站首页 > 编程文章 正文

编译 Ruby 2.6.0 缺少 openssl 库的解决方法 (已解决)

zazugpt 2024-10-19 16:28:04 编程文章 15 ℃ 0 评论

更新 cocoapods 的时候,提示 ruby 版本低,下面是升级 ruby 的坎坷之路。

一、材料

  1. macOS 系统版本 10.13.6
  2. 系统自带 ruby 版本为 ruby 2.3.7p456
  3. 系统自带 openssl 版本为 LibreSSL 2.2.7
  4. 另外用 brew install openssl 安装的版本为 OpenSSL 1.0.2o

二、过程

1、使用 sudo gem install cocoapods 更新 cocoapods 报错,需要 ruby version >= 2.6

2、去 ruby 官网下载 ruby-2.6.0,由于 macOS 版本较低,没有下载最新的 ruby

3、安装 ruby,执行以下操作猛如虎,一切正常:

./configure --prefix=/usr/local/ruby-2.6.0
make
sudo make install

4、把 ruby 2.6.0 可执行文件导入全局变量 PATH 中,使用如下命令:

echo 'export PATH="/usr/local/ruby-2.6.0/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

至此 ruby 2.6.0 安装成功,使用以下命令查看 ruby 版本:

ruby -v

然后终端输出 ruby 版本:

ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin17]

5、重新执行 sudo gem install cocoapods 又报错,ruby 没有 openssl 模块。

6、重新编译 ruby ,带上 openssl 模块。(就是这一步,浪费了我太多时间)

一开始使用下面的命令

./configure --prefix=/usr/local/ruby-2.6.0 --with-openssl=/usr/bin/openssl

make 后,提示找不到 openssl 库:

*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/Users/esdzxc/Downloads/ruby/ruby-2.5.9/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
Check ext/openssl/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.

后来发现需要使用 --with-openssl-dir ,所以更改命令再战:

./configure --prefix=/usr/local/ruby-2.6.0 --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2o_1
make
sudo make install

7、重新执行 sudo gem install cocoapods ,搞定。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表