78

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.

Scott Schupbach
  • 1,284
  • 9
  • 21
Chars Davy
  • 1,553
  • 3
  • 14
  • 14
  • You might want to put a little context with your question rather than just dump code in with a one-liner on your OS. Have you taken a look at this post re: the first error? http://stackoverflow.com/a/25186429/4475605 – Adrian May 20 '16 at 01:56
  • Hi Adrian, I am not the ERROR in OSX 10.10. But I update system to OSX10.11, I had the ERROR. – Chars Davy May 20 '16 at 02:26
  • @CharsDavy You may want to change the accepted solution – noraj Sep 23 '17 at 09:14
  • I was able to fix the openssl problem with the commands `rvm pkg install openssl` and `rvm install 2.5.3 --with-openssl-dir=$rvm_path/usr` as described in [this post](https://stackoverflow.com/questions/9049857/after-installing-ruby-1-9-3-rails-3-2-1-getting-opensslsslsslerror-on-simp) – builder-7000 Apr 14 '19 at 06:58

8 Answers8

172

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`
Meekohi
  • 10,390
  • 6
  • 49
  • 58
  • omg finally! this was making me go CRAZY. i just got a new laptop with 10.12.6 and my regular tutorial did not work! – chrisallick Nov 14 '17 at 00:40
  • 3
    for anyone still stuck, this only works if the ssl dir in the rvm command matched the path you get when you run $ which openssl – andy Jan 23 '18 at 13:53
  • 1
    This is not working for me on OS X 10.13.6 and Ruby 2.5.3. I tried using `\`brew --prefix openssl\``, `\`which openssl\``, and `'actual/path/to/openssl'` for the argument to the option. Nothing works. I can't install gems. – Huliax Oct 23 '18 at 18:55
  • 7
    Finally got it to work. I had to implement both this answer and the answer by @guapolo below. Neither solution on its own would work. – Huliax Oct 23 '18 at 19:40
  • 1
    An alternative worth considering (particularly if starting afresh, or with a new computer) is switching to [rbenv](https://github.com/rbenv/rbenv). Triple the github stars of RVM, simple and predictable. This problem is a real pain to solve, particularly for Ruby versions <= `2.3`, so if you need to support them, I highly recommend switching. (Fyi, requires uninstalling rvm). – stwr667 Dec 06 '19 at 02:28
  • 1
    May be for someone will be useful, if you have 3 versions of openssl (@1.0, @1.1, @3), try to use `rvm reinstall 3.0.2 --with-openssl-dir=\`brew --prefix openssl@1.1\`` If used `brew --prefix openssl`, it was latest version 3 and also raised errors. – zswqa Oct 12 '21 at 16:25
  • Thanks @zswqa @3 was indeed the problem for me. This worked `rvm reinstall 3.0.6 --with-openssl-dir=\`brew --prefix openssl@1.1\`` – Prakash Raman Jul 20 '23 at 22:45
43

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`
Ray Baxter
  • 3,181
  • 23
  • 27
Suriyaa
  • 2,222
  • 2
  • 25
  • 44
  • 2
    I had the issue with ruby 2.4.1. I had openssl installed and method 2 solve the issue for me. I updated rvm itself with `rvm get stable` and reinstall ruby with rvm `rvm reinstall ruby-2.4.1`. – Dmitry Shvetsov May 07 '17 at 10:11
  • 2
    I ran into this with ruby 2.4.2. I combined the steps of updating rvm then reinstalling with the dir param `--with-openssl-dir`. I would recommend you also run `which openssl` to know what directory to use in your rvm command. – carnator Oct 18 '17 at 21:17
16

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)

dav_i
  • 27,509
  • 17
  • 104
  • 136
guapolo
  • 2,443
  • 2
  • 20
  • 19
  • 3
    This worked for me. Had to specify the OpenSSL dir when I reinstalled however: `rvm reinstall 2.5.1 --with-openssl-dir=\`brew --prefix openssl\`` on my OSX machine – John Skiles Skinner Aug 23 '18 at 16:04
5

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`
Abhishek Pande
  • 313
  • 1
  • 4
  • 7
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`
Yoganand
  • 473
  • 4
  • 7
2

To solve this issue, you should install OpenSSL version 1.1, and link ruby to it while installing process. Here the commands worked fine with me (macOS):

// install openssl@1.1 
 brew install openssl@1.1
// export PKG_CONFIG_PATH variable 
export PKG_CONFIG_PATH=/opt/homebrew/opt/openssl@1.1/lib/pkgconfig 
// reinstall your ruby version with openssl 1.1 dir
rvm reinstall 3.0.4 --with-openssl-dir=/opt/homebrew/opt/openssl@1.1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45
0

After trying pretty much everything, only the following finally got it running was:

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

I have openssl installed using Mac Ports, rather than Brew

As suggested here: https://mentalized.net/journal/2021/11/29/ruby-3-0-3-rvm-and-openssl-1-1/

personalnadir
  • 402
  • 4
  • 9
-1

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
Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50