30
votes

I have openssl installed in my virtual machine ubuntu12.04lts.

When I run the gem command it gives error.

Error: while executing gem (Gem::Exception)
Unable to require openssl. install openSSL and rebuilt ruby (preferred) or use non HTTPs sources

And I also test require openssl in irb mode. it gives error.

Loaderror: cannot load such file --openssl
from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55 `require'

I have openssl

$openssl version
OpenSSL 1.0.1 14 mar 2012

How to fix the error?

13
What version of Ruby are you using and how did you install it? You probably have to rebuild Ruby as it says in the error message. - David Grayson
Hi David I am using ruby2.1.0p0 of ruby. I installed it by built its source. - Siva Gnanam
The problem looks like the filename: --openssl vs just openssl (unless Ruby prepends the dashes on error output). Is openssl accidentally getting formatted as a switch? - jww
Hello noloader, I am sorry I could not understand what you just asking. Is openssl accidentally getting formatted as a switch? what it mean how can I answer to this question. Help me to do Thanks :) - Siva Gnanam
What if I do not want to run with openssl? - Louie Miranda

13 Answers

23
votes

Note: Calls to rubygems.org are deprecated - proceed with caution!

I had the same issue on Mac OSX after also building ruby2.1.0p0 from the source. I already had openssl installed. It appears that the reference in gems needed refreshing. I ran:

gem source -r https://rubygems.org/ to remove

followed by

gem source -a https://rubygems.org/ to read

After this, I was able to run gems install bundler successfully.

If you run into further errors, you can try ./configure --with-openssl-dir=/usr/local/ssl in your ruby downloaded dir/.

18
votes

I got this error while using debian where openssl was in /usr/bin.

Following the suggestion of jspacek I reconfigured ruby using:

./configure --with-openssl-dir=/usr/bin

After make and sudo make install I was able to install rails.

16
votes

make sure you have libssl-dev installed:

dpkg -s libssl-dev

if not, install it:

sudo apt-get -y install libssl-dev
8
votes

In case someone else has this problem, try reinstalling your Ruby version with openssl included

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

You might already have openssl - so you can ignore the first step. This helped me.

4
votes

I'm leaving this answer for reference to future Googlers:

Type all these commands in your Terminal (OSX) just to be extra sure you've done everything (this is what eventually worked for me)

rvm get stable
brew update
brew doctor
brew install openssl
rvm install ruby-2.1 (or whatever version)
rvm use (ruby version here)  i.e. rvm use ruby-2.1
rvm gemset create NAME   i.e. rvm gemset create rails41
gem install rails -v 4.1

Finally...

As many commenters have pointed out - you need OpenSSL installed before you compile ruby before you install rails (or other gems)

3
votes

You probably built Ruby from source before installing OpenSSL. Make sure you install it and then try reconfiguring and rebuilding Ruby.

2
votes

Recently I was struggling with ruby installations due to the recent auto-update in openssl version from 1.0 to 1.1 and wanted to revert it back to older version. No other solution except the one given below worked for me:

brew install rbenv/tap/[email protected] rvm reinstall 1.9.3-p551 --with-openssl-dir='/usr/local/opt/[email protected]' gem update --system Now my ruby runs with openssl 1.0 whereas all other libraries are running on the default openssl version 1.1.

1
votes

Rebuilding Ruby after running sudo apt-get install libssl-dev libreadline-dev libgdbm-dev can solve this issue.

I found this solution here.

1
votes

I was getting this error installing Ruby with RVM. Nothing worked. I switched to rbenv. Problem solved!

0
votes

for me it was a case of missing dependencies.

i thought i had all the dependencies required to install ruby, but i too was getting an openSSL and readline error.

i attempted to install ruby with RVM without root privileges which failed but gave me a list of missing dependencies. i then installed the dependencies with a package manager. i then re-attempted to install ruby from source from the beginning, and everything worked OK

the dependencies that were missing, for me, were:

 patch libyaml-devel autoconf gcc-c++
 readline-devel libffi-devel openssl-devel
 automake libtool bison sqlite-devel

but they may be different for you.

update: i don't originally remember where exactly i found this list, but a quick search found similar lists on the following pages, which might also help you:

https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-on-centos-6-with-rvm

http://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/install-ruby-on-rails-on-centos-ubuntu-fedora-from-source.html

0
votes

These steps worked for me:

  1. Fixed ruby install:

    brew upgrade openssl; openssldir=which openssl rvm reinstall ruby-2.4.2 --with-openssl-dir=$openssldir

  2. Removed and re-added sources for gems

    gem sources -r https://rubygems.org/ gem sources --add https://rubygems.org/

0
votes

i had similar issue and tried to solve it by following guides. The "rebuild ruby" is an important step!

after openssl_devel is installed

cd folder_of_ruby_source_code/ext/openssl  
ruby ./extconf.rb  
make  
make install  

cd folder_of_ruby_source_code  
./configure  
make clean       <= clean is important here
make  
make install  
-2
votes

Do you use RVM?

If not, try using it and see if it fixes your problem.