96

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.

5
  • 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? stackoverflow.com/a/25186429/4475605 Commented May 20, 2016 at 1:56
  • Hi Adrian, I am not the ERROR in OSX 10.10. But I update system to OSX10.11, I had the ERROR. Commented May 20, 2016 at 2:26
  • @CharsDavy You may want to change the accepted solution Commented Sep 23, 2017 at 9: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 Commented Apr 14, 2019 at 6:58
  • rvm reinstall ruby-3.3.6 --with-openssl-dir=brew --prefix [email protected]`` Worked for me Commented Dec 2, 2024 at 4:08

11 Answers 11

188

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`
Sign up to request clarification or add additional context in comments.

8 Comments

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
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.
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.
An alternative worth considering (particularly if starting afresh, or with a new computer) is switching to 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).
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 [email protected]` If used brew --prefix openssl, it was latest version 3 and also raised errors.
|
46

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`

2 Comments

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.
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.
17

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)

1 Comment

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
11

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 [email protected]`

1 Comment

Thank you so much, I have been pulling my hair out trying to get this to work
7

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 [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]

Comments

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

Comments

4

Recent iterations of OSX have deprecated openSSL, resulting in numerous broken dependencies. To rectify this issue, you must reinstall Ruby, ensuring that you precisely specify the location of your openSSL libraries. If you're employing rvm, the process entails:

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

For users leveraging homebrew, a convenient method to locate the libraries is:

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

Comments

1

For those who use homebrew + rbenv, the fix is similar to the answer by @Meekohi:

RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl)" rbenv install [ruby version]

If you have more than one openssl, specify the one you want, for example:

Look in the directory to see which versions you can select. Be aware that Homebrew rolls up the minor versions when you upgrade, so you might see something like this:

$ brew --prefix openssl

/usr/local/opt/openssl@3

$ ls -l /usr/local/opt/

...
openssl -> ../Cellar/openssl@3/3.3.1
openssl@3 -> ../Cellar/openssl@3/3.3.1
[email protected] -> ../Cellar/openssl@3/3.3.1
[email protected] -> ../Cellar/openssl@3/3.3.1
[email protected] -> ../Cellar/openssl@3/3.3.1

Thus openssl, openssl@3 and [email protected] all point to [email protected]

Comments

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/

Comments

0

For those who are using another Ruby Version Manager (frum in my case)

run this command:

brew --prefix openssl

you'll get something like:

/usr/local/opt/openssl@3

then, uninstall any ruby version if you has already installed one: (in my case):

frum uninstall 3.3.0 

once it is unistalled run this command:

frum install 3.3.0 --with-openssl-dir=/usr/local/opt/openssl@3

Finally you-ll get a new ruby version with openssl.

Happy coding :D

Comments

-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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.