问题描述:

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?

网友答案:

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

网友答案:

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

I reconfigured ruby using:

./configure --with-openssl-dir=/usr/bin (following the suggestion of jspacek)

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

网友答案:

make sure you have libssl-dev installed:

dpkg -s libssl-dev

if not, install it:

sudo apt-get -y install libssl-dev
网友答案:

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)

网友答案:

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

网友答案:

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

网友答案:

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

网友答案:

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

I found this solution here.

网友答案:

Do you use RVM?

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

相关阅读:
Top