gem install redis报错解决办法

  • Post author:
  • Post category:其他


redis-cluster安装需要通过gem install redis来安装相关依赖。否则报错。

通过gem install redis会报如下错误1:

ERROR:  Loading command: install (LoadError)
	cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass

这是缺少zlib依赖,需要安装zlib库

还有一个错误2就是

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

提示缺少openssl库,这两个库可以通过yum安装,但是安装了需要集成到ruby中。

先解决错误一,解决办法分为两步:

一、安装zlib库,如果已经安装,跳过,直接进入第二步。

yum install zlib-devel

二、集成zlib库到ruby环境

cd /data/ruby-2.4.2
cd ext/zlib
ruby extconf.rb
//在操作下一步之前需要修改Makefile文件中的zlib.o: $(top_srcdir)/include/ruby.h,将$(top_srcdir)修改为../..如下
//zlib.o: ../../include/ruby.h
//这一步如果不修改,make时会爆出另外一个错误
//make:*** No rule to make target `/include/ruby.h', needed by `zlib.o'.  Stop
make && make install

另一个缺少openssl库的错误,可以用同样的问题解决。

一、安装openssl库,如果已经安装可以跳过,直接进入第二步。

yum install openssl-devel

不要只用yum install openssl来安装,否则会缺少pcre等相关库,执行ruby extconf.rb会提示找不到ssl.h文件。

checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for openssl/ssl.h... no

第二步、集成openssl库到ruby

cd /data/ruby-2.4.2
cd ext/openssl
ruby extconf.rb
//同样修改Makefile中的$(top_srcdir)为../..
make && make install
[root@node01 openssl]# make && make install
compiling openssl_missing.c
compiling ossl.c
compiling ossl_asn1.c
compiling ossl_bio.c
compiling ossl_bn.c
compiling ossl_cipher.c
compiling ossl_config.c
compiling ossl_digest.c
compiling ossl_engine.c
compiling ossl_hmac.c
compiling ossl_ns_spki.c
compiling ossl_ocsp.c
compiling ossl_pkcs12.c
compiling ossl_pkcs5.c
compiling ossl_pkcs7.c
compiling ossl_pkey.c
compiling ossl_pkey_dh.c
compiling ossl_pkey_dsa.c
compiling ossl_pkey_ec.c
compiling ossl_pkey_rsa.c
compiling ossl_rand.c
compiling ossl_ssl.c
compiling ossl_ssl_session.c
compiling ossl_x509.c
compiling ossl_x509attr.c
compiling ossl_x509cert.c
compiling ossl_x509crl.c
compiling ossl_x509ext.c
compiling ossl_x509name.c
compiling ossl_x509req.c
compiling ossl_x509revoked.c
compiling ossl_x509store.c
linking shared-object openssl.so
/usr/bin/install -c -m 0755 openssl.so /usr/local/lib/ruby/site_ruby/2.4.0/x86_64-linux
installing default openssl libraries

成功之后,再次运行gem install redis,出现以下界面:

Fetching: redis-4.0.1.gem (100%)
Successfully installed redis-4.0.1
Parsing documentation for redis-4.0.1
Installing ri documentation for redis-4.0.1
Done installing documentation for redisafter 1 seconds
1 gem installed

gem install redis安装成功。



版权声明:本文为feinifi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。