gem安装失败,出现openssl错误

63

我试图在我的OSX Mountain Lion上安装CocoaPods (http://cocoapods.org/)。

 moshe-mbp:~ moshem$ gem install cocoapods
 ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
      Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0      state=SSLv3 read server key exchange B: bad ecpoint (https://rubygems.org/latest_specs.4.8.gz)

首先我尝试了

 rvm reinstall all --force

然后我尝试了

 brew upgrade openssl

    ==> Upgrading openssl
    ==> Downloading http://openssl.org/source/openssl-1.0.1e.tar.gz
    Already downloaded: /Library/Caches/Homebrew/openssl-1.0.1e.tar.gz
    ==> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1e --openssldir=/usr/local/etc/openssl zlib-dynamic shared d
    ==> make
    ==> make test
    ==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1e/share/man MANSUFFIX=ssl
    ==> Caveats
    To install updated CA certs from Mozilla.org:

        brew install curl-ca-bundle

    This formula is keg-only: so it was not symlinked into /usr/local.

    Mac OS X already provides this software and installing another version in
    parallel can cause all kinds of trouble.

    The OpenSSL provided by OS X is too old for some software.

    Generally there are no consequences of this for you. If you build your
    own software and it requires this formula, you'll need to add to your
    build variables:

        LDFLAGS:  -L/usr/local/opt/openssl/lib
        CPPFLAGS: -I/usr/local/opt/openssl/include

    ==> Summary
      /usr/local/Cellar/openssl/1.0.1e: 429 files, 15M, built in 5.1 minutes

接着我尝试了

openssl version

仍然拥有旧版本(!)

moshe-mbp:~ moshem$ openssl version
OpenSSL 0.9.8r 8 Feb 2011
moshe-mbp:~ moshem$ 

我做错了什么?如何安装CocoaPods gem?

谢谢


编辑,尝试@sean的建议:

moshe-mbp:~ moshem$ brew update
Updated Homebrew from 672af665 to 10b4d426.
==> Updated Formulae
bash        wireshark
moshe-mbp:~ moshem$ brew install openssl
Error: openssl-1.0.1e already installed
moshe-mbp:~ moshem$ brew link openssl --force
Linking /usr/local/Cellar/openssl/1.0.1e... 1139 symlinks created
moshe-mbp:~ moshem$ brew install curl-ca-bundle
Error: curl-ca-bundle-1.87 already installed
moshe-mbp:~ moshem$ 
moshe-mbp:~ moshem$ openssl version
OpenSSL 0.9.8r 8 Feb 2011
moshe-mbp:~ moshem$ gem install cocoapods
ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server key exchange B: bad ecpoint (https://rubygems.org/latest_specs.4.8.gz)

修正brew doctor问题后,进行了编辑(2)

moshe-mbp:~ moshem$ gem install cocoapods
ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server key exchange B: bad ecpoint (https://rubygems.org/latest_specs.4.8.gz)
moshe-mbp:~ moshem$ openssl version
OpenSSL 0.9.8r 8 Feb 2011
moshe-mbp:~ moshem$ brew update
Updated Homebrew from 10b4d426 to 6a00bc3c.
==> Updated Formulae
clozure-cl  python  python3
moshe-mbp:~ moshem$ brew install openssl
Error: openssl-1.0.1e already installed
moshe-mbp:~ moshem$ 
moshe-mbp:~ moshem$ echo $PATH
/Users/moshem/.rvm/gems/ruby-2.0.0-p0/bin:/Users/moshem/.rvm/gems/ruby-2.0.0-p0@global/bin:/Users/moshem/.rvm/rubies/ruby-2.0.0-p0/bin:/Users/moshem/.rvm/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/tools:/platforms:/platform-tools:
moshe-mbp:~ moshem$ 

在修改了/etc/paths文件后进行编辑。

我将/etc/path文件编辑为:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

关闭终端并重新打开,仍然会启动旧版本的openssl!

为什么?

moshe-mbp:~ moshem$ env $PATH
env: /Users/moshem/.rvm/gems/ruby-2.0.0-p0/bin:/Users/moshem/.rvm/gems/ruby-2.0.0-p0@global/bin:/Users/moshem/.rvm/rubies/ruby-2.0.0-p0/bin:/Users/moshem/.rvm/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/tools:/platforms:/platform-tools

编辑我的bash_profile文件

source "`brew --prefix grc`/etc/grc.bashrc"

export PATH=${JAVA_HOME}/bin:$PATH
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platforms:$ANDROID_SDK/platform-tools:$ANDROID_NDK"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

顺便说一句,在我的计算机上似乎不存在/etc/grc.bashrc文件。这行和最后的rvm行都是由安装脚本添加的。


编辑

moshe-mbp:~ moshem$ rvm pkg install openssl 
Fetching openssl-1.0.1c.tar.gz to /Users/moshem/.rvm/archives
Extracting openssl to /Users/moshem/.rvm/src/openssl-1.0.1c
Configuring openssl in /Users/moshem/.rvm/src/openssl-1.0.1c.
Compiling openssl in /Users/moshem/.rvm/src/openssl-1.0.1c.
Installing openssl to /Users/moshem/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Updating openssl certificates
moshe-mbp:~ moshem$ openssl version
OpenSSL 1.0.1e 11 Feb 2013


moshe-mbp:~ moshem$ gem source -r http://rubygems.org/
http://rubygems.org/ removed from sources
moshe-mbp:~ moshem$ gem source -a https://rubygems.org/
Error fetching https://rubygems.org/:
    SSL_connect returned=1 errno=0 state=SSLv3 read server key exchange B: bad ecpoint (https://rubygems.org/specs.4.8.gz)
moshe-mbp:~ moshem$ gem install cocoapods
ERROR:  Could not find a valid gem 'cocoapods' (>= 0) in any repository

1
你最终解决了这个问题吗?我遇到了同样的问题。Gem源的方法对我没用。 - Paul Hoffer
还没有,仍然存在问题... - Moshe Marciano
2
仅作为附加信息:当使用Ruby时遇到SSL错误,请运行gem update --system --source http://rubygems.org/以更新所有内容,包括rubygems gem。这对我很有效。 - RaphaelDDL
11个回答

78

通过避免使用https,改用不安全的http来解决这个问题。对我而言,这种方法有效。

gem source -a http://rubygems.org/

17
正如回答所示,这是“不安全的”。 - mpapis
3
如果有其他人看到这条信息:请删除旧的源。运行命令 "gem source -r https://rubygems.org/"。 - Peach Passion

55
rvm osx-ssl-certs update all

对我起了作用,Ruby 2.0.0


3
由于某些原因,我的/etc/openssl权限设置不正确。修复方法:sudo chmod og+rw /etc/openssl。(如果您像我一样遇到了权限问题,请运行上述命令以实际修复)。这条评论是为其他人而写的,而不是答案的作者。 - Joe Johnson
什么鬼?我有Ruby 2.3,但我得到了这个 rvm osx-ssl-certs update all *** ERROR Unknown command line option: "osx-ssl-certs" - kayleeFrye_onDeck

39

尝试使用 http://rubygems.org/(不使用 SSL)作为源 - 这对我来说修复了错误。

gem source -r https://rubygems.org/
gem source -a http://rubygems.org/
gem install cocoapods

2
这个有效...谢谢!但我感觉像是在作弊,因为我的openSSL安装仍然有问题,可能会影响到我的机器上的其他东西。 - Moshe Marciano
2
这个答案比被接受的那个略微好一些,因为它包括了删除安全源这一步骤。当我尝试使用被接受的答案时,只是添加了不安全的源,安装命令仍然会因为原始错误而失败,因为安全源仍然在源列表中并且首先被使用。 - Mr. Lance E Sloan
两年了,但是一切运行得很顺利,除了我需要输入“sudo gem install cocoapods” :) - Erik Bean
1
无法运行 $ gemsource。提示 OpenSSL 无法加载。 - Daniel Lizik

26

当前发布的rvm在处理这些事情方面做得更好,运行以下命令:

rvm get head
rvm reload
rvm autolibs enable
rvm reinstall 1.9.3 --disable-binary

请确保遵循显示的任何指示——所有这些都是为了帮助您。


11

我也遇到了同样的错误。为了解决问题,请运行以下命令(我知道你已经运行过一些,但请尝试):

brew update
brew install openssl
brew link openssl --force
brew install curl-ca-bundle

之后,打开一个新的shell或者源文件,这样一切都应该没问题了 :)

更新:

要更新你的路径,你需要编辑你的/etc/paths文件,所以可以像这样做:

sudo vim /etc/paths
在那里,它应该看起来像这样:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

您想要做的是确保 /usr/local/bin 在文件顶部。因此请将其更改为以下内容:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

希望这能解决问题!


你尝试过打开一个新的shell窗口,结果一样吗?这也可能是路径的问题。brew doctor有给你任何建议吗? - Sean
看起来它正在使用 /usr/bin/openssl 中的旧版本,你能告诉我需要做什么来使该路径指向新版本吗? - Moshe Marciano
我更新了我的答案,告诉你如何更改路径。希望这次终于解决了! - Sean
刚试了一下,确实是相反的情况,但是改变后仍然不起作用!我已经更新了我的问题并附上了结果。 - Moshe Marciano
我很困惑。最后一件要尝试的事情是:'brew tap raggi/ale' 然后 'brew install openssl-osx-ca'。 - Sean
显示剩余6条评论

10

更新于2021年5月20日:Rubygems更改了他们使用的证书。我已更新证书链接,但我没有确认这个解决方案是否仍然有效。

对我有用的解决方法是:

安装此证书:https://raw.githubusercontent.com/rubygems/rubygems/master/lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem

将证书放在此文件夹中:
{rubyfolder}\lib\ruby\x.x.x\rubygems\ssl_certs

这样您就不必添加不安全的来源。

更多信息请参见:https://www.develves.net/blogs/asd/2016-04-08-rubygems-and-ssl/


问题已经为我解决了。谢谢。 - GFoley83
1
这也适用于安装了Chocolately的Ruby 2.1.0的Windows 8.1。 - Ciryon
这两个链接对我来说都是404错误。 - Watchdog101
1
@Watchdog101 我已经更新了链接,但我不确定这个解决方案是否过时。 - gijswijs

5
如果您在中国,请尝试使用http://ruby.taobao.org/作为源——这对我来说修复了错误。同时,避免使用https。这个运行对我有用。
gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
gem install cocoapods

4
以下内容让我成功解决了问题!
rvm get stable

brew update

brew install libyaml
brew install pkg-config 
brew install libxml2 
brew install libxslt

brew install openssl
brew link openssl --force

brew install sqlite

brew install apple-gcc42

rvm install 2.0.0 --with-gcc=gcc-4.2

如果这个方法不奏效,那么请先卸载您现有的 rubygems,并按照以下步骤操作:
rvm remove 2.0.0
rvm get head --autolibs=3
rvm requirements

#At this point, brew install anything that's missing, like apple-gcc42.

rvm install 2.0.0 --with-gcc=gcc-4.2

完成了,谢谢!但是现在我尝试返回https gem源代码以利用我的更新的openssl。但它不接受,可以在我的问题底部看到终端输出。 - Moshe Marciano
啊,好的,我们重新开始吧。请检查我的更新答案。我也遇到了与openssl证书相关的问题,但是按照我提到的步骤解决了。如果这个方法不行,我就不知道还能建议什么了 :/ 请在新的终端窗口中测试一下。 - Scotty
运行 rvm pkg install openssl 然后运行 rvm requirements 确保没有需要的依赖。最后运行 rvm install 2.0.0 --with-gcc=gcc-4.2 - Scotty
好的...这让我们向前迈进了一步,但安装仍然失败了...请参见此处:https://gist.github.com/moshem/5180485 - Moshe Marciano
你能提供下一步吗? - Moshe Marciano
显示剩余2条评论

2

您可以先安装一个更新的openssl,就像Mike Slutsky所描述的那样。 检查您的openssl版本:

$ openssl version

在这里获取更新版本: http://www.openssl.org/source/ 然后进行配置和安装:

$ cd openssl-1.0.1f_src/
$ ./Configure --prefix=/Users/me/bin/openssl-1.0.1f_bin darwin64-x86_64-cc
$ make install

现在使用这个openssl配置ruby:
$ cd ruby-2.1.0_src/
$ ./configure --with-openssl-dir=/Users/me/bin/openssl-1.0.1f_bin --prefix=/Users/me/bin/ruby-2.1.0_bin

注意:新的openssl不需要在您的$PATH上。 这对我来说适用于ruby 2.0和2.1。祝你好运(-:

1
您可以尝试从源代码更新OpenSSL:
curl -L -O http://www.openssl.org/source/openssl-1.0.1b.tar.gz.asc
curl -L -O http://www.openssl.org/source/openssl-1.0.1b.tar.gz
gpg --verify openssl-1.0.1b.tar.gz.asc
tar xvzf openssl-1.0.1b.tar.gz
cd openssl-1.0.1b
perl ./Configure shared zlib --prefix=/opt/local darwin64-x86_64-cc
make
make test
sudo make install

{{链接1:源代码}}


已经完成,但仍在使用旧版本... OpenSSL版本为0.9.8r,发布于2011年2月8日。 - Moshe Marciano
我认为不需要任何指向,它应该立即生效或在打开新终端后生效,我不确定为什么它没有起作用。 - Mike S
那么,这个问题有解决方案吗?如果有,是什么呢? - lucasrizoli

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接