Can't access RubyGems - possibly due to SSL? [duplicate]

New Ruby on Rails dev here, just trying to install and get set up.

I'm following this guide on how to get started. However, when I get to 3.2 Creating the Blog Application, I run into an issue when I run rails new blog. When I try that, I get an error that says

An error occurred while installing rake 10.4.2, and Bundler cannot continue. Make sure that 'gem install rake -v '10.4.2'' succeeds before bundling.

So, when I try to run that command, I get this error:

ERROR: Could not find a valid gem 'rake': Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

After Googling around, I found this guide. During the diagnosis portion, I tried running openssl version, which didn't work. I installed OpenSSL and added it to my path. However, I still get the same error when I try to fetch any gems. I also can't ping rubygems.org - nothing comes back.

I'm using Windows 7, Rails 4.1.8, Ruby 2.0.0p598, RubyGems 2.0.14, and OpenSSL 1.01j. Any help would be greatly appreciated!


Solution 1:

Here is a quick solution:

Go to your gem file and change

source 'https://rubygems.org' 

to

source 'http://rubygems.org' #remove the 's' 

Check this similar question on StackOverflow for more solutions and insights into the error :)

Edit:

Based on inputs by @Anthony in the comments below, here is a more permanent solution :

Download : AddTrustExternalCARoot-2048.pem.(Note: File must have .pem as extension. Browsers like Chrome will try to save it as plain text file. Ensure you change the filename to have .pem in it after you have downloaded it.)

Now Run the following in your command prompt:

C:\>gem which rubygems

Thiw will give you a path where you need to place the above .pem file. Navigate inside the directory to which the path points. Inside it locate ssl_certs directory and copy the .pem file we obtained from previous step inside.

This shall do the trick!

Solution 2:

It's specific to a windows permission issue, you can read the entire scope of the issue here

For the tl;dr -

Step 1: Obtain the new trust certificate

Download: AddTrustExternalCARoot-2048.pem

Step 2: Locate RubyGems certificate directory in your installation

C:\>gem which rubygems
C:/Ruby21/lib/ruby/2.1.0/rubygems.rb

We want to open the path listed above:

C:\>start C:\Ruby21\lib\ruby\2.1.0\rubygems

Step 3: Copy new trust certificate

Now, locate ssl_certs directory and copy the .pem file we obtained from step 1 inside.