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

9

89

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.

Princedom answered 20/5, 2016 at 1:31 Comment(4)
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? https://mcmap.net/q/246271/-couldn-39-t-require-openssl-in-rubyRathe
Hi Adrian, I am not the ERROR in OSX 10.10. But I update system to OSX10.11, I had the ERROR.Princedom
@CharsDavy You may want to change the accepted solutionLangmuir
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 postThimbleful
J
182

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`
Jockey answered 14/2, 2017 at 20:49 Comment(8)
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!Shirleeshirleen
for anyone still stuck, this only works if the ssl dir in the rvm command matched the path you get when you run $ which opensslSyverson
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.Schizophrenia
Finally got it to work. I had to implement both this answer and the answer by @Calif below. Neither solution on its own would work.Schizophrenia
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).Legality
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.Beaufort
Thanks @Beaufort @3 was indeed the problem for me. This worked rvm reinstall 3.0.6 --with-openssl-dir=`brew --prefix [email protected]`Gaslit
For any ruby versions above 3 I had to specify the exact path for my openssl install like in the first answer above. All of the brew --prefix commands didn't work for me.Darkling
S
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`
Selmore answered 22/5, 2016 at 15:28 Comment(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.Myogenic
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.Tame
C
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)

Calif answered 15/2, 2017 at 0:5 Comment(1)
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 machineMicrosporangium
E
9

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]`
Equimolecular answered 13/5, 2022 at 10:51 Comment(1)
Thank you so much, I have been pulling my hair out trying to get this to workMispronounce
B
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`
Billen answered 24/5, 2019 at 13:0 Comment(0)
C
4

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]
Comparison answered 31/1, 2023 at 21:5 Comment(0)
F
2

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`
Fulgurate answered 5/2 at 5:50 Comment(0)
F
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/

Fortnightly answered 22/8, 2023 at 17:59 Comment(0)
G
-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
Gyre answered 7/4, 2017 at 19:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.