Couldn't require openssl in ruby
Asked Answered
F

13

31

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?

Fluency answered 18/1, 2014 at 7:45 Comment(6)
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.Knighthead
Hi David I am using ruby2.1.0p0 of ruby. I installed it by built its source.Fluency
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?Fimbriate
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 :)Fluency
What if I do not want to run with openssl?Resor
Without openssl enabled in ruby environment we are using. could not access remote gems. It shows clearly that install openSSL and rebuilt ruby (preferred) or use non HTTPs sources. To use HTTPs sources ruby have to access to openssl library.Fluency
S
23

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

Sidonie answered 7/8, 2014 at 15:29 Comment(7)
Thanks for the heads up! I will put a note that this solution is deprecated, as the answer is old now.Sidonie
thanks. I just had this same problem after installing ruby 2.2 on linux from sources also. Your fix workedIsrael
More than being deprecated, this is scary from a security standpoint.Eisele
@DrewStephens I'm not very knowledgable about security - would you mind elaborating? Would be good to know!Sidonie
@Sidonie Not using HTTPS opens the connection up to man-in-the-middle attacks. HTTPS without certificate pinning is still susceptible to a lot of attacks, but at least they require trusted certificates. Less important in the case of retrieving gems is that S prevents attackers from eavesdropping on your HTTP requests.Eisele
It seems that running "gem source -a rubygems.org" works just as well as http. Actually, http version now prints out the warning "rubygems.org is recommended for security over rubygems.org" for the unsecure version. I'll edit the original. Thanks for pointing this out!Sidonie
i can't run gem source, it says cannot load such file -- opensslDisconnection
M
18

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.

Melodist answered 1/12, 2014 at 20:43 Comment(3)
This is the issue with my Raspberry Pi running Raspbian / DebianDeel
This really help!Electronic
For Homebrew users: brew install openssl; rvm reinstall 2.3.0 --with-openssl-dir=brew --prefix openssl``Eisele
I
16

make sure you have libssl-dev installed:

dpkg -s libssl-dev

if not, install it:

sudo apt-get -y install libssl-dev
Infrequent answered 15/4, 2014 at 11:14 Comment(0)
C
8

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.

Compassionate answered 5/3, 2017 at 15:32 Comment(0)
C
4

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)

Carpetbagger answered 23/4, 2014 at 16:56 Comment(0)
K
3

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

Knighthead answered 19/1, 2014 at 5:13 Comment(1)
doing $ openssl in bash works for me...but trying to run any gem command ends up in cannot load such file -- opensslDisconnection
O
2

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.

Oquendo answered 22/4, 2020 at 15:4 Comment(0)
M
1

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

I found this solution here.

Mommy answered 16/3, 2016 at 9:7 Comment(0)
O
1

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

Otway answered 25/2, 2017 at 0:4 Comment(0)
T
1

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  
Tongs answered 28/5, 2019 at 7:36 Comment(0)
T
0

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

Teledu answered 10/8, 2015 at 13:15 Comment(0)
D
0

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/

Deadening answered 2/12, 2017 at 5:43 Comment(0)
G
-3

Do you use RVM?

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

Gaze answered 18/1, 2014 at 8:25 Comment(2)
I already installed ruby from its source.So as you said to install rvm. How to do it. Whether i want to remove ruby i already installed and install ruby with help of rvm. I have no clear idea if you can tell me. what difference between install ruby from source and install by rvm. please let me know i need some good reference. Thanks :)Fluency
I'm using rvm and searching for documentation on SSL installation support. I'm going to follow @Carpetbagger 's adviceIslington

© 2022 - 2024 — McMap. All rights reserved.