Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

MacosRubygemsRvm

Macos Problem Overview


I'm attempting to install jekyll and I've encountered an error. I'm running 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

I welcome your suggestions how to resolve this error.

Macos Solutions


Solution 1 - Macos

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`

Solution 2 - Macos

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`

Solution 3 - Macos

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)

Solution 4 - Macos

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`

Solution 5 - Macos

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 [email protected]
rvm install 3.0.2 --with-openssl-dir=`brew --prefix openssl@1.1`

Solution 6 - Macos

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChars DavyView Question on Stackoverflow
Solution 1 - MacosMeekohiView Answer on Stackoverflow
Solution 2 - MacosSuriyaaView Answer on Stackoverflow
Solution 3 - MacosguapoloView Answer on Stackoverflow
Solution 4 - MacosYoganandView Answer on Stackoverflow
Solution 5 - MacosAbhishek PandeView Answer on Stackoverflow
Solution 6 - MacosFilipe AguiarView Answer on Stackoverflow