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版本: Linux ossjh2 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- 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報錯,在修改後再次
make
make install
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
- 安裝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報錯,在修改後再次
make
make install
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
vim Makefile
: %s/$(top_srcdir)/..\/../g
: wq