Ruby and "You must recompile Ruby with OpenSSL support or change the sources in your Gemfile"
RubyMacosOpensslRvmRuby Problem Overview
Using rvm I upgraded my ruby to 1.9.3-p392, also added 2.0.0, anytime I try to use this version when I run my bundle command I get this error.
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using RVM are
available at rvm.io/packages/openssl.
I have followed several different instructions on how to fix this. I have tried removing the version and installing it with the rvm options
--with-openssl-dir=$HOME/.rvm/usr
I have installed OpenSSL with rvm, and macports. Both have not helped the problem. I even changed the file location of the ssl cert using this:
export SSL_CERT_FILE=/Users/DarkLord/.rvm/usr/ssl/cert.pem
No matter what I do I continue to get the error. Can someone please help me fix this?
Ruby Solutions
Solution 1 - Ruby
This works for me:
rvm get stable
brew install libyaml
rvm pkg install openssl
rvm install ruby-2.0.0 --with-openssl-dir=$HOME/.rvm/usr
rvm use ruby-2.0.0
All credits go to https://coderwall.com/p/tptocq
Solution 2 - Ruby
This helps me install 1.9.3-head on Mac:
rvm get latest
brew install openssl
rvm reinstall 1.9.3-head --with-openssl-dir=`brew --prefix openssl`
Solution 3 - Ruby
In my case after:
1. brew install openssl
2. rvm install ruby-2.6.0
bundle install
failed with this error. The problem was that openssl was globally set so I had to install the new ruby version by setting the openssl directory explicitly.
So what I had to do was:
1. rvm reinstall ruby-2.6.0 --with-openssl-dir=/usr/local/opt/openssl
2. rvm reload
Assuming that usr/local/opt/openssl
is where it is installed.
After that bundle install
ran successfully.
Warning when I tried this command with this path /usr/local
like some answers suggested, it didn't work.
Solution 4 - Ruby
To get this working again I had to install homebrew and move my mac ports out of the way. Then do the following after removing 1.9.3-p392 and 2.0.0-p0:
rvm get head --autolibs=3
rvm install 1.9.3 --with-opt-dir=/usr/bin
rvm install 2.0.0
There was something not working with my mac ports and openssl and make and configure. This was the only way I was able to get rvm to install ruby again with out getting openssl issues or make/configure issues.
Solution 5 - Ruby
In my case:
Problem: After installing ruby-2.3.1, I ran the command bundle install
and then the error occurred.
Solution:
-
I first installed OpenSSL on my machine.
$ brew install openssl
-
And then, reinstalled the ruby version I require (2.3.1) with the openssl.
$ rvm reinstall 2.3.1 --with-openssl-dir=/usr/local/opt/openssl
And this solved my problem!
Solution 6 - Ruby
The new way to do it, according to a comment by @Purplejacket above, is the following:
rvm autolibs homebrew
rvm install 2.1.1
rvm use 2.1.1
It's much easier.
Solution 7 - Ruby
According to the following question: https://stackoverflow.com/questions/13956134/how-to-tell-which-openssl-lib-is-actually-being-used-by-an-rvm-installed-ruby/13958931
It seems that the options --with-openssl-dir=...
is no longer valid as of Ruby 1.9.3. I tried
rvm install 1.9.3 --with-opt-dir=/usr/local --with-openssl
and it worked.
Solution 8 - Ruby
macOS Catalina
brew install rbenv/tap/openssl@1.0
rvm reinstall 2.3.8 --with-openssl-dir=/usr/local/opt/openssl@1.0
Solution 9 - Ruby
The following steps worked for me.
First ensure openssl
is installed by running brew install openssl
, then reinstall the ruby version using rvm, but this time around, you have to pass the with-opt-dir
flag pointing to the location where openssl was installed on your machine (use command which openssl
to find this location).
rvm install 1.9.3-p392 --with-openssl-dir=/usr/local/opt/openssl
Solution 10 - Ruby
On macOS 10.14, Ruby 2.5.3, and OpenSSL 1.0.2n this worked for me:
./configure --with-openssl --with-openssl-dir=/usr/local/ssl
but I was only trying what the error messages were telling me:
*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/Users/brian/Desktop/Ruby/ruby-2.5.3/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
Check ext/openssl/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
make[1]: *** [note] Error 1
Solution 11 - Ruby
That's what helped me:
rvm reinstall 2.5
brew tap raggi/ale
brew install openssl-osx-ca
brew services start openssl-osx-ca
Found this solution here: https://github.com/raggi/openssl-osx-ca#readme
Solution 12 - Ruby
I specified a more recent Ruby version in my Gemfile, then ran bundle install. All good now.
Solution 13 - Ruby
I encountered this issue when working on a Ruby 2.2.3 application.
I had previously uninstalled the MySQL database server on my machine, since I did not need it. However, I still needed the mysql2 gem since my application was connecting to another application's MySQL database to pull data.
However, when I try to run the bundle
command I get the error:
> Could not load OpenSSL. You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using RVM are available at rvm.io/packages/openssl.
Here's how I solved it:
The issue was caused by removing the libssl-dev
library when I was uninstalling the MySQL database server on my machine and its libraries.
First I ran the command below to reinstall ruby
since I installed it using rvm
:
rvm reinstall ruby-2.2.3
This raised an error:
> Making gemset ruby-2.2.3 pristine............................................./- .'command gem pristine --extensions mysql2 --version 0.5.3' failed, you need to fix these gems manually. . Error running '__rvm_with ruby-2.2.3 gemset_pristine', please read /home/promisepreston/.rvm/log/1630094455_ruby-2.2.3/gemset.pristine-ruby-2.2.3.log
Next, I tried to install the mysql2 gem:
gem install mysql2
Then I ran into this error:
> Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.
Finally, I installed the mysql client library using the command:
sudo apt-get install libmysqlclient-dev
Note: This also installs the libssl-dev
library alongside.
And everything worked fine.
That's all.
Solution 14 - Ruby
I don't use rvm, and I don't want to. I had to install asdf in order to resolve what I used to be able to do with just homebrew & ruby.
Following this guide is the only thing that worked for me after following dozens of suggestions. I had to install asdf and update my .zshrc to include the following at the end of the doc:
eval "$(rbenv init - zsh)"
I'm on an Intel Mac running Monterey 12.2.1.