ruby 2.0 rails gem 安装错误“无法加载此类文件 -- openssl”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15129355/
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
ruby 2.0 rails gem install error "cannot load such file -- openssl"
提问by Stephen Nguyen
I am using osx 10.8.2installed ruby 2.0and.... got this when trying to run "sudo gem install rails"
我正在使用osx 10.8.2安装的ruby 2.0并且....在尝试运行“sudo gem install rails”时得到这个
$ sudo gem install rails
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
I had ruby 1.9.x and rails 3.2.x working alright before
我之前有 ruby 1.9.x 和 rails 3.2.x 工作正常
回答by Valery Kvon
You have to install OpenSSL first and recompile ruby again:
您必须先安装 OpenSSL 并再次重新编译 ruby:
RVM:
RVM:
rvm pkg install openssl
rvm reinstall ruby-2.0.0-p0 --with-gcc=gcc-4.7 --with-openssl-dir=$rvm_path/usr
回答by xyz
If you're using RVM please follow:
如果您使用的是 RVM,请遵循:
$ brew install automake
$ rvm pkg install openssl
$ rvm requirements run
$ rvm reinstall all --force
$ gem install rails
It worked for me.
它对我有用。
回答by Pravin Mishra
I had very bad time with this ERROR. Finally i done with it. There is only Once solution either you are with RVM or without RVM.
我在这个错误上度过了非常糟糕的时光。最后我完成了它。无论您是使用 RVM 还是不使用 RVM,只有一次解决方案。
Make sure you have installed OpenSSL first BEFORE installing ruby.
确保在安装 ruby 之前先安装了 OpenSSL。
RVM
虚拟机
Uninstall rvm
rvm implode
卸载 rvm
房车内爆
or
或者
rm -rf ~/.rvm
Don't forget to remove the script calls in your .bashrc and/or .bash_profile (or whatever shell you're using). sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev curl git-core python-software-properties libpq-dev nodejs
不要忘记删除 .bashrc 和/或 .bash_profile(或您使用的任何 shell)中的脚本调用。sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev curl git-core python-software-properties libpq-dev nodejs
Then install RVM, post ruby.
然后安装 RVM,发布 ruby。
OR
或者
rvm pkg install openssl
rvm reinstall ruby-2.0.0-p0 --with-gcc=gcc-4.7 --with-openssl-dir=$rvm_path/usr
WITHOUT RVM
没有 RVM
First you should find where Ruby is:
首先,您应该找到 Ruby 的位置:
whereis ruby
will list all the places where it exists on your system, then you can remove all them explicitly. Or you can use something like this:
将列出它在您的系统上存在的所有位置,然后您可以明确删除所有这些位置。或者你可以使用这样的东西:
rm -rf /usr/local/lib/ruby
rm -rf /usr/lib/ruby
rm -f /usr/local/bin/ruby
rm -f /usr/bin/ruby
rm -f /usr/local/bin/irb
rm -f /usr/bin/irb
rm -f /usr/local/bin/gem
rm -f /usr/bin/gem
THEN
然后
sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev curl git-core python-software-properties libpq-dev nodejs
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
tar -xvzf ruby-2.0.0-p247.tar.gz
cd ruby-2.0.0-p247/
./configure --prefix=/usr/local
make
make install
I hope this help you.
我希望这对你有帮助。
回答by hjing
On OSX, with rbenv and homebrew, the following worked for me:
在 OSX 上,使用 rbenv 和自制软件,以下对我有用:
brew install openssl
CONFIGURE_OPTS=--with-openssl-dir=$(brew --prefix openssl) rbenv install whatever-ruby-version
回答by Flynn
This worked for me which is similar to some of the other answers already posted.
这对我有用,类似于已经发布的其他一些答案。
rvm pkg install openssl
rvm reinstall all --force
回答by Nikola
I had the same problem earlier, tried all of the snippets about and none of them worked out. After looking around for a bit the following worked for me:
我早些时候遇到了同样的问题,尝试了所有的片段,但没有一个成功。环顾四周后,以下对我有用:
$ rvm remove 2.0.0 # get rid of unsuccessful installation
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm install ruby-2.0.0
$ rvm --default use ruby-2.0.0
What does rvm get head --autolibs=3do exactly? I'm guess it automatically downloads dependencies, but I was hoping for a clear answer.
具体有什么作用rvm get head --autolibs=3?我猜它会自动下载依赖项,但我希望得到一个明确的答案。
回答by Robert Mackenzie
I had the same problem with the same OS version. I use rvm and followed the steps in this command:
我在相同的操作系统版本上遇到了同样的问题。我使用 rvm 并按照此命令中的步骤操作:
$ rvm requirements
Following those instructions, I ran:
按照这些说明,我跑了:
$ brew update
$ brew tap homebrew/dupes
$ brew install bash curl git
$ brew install autoconf automake apple-gcc42 libtool pkg-config openssl readline libyaml sqlite libxml2 libxslt libksba
回答by fdibartolo
When installing ruby 2.0, it is possible that rubygems 2.0 installation did not complete ok, because of openssl. Make sure you provide a valid path to the openssl config file; you could:
安装 ruby 2.0 时,可能是因为 openssl 导致 rubygems 2.0 安装没有完成。确保您提供了 openssl 配置文件的有效路径;你可以:
find . -type f -name "openssl.cnf"
path is usually $HOME/.rvm/usr or $HOME/.rvm/usr/ssl
路径通常是 $HOME/.rvm/usr 或 $HOME/.rvm/usr/ssl
Then
然后
[sudo] rvm reinstall ruby-2.0.0-p0 --with-openssl-dir=[openssl.cnf path] --verify-downloads 1
Make sure rubygems installation complete successfully. Might be a better way to fix that path without reinstalling, but this should do it.
确保 rubygems 安装成功完成。可能是在不重新安装的情况下修复该路径的更好方法,但这应该可以。
回答by Josan
Make sure to check out this page on the rvm site: https://rvm.io/packages/openssl/
请务必在 rvm 站点上查看此页面:https://rvm.io/packages/openssl/
Running
跑步
rvm requirements run
rvm requirements run
gave me:
给我:
Missing required packages: autoconf, automake, libtool, pkg-config, apple-gcc42, readline, libxml2, libxslt, libksba, openssl, sqlite
Missing required packages: autoconf, automake, libtool, pkg-config, apple-gcc42, readline, libxml2, libxslt, libksba, openssl, sqlite
after brew install autoconf automake ...
后 brew install autoconf automake ...
I was able to rvm reinstall 2.0.0without openssl errors
我能够rvm reinstall 2.0.0没有 openssl 错误
回答by Adam Prax
I encountered the same openssl error on Fedora when trying to use gem install <package>. It seems you need to install additional packages with yum/dnf
我在 Fedora 上尝试使用gem install <package>. 看来您需要使用 yum/dnf 安装其他软件包
sudo dnf install rubygems rubygem-bundler ruby-devel mariadb-devel
After running the above command, gem install <package>should now work.
运行上述命令后,gem install <package>现在应该可以工作了。

