无法要求 OpenSSL、安装 OpenSSL 和重新生成 Ruby (首选)或使用非 HTTPS 源

我正在尝试安装 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

我欢迎您提出解决这个错误的建议。

55523 次浏览

Method 1 (Install OpenSSL)

Type all these commands in your Terminal (OSX) just to be extra sure you've done everything:

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

Finally, you need OpenSSL installed before you compile Ruby before you install Jekyll (or other gems)!

Method 2 (Reinstalling Ruby)

Newer versions of OSX deprecated openSSL.

You need to reinstall Ruby!

RVM with OpenSSL

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

With the latest RVM version

rvm get stable
rvm reinstall ruby-2.3.0

homebrew and OpenSSL

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

Newer versions of OSX deprecated openSSL, leaving many dependencies broken. You need to reinstall ruby, but specify exactly where your openSSL libraries are. If you're using rvm then that looks like:

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

If you're using homebrew, then a quick shortcut to where your libraries are is:

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

You just need to set this env variables so your compiler has the correct path for openssl libs (if using Homebrew on macOS, try brew info openssl to see this info):

$ 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

Then reinstall your ruby (rvm reinstall ruby-version)

Considering the other answers related to openssl, we can see the same error yet when we try to execute as a superuser in some cases, as follows:

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

Without superuser permissions, we can see a different behavior, a successful one, as follows:

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
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`

For ubuntu 22.04. Ruby will not compile with openssl v3. Which is the openssl if you install it using brew. Do this:

brew install openssl@1.1
rvm install 3.0.2 --with-openssl-dir=`brew --prefix openssl@1.1`