LearnHow to Install Rails 5 on Windows

Treehouse
writes on August 2, 2016

While setting up for the Treehouse Rails 5 Basics course, we’re also updating our installation help workshops to cover Rails 5. We figured we’d share those directions here, as a little nudge for those of you who still haven’t discovered how awesome Rails is.

We’ve set up guides for 3 different operating systems:

We’re not going to mess with installing a fancy database, alternate testing frameworks, or anything like that; this is an easy, bare-bones installation that will let you try Rails and see if it’s right for you.

  • We’ll use a program called “Ruby Installer” to install the Ruby programming language.
  • Then we’ll use Rubygems, a tool that’s included with our Ruby installation, to automatically download and install the Rails library.
  • We’ll install a Ruby “Development Kit” that Rails needs to work correctly.
  • Lastly, since Rails includes several JavaScript-based features, we’re going to need a JavaScript runtime. So we’ll install Node.js.

Ready? Let’s get started!

Ruby

First, we need an installation of the Ruby programming language. We’re going to use a precompiled version of Ruby called Ruby Installer.

  • Download and run Ruby Installer from rubyinstaller.org. (For convenience, we linked directly to the version you need. The rubyinstaller.org site hosts its files on bintray.com.)
  • Allow the download to finish, then go to your Downloads folder, and open the “rubyinstaller” program. An installation wizard will open. Check “Add Ruby executables to your PATH”, then click Install. Wait while the installer runs, and click Finish when done.
  • To access Ruby, go to the Windows menu, click All Programs, scroll down to Ruby, and click “Start Command Prompt with Ruby”. A command prompt terminal will open. If you type ruby -v and press Enter, you should see the Ruby version number that you installed.

Ruby Development Kit

At this point, we could attempt to install Rails. But some of the libraries Rails depends on need some “build tools” in order to be compiled, and Windows lacks those tools by default. (You’ll know this is happening if you see an error when attempting a Rails install: “Gem::InstallError: The ‘[gem name]’ native gem requires installed build tools.”) To fix this, we need to install the Ruby “Development Kit”, which includes those build tools.

  • Download the Ruby Development Kit. (This download also originates from rubyinstaller.org, and is also hosted on bintray.com.)
  • When it’s done, go to your downloads folder and double-click the DevKit executable.
  • We need to specify a folder where we’re going to permanently install the DevKit. I recommend installing it in the root of your hard drive, at “C:\RubyDevKit“. (Don’t use spaces in the directory name.)

Now we need to make the DevKit tools available to Ruby.

  • Back in your command prompt, change to the the DevKit directory. (“Directory” is another name for a folder.) Type “cd C:\RubyDevKit“, or whatever other directory name you installed it in.
  • Next we need to run a Ruby script to initialize the DevKit setup. Type “ruby dk.rb init“.
  • Now we’ll tell that same script to add the DevKit to our Ruby installation. Type “ruby dk.rb install“.

The DevKit should now be available for your Ruby tools to use when installing new libraries.

Rails

Now it’s time to install Rails. Rails comes as a Ruby “gem”. A gem is a library, a collection of reusable code, that can be automatically downloaded and installed on your system, using the “gem” tool. In your command prompt, type:

gem install rails --version 5.0.0

This will ensure you’re downloading the correct version of the gem. Once you press Enter, the “gem” program will download and install that version of the Rails gem, along with all the other gems Rails depends on.

Node.js

One last thing. . . Some libraries that Rails depends on require a JavaScript runtime to be installed. Let’s install Node.js so that those libraries work properly.

  • Download the Node.js installer.
  • When the download completes, visit your downloads folder, and run the “node-v4.4.7.pkg” installer.
  • Read the full license agreement, accept the terms, and click Next through the rest of the wizard, leaving everything at the default.
  • A window may pop up asking if you want to allow the app to make changes to your computer. Click “Yes”.
  • When the installation is complete, you’ll need to restart your computer so Rails can access Node.js.

Once your computer restarts, don’t forget to go to the Windows menu, click “All Programs”, scroll down to Ruby, and click “Start Command Prompt with Ruby”.

That’s it!

You should be ready to create your first Rails app!

You’ll want to check out our Rails 5 Basics course for an in-depth guide to getting started. Rails is a powerful, productive framework, and after you play with it a bit, we’re betting you’ll love it.

Start learning to code today with a free trial on Treehouse.

15 Responses to “How to Install Rails 5 on Windows”

  1. Anisio on April 5, 2017 at 7:31 pm said:

    I solved the problem for install gem rails for me
    Download Ruby gems zip
    https://rubygems.org/pages/download
    extract
    open command prompt on folder
    run $ruby setup.rb
    and them
    gem install –local

    After this work to install gem rails

  2. Dave McGrath on March 20, 2017 at 10:19 am said:

    I ended up with an unable to install due to SSL certificate error:
    “SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed”

    And solved it by following the instructions here:
    https://superdevresources.com/ssl-error-ruby-gems-windows/

  3. Just in case this trips anybody else up… Make sure the cacert.pem file has not saved as a .txt file. If it is – you can open it in notepad and save it without the .pem extension. Then find it in the folder and rename it (add the .pem extension).

  4. Paul van Gils on November 10, 2016 at 1:43 am said:

    When trying to install rails 5.0.0 i get this error:

    C:\RubyDevKit>gem install rails –version 5.0.0
    ERROR: Could not find a valid gem ‘rails’ (= 5.0.0), here is why:
    Unable to download data from https://rubygems.org/ – SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/specs.4.8.gz)

    i did a ruby gem update but i still can’t get it to work

  5. I don’t know why it doesn’t work for me 🙁

  6. Ksaveras on August 7, 2016 at 12:22 pm said:

    You forgot bcrypt problems on Windows. There are lot of complains about Windows ruby and bcrypt.

    • Probably moved on now but after 4 hours trying to get rails working and then another hour having this bcrypt issue i resolved it by moving from 64 bit to 32 bit ruby

  7. Peter Camilleri on August 4, 2016 at 6:30 pm said:

    I’m not 100% sure, but I’m pretty sure the devkit needs to be installed before rails so that gems with ‘C’ extensions will build correctly.

    • Peter Camilleri on August 4, 2016 at 6:33 pm said:

      What I mean is, why install Rails when you know it will likely fail?

      • Jay McGavren on August 9, 2016 at 7:21 am said:

        In the installation video, we’re including an attempt to install Rails without DevKit pre-installed to demonstrate what can go wrong. But that may just be more confusing in blog format. I’ve modified the order of the installation instructions accordingly. Thanks for the feedback!

  8. Andy Gray on August 3, 2016 at 10:52 am said:

    The link for Node in the text downloaded a .pkg file rather than an .msi… 🙂

Leave a Reply

You must be logged in to post a comment.

Want to learn more about Ruby?

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. Learn how to build a website using Ruby and the Rails framework.

Learn more