无法要求 openssl,安装 OpenSSL 并重建 ruby(首选)或使用非 HTTPS 源

问题描述 投票:0回答:8

我正在尝试安装

jekyll
,但遇到错误。我正在运行 Mac OS X 10.11.4 (El Capitan)。

$gem install jekyll
ERROR : While executing gem ... (Gem::Exception)
        Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
$gem source -l
https://ruby.taobao.org
$which openssl
/usr/local/bin/openssl

欢迎您提出如何解决此错误的建议。

macos rubygems rvm
8个回答
172
投票

较新版本的 OSX 已弃用 openSSL,导致许多依赖项被破坏。您需要重新安装 ruby,但要准确指定 openSSL 库的位置。如果您使用

rvm
那么看起来像:

rvm reinstall 2.3.0 --with-openssl-dir=/usr/local/opt/openssl

如果您使用的是自制软件,那么您的库所在位置的快速快捷方式是:

brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`

43
投票

方法一(安装OpenSSL)

在终端 (OSX) 中输入所有这些命令,以确保您已完成所有操作:

rvm get stable
brew update
brew doctor
brew install openssl
rvm install ruby-2.4 (or whatever version)
rvm use ruby-2.4 (or whatever version)
rvm gemset create jekyll
gem install jekyll

最后,在安装 Jekyll(或其他 gem)之前,您需要在编译 Ruby 之前安装 OpenSSL!

方法2(重新安装Ruby)

较新版本的 OSX 已弃用 openSSL。

您需要重新安装 Ruby!

带有 OpenSSL 的 RVM

rvm reinstall 2.3.0 --with-openssl-dir=/usr/local/opt/openssl

使用最新的RVM版本

rvm get stable
rvm reinstall ruby-2.3.0

自制程序和 OpenSSL

brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`

16
投票

您只需设置此环境变量,以便您的编译器具有 openssl 库的正确路径(如果在 macOS 上使用 Homebrew,请尝试

brew info openssl
查看此信息):

$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
# For pkg-config to find this software you may need to set:
$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

然后重新安装你的 ruby (

rvm reinstall ruby-version
)


4
投票
brew install openssl

brew info openssl # do the suggested options
$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
# For pkg-config to find this software you may need to set:
$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

rvm reinstall <version> --with-openssl-dir=`brew --prefix openssl`

4
投票

适用于 ubuntu 22.04。 Ruby 无法使用 openssl v3 进行编译。如果你使用brew安装的话,这就是openssl。 这样做:

brew install [email protected]
rvm install 3.0.2 --with-openssl-dir=`brew --prefix [email protected]`

2
投票

要解决这个问题,您应该安装OpenSSL 1.1版本,并在安装过程中将ruby链接到它。 这里的命令对我来说效果很好(macOS):

// install [email protected] 
 brew install [email protected]
// export PKG_CONFIG_PATH variable 
export PKG_CONFIG_PATH=/opt/homebrew/opt/[email protected]/lib/pkgconfig 
// reinstall your ruby version with openssl 1.1 dir
rvm reinstall 3.0.4 --with-openssl-dir=/opt/homebrew/opt/[email protected]

0
投票

在尝试了几乎所有方法之后,只有以下内容最终使其运行:

PKG_CONFIG_PATH=/opt/local/lib/openssl-1.1/pkgconfig rvm reinstall 3.0.3 --with-openssl-lib=/opt/local/lib/openssl-1.1 --with-openssl-include=/opt/local/include/openssl-1.1

我使用 Mac Ports 安装 openssl,而不是 Brew

如此处建议:https://mentalized.net/journal/2021/11/29/ruby-3-0-3-rvm-and-openssl-1-1/


-1
投票

考虑到与 openssl 相关的其他答案,当我们尝试在某些情况下以超级用户身份执行时,我们可以看到相同的错误,如下所示:

filipe@FILIPE:~$ sudo gem install bundler 
ERROR:  While executing gem ... (Gem::Exception)
    Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

没有超级用户权限,我们可以看到不同的行为,成功的行为,如下所示:

filipe@FILIPE:~$  gem install bundler 
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Installing ri documentation for bundler-1.14.6
Done installing documentation for bundler after 4 seconds
1 gem installed
© www.soinside.com 2019 - 2024. All rights reserved.