无法在 ruby​​ 中要求 openssl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21201493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:22:04  来源:igfitidea点击:

Couldn't require openssl in ruby

rubyopensslrubygems

提问by Siva Gnanam

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

我在我的虚拟机 ubuntu12.04lts 中安装了 openssl。

When I run the gem command it gives error.

当我运行 gem 命令时,它会出错。

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

错误:执行 gem (Gem::Exception) 时
无法要求 openssl。安装 openSSL 并重建 ruby​​(首选)或使用非 HTTPs 源

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

而且我还在 irb 模式下测试了 require openssl。它给出了错误。

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

加载错误:无法
从 /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55 `require'加载此类文件 --openssl

I have openssl

我有openssl

$openssl version
OpenSSL 1.0.1 14 mar 2012

How to fix the error?

如何修复错误?

回答by jspacek

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

注意:不推荐调用 ruby​​gems.org - 谨慎操作!

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:

在从源代码构建 ruby​​2.1.0p0 之后,我在 Mac OSX 上遇到了同样的问题。我已经安装了openssl。看来 gems 中的引用需要刷新。我跑了:

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

gem source -r https://rubygems.org/去除

followed by

其次是

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

gem source -a https://rubygems.org/阅读

After this, I was able to run gems install bundlersuccessfully.

在此之后,我能够gems install bundler成功运行。

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

如果遇到更多错误,可以尝试./configure --with-openssl-dir=/usr/local/ssl在 ruby​​ 下载的 dir/.

回答by Toni Letendre

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

我在使用 debian 时遇到此错误,其中 openssl 位于 /usr/bin 中。

Following the suggestion of jspacek I reconfigured ruby using:

按照 jspacek 的建议,我使用以下命令重新配置了 ruby​​:

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

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

在 make 和 sudo make install 之后,我能够安装 rails。

回答by kitteehh

make sure you have libssl-dev installed:

确保你已经安装了 libssl-dev:

dpkg -s libssl-dev

if not, install it:

如果没有,请安装它:

sudo apt-get -y install libssl-dev

回答by The Whiz of Oz

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

如果其他人遇到此问题,请尝试重新安装包含 openssl 的 Ruby 版本

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.

您可能已经拥有 openssl - 因此您可以忽略第一步。这对我有帮助。

回答by notaceo

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

我将这个答案留给未来的 Google 员工参考:

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

在您的终端 (OSX) 中键入所有这些命令,以确保您已完成所有操作(这最终对我有用)

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)

正如许多评论者指出的那样 - 在安装 rails(或其他 gem)之前,您需要先安装 OpenSSL,然后再编译 ruby

回答by David Grayson

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

您可能在安装 OpenSSL 之前从源代码构建了 Ruby。确保安装它,然后尝试重新配置和重建 Ruby。

回答by Justus

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

运行后重建 Rubysudo apt-get install libssl-dev libreadline-dev libgdbm-dev可以解决这个问题。

I found this solution here.

我在这里找到了这个解决方案。

回答by mmell

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

使用 RVM 安装 Ruby 时出现此错误。没有任何效果。我切换到rbenv。问题解决了!

回答by infinite-etcetera

for me it was a case of missing dependencies.

对我来说,这是缺少依赖项的情况。

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

以为我拥有安装 ruby​​ 所需的所有依赖项,但我也遇到了 openSSL 和 readline 错误。

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

我试图在没有 root 权限的情况下使用 RVM 安装 ruby​​,但失败了,但给了我一个缺少依赖项的列表。然后我用包管理器安装了依赖项。然后我重新尝试从一开始就从源代码安装 ruby​​,一切正常

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

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

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

回答by Sudhanshu Mishra

These steps worked for me:

这些步骤对我有用:

  1. Fixed ruby install:

    brew upgrade openssl; openssldir=which opensslrvm 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/

  1. 固定 ruby​​ 安装:

    brew 升级 openssl; openssldir= which opensslrvm 重新安装 ruby​​-2.4.2 --with-openssl-dir=$openssldir

  2. 删除并重新添加了宝石的来源

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