Ruby源码安装 cannot load such file -- zlib (LoadError) 和 cannot load such file -- openssl (LoadError) 及 gem No rule to make target `/include/ruby.h', needed by`zlib.o'. Stop. 解决办法
发生问题时我的前置条件
- linux版本: Linux version 3.10.0-862.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018
- gcc版本: gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
- Ruby版本:ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
- gem版本: 3.0.6
- Ruby安装方式: 源码安装且源码未删除
- 安装Ruby及gems目的: 使用ruby搭建redis集群
cannot load such file -- zlib 问题解决
原因
- 缺少zlib函式库
- 缺少ruby-zlib
解决
- (未安装zlib时)下载安装zlib
- 我是使用源码安装,由是默认安装到/usr/local/lib,我选择使用root用户操作
- 安装版本zlib-1.2.11
- 下载软件包
wget http://www.zlib.net/zlib-1.2.11.tar.gz
- 解压缩软件包
tar -zxvf zlib-1.2.11.tar.gz
- 进入zlib源码目录
cd zlib-1.2.11/
- 配置
./configure
- make
make
- 检查
make check
- 安装
make install
- 查看是否成功(目录中存在libz.a)
find /usr/local/lib -name libz.a
- 下载软件包
- 安装 ruby-zlib
- Ruby源码提供了该源码,直接找到对应目录安装
cd /root/ruby-2.6.5/ext/zlib
ruby ./extconf.rb
- 如果报错 checking for zlib.h... no 或 checking for deflateReset() in -lzlib... no
- 则
ruby ./extconf.rb --with-zlib-dir =/usr/local/zlib
make
- 如果报错 make: *** No rule to make target
/include/ruby.h', needed by
zlib.o'. Stop. - 根据日志得知 zlib.o: $(top_srcdir)/include/ruby.h 去查看源码的确不存在变量值的话
- 在Makefile文档第一行,设置变量top_srcdir的路径
- (我采用)用绝对/相对路径替换$(top_srcdir)
- 建议先备份Makefile
vim Makefile
: %s/$(top_srcdir)/..\/../g
:wq
- 如果报错 make: *** No rule to make target
- 如果上一步make报错,在修改后再次
make
make install
- Ruby源码提供了该源码,直接找到对应目录安装
cannot load such file -- openssl 问题解决
原因
- 未安装openssl-devel
- 缺少ruby-openssl
解决
- (未安装openssl时)下载安装openssl
- 我是使用源码安装,默认安装到/usr/local/ssl,且没有链接命令
- 安装版本 openssl-1.0.2t
- 下载软件包
wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz
- 解压缩软件包
tar -zxvf openssl-1.0.2t.tar.gz
- 进入目录
cd openssl-1.0.2t
./config shared zlib
make depend
make
make install
- 验证是否安装成功(显示版本信息)
/usr/local/ssl/bin/openssl version -a
- 如有需要则可以手工链接openssl命令
- 先确认/usr/bin/openssl和/usr/include/openssl不存在,若存在请备份或删除原来的openssl
- (可选)备份方式
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
- (可选)备份方式
- 链接刚刚安装的openssl
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
- (可选)写入ld.so.conf记录动态库的路径
echo “/usr/local/ssl/lib” >> /etc/ld.so.conf
ldconfig -v
- 验证链接是否成功 openssl version -a
- 先确认/usr/bin/openssl和/usr/include/openssl不存在,若存在请备份或删除原来的openssl
- 下载软件包
- 安装ruby-openssl
- Ruby源码提供了该源码,直接找到对应目录安装
cd /root/ruby-2.6.5/ext/openssl
ruby ./extconf.rb
- (未链接刚安装的openssl可能)报错 checking for openssl.h... no 或 checking for deflateReset() in -openssl... no
- 则
ruby ./extconf.rb --with-openssl-dir=/usr/local/ssl
make
- 如果报错 make: *** No rule to make target
/include/ruby.h', needed by
zlib.o'. Stop. - 根据日志得知 zlib.o: $(top_srcdir)/include/ruby.h 去查看源码的确不存在变量值的话,处理方式同安装ruby-zlib
- 在Makefile文档第一行,设置变量top_srcdir的路径
- (我采用)用绝对/相对路径替换$(top_srcdir)
- 建议先备份Makefile
vim Makefile
: %s/$(top_srcdir)/..\/../g
: wq
- 如果报错 make: *** No rule to make target
- 如果上一步make报错,在修改后再次
make
make install
- Ruby源码提供了该源码,直接找到对应目录安装
No rule to make target /include/ruby.h', needed by
zlib.o'. Stop. 解决办法
原因
- 可能是缺少$(top_srcdir)/include/ruby.h变量对应值
解决
- 如果报错 make: *** No rule to make target
/include/ruby.h', needed by
zlib.o'. Stop. - 根据日志得知 zlib.o: $(top_srcdir)/include/ruby.h 去查看源码的确不存在变量值的话
- 在Makefile文档第一行,设置变量top_srcdir的路径
- (我采用)用绝对/相对路径替换$(top_srcdir)
- 建议先备份Makefile
cp Makefile Makefile.bak
vim Makefile
: %s/$(top_srcdir)/..\/../g
: wq
- 建议先备份Makefile