You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu下安装Ruby的openssl gem失败,求正确gem install参数

OpenSSL Gem安装失败解决方案

问题背景

执行以下命令安装openssl gem失败:

$ apt-get install -y openssl
$ gem install openssl -- --with-openssl-include=/usr/include/openssl

报错信息

...
checking for openssl/ssl.h... yes
checking for CRYPTO_malloc() in -lcrypto... yes
checking for SSL_new() in -lssl... yes
checking for LIBRESSL_VERSION_NUMBER in openssl/opensslv.h... no
checking for OpenSSL version >= 1.0.2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-3.0.1/bin/$(RUBY_BASE_NAME)
    --with-openssl-dir
    --with-openssl-include=${openssl-dir}/include
    --with-openssl-lib=${openssl-dir}/lib
    --with-kerberos-dir
    --without-kerberos-dir
    --with-kerberos-include
    --without-kerberos-include=${kerberos-dir}/include
    --with-kerberos-lib
    --without-kerberos-lib=${kerberos-dir}/lib
    --with-nsl-dir
    --without-nsl-dir
    --with-nsl-include
    --without-nsl-include=${nsl-dir}/include
    --with-nsl-lib
    --without-nsl-lib=${nsl-dir}/lib
    --with-nsllib
    --without-nsllib
    --with-socket-dir
    --without-socket-dir
    --with-socket-include
    --without-socket-include=${socket-dir}/include
    --with-socket-lib
    --without-socket-lib=${socket-dir}/lib
    --with-socketlib
    --without-socketlib
    --with-crypto-dir
    --without-crypto-dir
    --with-crypto-include
    --without-crypto-include=${crypto-dir}/include
    --with-crypto-lib
    --without-crypto-lib=${crypto-dir}/lib
    --with-cryptolib
    --without-cryptolib
    --with-ssl-dir
    --without-ssl-dir
    --with-ssl-include
    --without-ssl-include=${ssl-dir}/include
    --with-ssl-lib
    --without-ssl-lib=${ssl-dir}/lib
    --with-ssllib
    --without-ssllib	extconf.rb:136:in `<main>': OpenSSL >= 1.0.2 or LibreSSL >= 3.1.0 is required (RuntimeError)

系统环境验证

系统已安装OpenSSL 3.0.2:

$ which openssl
/usr/bin/openssl
$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)

解决方法

方法1:指定完整OpenSSL安装目录

gem扩展需要完整的OpenSSL路径来识别版本,执行以下命令:

gem install openssl -- --with-openssl-dir=/usr

方法2:安装OpenSSL开发包

如果方法1失败,先安装包含头文件和静态库的开发包:

apt-get install -y libssl-dev

再重新执行方法1的gem安装命令。

方法3:重新关联RVM与OpenSSL(针对RVM用户)

若使用RVM管理Ruby,重新编译Ruby并关联正确的OpenSSL版本:

rvm reinstall 3.0.1 --with-openssl-dir=/usr

完成后直接安装openssl gem即可,无需额外参数。

内容的提问来源于stack exchange,提问作者yegor256

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 04:25:39