Fixing SSL_connect error while installing Ruby Gems on Windows

As Windows is my primary development machine, I did a setup of Jekyll by following this guide by Julian Thilo. However, I ran into SSL_connect issues while installing the Jekyll gem.

After some research, I found out that this is an issue in Ruby and I would need to manually specify an SSL certificate file. In this post I will share the specific steps I took to resolve this SSL_connect error on my Windows machine.

Ruby SSL_connect error on Windows

After installing Ruby and Ruby Dev Kit on my machine, I ran the command gem install jekyll, however on first try it produced the following error:

> gem install jekyll
ERROR: Could not find a valid gem 'jekyll' (>= 0), here is why: 
Unable to download data from 
- SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed 

The reason why this error occurs and how to resolve it has been explained in detail by Fletcher Nichol in this gist. Find below the exact steps I took to resolve this SSL certificate verification failure on Windows.

Fixing SSL_connect error on Windows

  • Download the cacert.pem file and save this file to C:\Rails\Installer\cacert.pem
  • Open System in Control Panel
  • Go to Advanced System Settings
  • Click on Environment Variables
  • Define a new System Variable with SSL_CERT_FILE=C:\Rails\Installer\cacert.pem as shown in screen-shot below
  • Close and reopen your command prompt for allowing the changes to take place

SSL Certificate on Windows

Specifying SSL_CERT_FILE on Windows for Ruby

Now we have the SSL certificate file defined permanently in our System settings. This will allow us to install Ruby gems without anymore SSL errors. You should be able to install Jekyll as well as other Ruby gems such as Rouge, Bundle etc. In case you find the install command to be stuck for long time try running the following command to get a more verbose output.

gem install jekyll --debug -V

Hope you found this post useful and will be able to setup Jekyll on your Windows machine. :)

Kanishk Kunal

Kanishk is a Software Engineer turned Online Entrepreneur who has created many successful apps and websites. He devotes most of his time punching his keyboard and swiping his smartphone. Follow him on Twitter @kanishkkunal

This Post Has 26 Comments

    1. Avatar
      Kanishk Kunal

      While this would work, leaving out https is not really fixing the problem. Just avoiding it.

  1. Avatar

    Many Thanks!

  2. Avatar
    Pranav Sarin

    Thanks man. Lifesaver!

  3. Avatar

    Thanks a lot man!, everything is working now!

  4. Avatar

    You said save it to – C:RailsInstallercacert.pem

    So is that path or file name and Is it necessary to save only to that path?

    1. Avatar
      Kanishk Kunal

      Hi Kiran,

      That is a path and you can save it to any location. Just make sure to set the value of SSL_CERT_FILE to the location where you save the pem file.

  5. Avatar

    Hello Kanishk Kunal.
    when ever i run the command “gem install rails”, i always get this error.

    ERROR: Could not find a valid gem ‘rails’ = 0>, here is why: Unable to download data from – SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

    i tried out the solution you gave above but i still get the same error message. please kindly help me out.

    1. Avatar
      Kanishk Kunal

      Hi Amos,

      Please make sure you have correct path set for SSL_CERT_FILE.
      You can check whether you have correct environment variable set or not by running the following command in your command prompt.

      echo %SSL_CERT_FILE%

      This should output the location where your cert files are stored.

  6. Avatar

    thanks! was almost about to throw the computer into a busy street and this prevented that.

  7. Avatar

    Thank you so much :)

  8. Avatar

    Thanks. super helpful.

  9. Avatar

    Thanks for this trick. My derivative solution for my standard ruby installation (simply installed using rubyinstaller on win10 64 bits) :
    Just place the “cacert.pem” in the “rubygems/ssl_certs/” directory (in C:\ruby23-x64\lib\2.3.0 for my own installation) and that’s all.

    1. Avatar

      Gelth is right just add the cacert.pem file to the existing ‘rubygems\ssl_certs’ directory of your existing ruby installation. In my case Windows 7 and installed ruby via Chocolatey the ssl certs directory of ruby by deafult is located at ‘C:\tools\ruby23\lib\ruby\2.3.0\rubygems\ssl_certs’

      1. Avatar

        That’s where I added it, too.

      2. Avatar

        This solved it for me too. I just saved the cert into the already existing `ssl_certs` folder.

        1. Avatar

          This solution works for me as well.

    2. Avatar

      Thanks, this worked great for me. Didn’t need to set any environment variables.

    3. Avatar
      Fer Torres

      I didn’t find any working solution until I read your comment! Thank you so much!

  10. Avatar

    Thank you! I was about to give up trying to install Jekyll on Windows when I found this. Installed! Now I can start playing.

  11. Avatar

    Thanks a lot! now it works!

  12. Avatar

    Thanks very very thanks

  13. Avatar

    thanks buddy, saved a lot of time.

  14. Avatar

    Thanks Kanishk!

  15. Avatar

    Kanishk Gelth Alex thanks so much!

  16. Avatar

    it works for me, very thanks

Leave a Reply