Install Ruby and Rails on Windows - SEIR-59/course-wiki GitHub Wiki

Install Ruby and Rails on Windows

Introduction

Ruby is a high-level programming language we will use in the later units of this course. While learning Ruby, we will dive into building backend servers using a 'gem' called Rails (commonly called Ruby on Rails). These technologies were designed for UNIX-like systems, like Linux and macOS -- not Windows. That means in order to get Ruby on Rails working, we need to set up a UNIX-like environment on our device.

You have a few options for how to achieve this:

  • Create a Virtual Machine (Tricky to set up, but always works and easy to use)
  • Create a Windows Subsystem for Linux (Easy to set up, but has lots of bugs... I gave up on trying to make this work, but maybe you have better luck)
  • Dual Boot Windows and Linux (Fairly straightforward, but difficult to switch between Linux and Windows)

Or if you do not care about running Rails and simply want to execute .rb files, check out RubyInstaller 2

Virtual Machine

  1. Install the latest version of VirtualBox and run through the
  2. Download the latest LTS version of Ubuntu (you should end up with an .iso file in your Downloads folder)
  3. Follow this tutorial on setting up the Linux VM

Troubleshooting Resources:

You will likely run into issues while setting up your VM, but fear not! The internet has already encountered all of your problems before. Here are some things I found helpful in my quest.

The reason errors are so common in setting up a VM is that you need to configure the Settings correctly based on your specific computer. Having a different version of Windows, processor, graphics card, BIOS settings, or other computer settings can make all the difference.

After you encounter an error, check the Logs in VirtualBox to see if you have any errors or concerning messages. It may be tedious to read through, so try using the search tools at the top of the window to Find/Filter anything with the word "Error", "Warning", "!", or anything else the internet tells you to.

  • I was getting a black screen with a curser after starting the VM and pressing "Install Ubuntu". I was also getting this message in the Logs: NEM: Disable Hyper-V if you need X2APIC for your guests!. I fixed it by...
    • In Settings > Display > Screen, set the "Monitor Count" to the number of monitors currently plugged in, and increase the "Video Memory" to 64 GB
    • Disable Hyper-V and restart computer

If you encounter any other errors and find solutions, feel free to add them here

RubyInstaller 2 for Windows (Not recommended)

WARNING: I am not sure how to make Rails (or any gem) work using this method. The only reason you might use this method is to execute simple .rb files from Command Prompt or Git Bash.

Use Ruby Installer to Install Ruby

  1. Download Ruby+Devkit 2.7.X (x64) from RubyInstaller
  2. Run the installer
  3. The following command prompt should open at the end of the installation. Hit enter to finish installing.

     RubyInstaler2 for Windows 1 - MSYS2 base installation; 2 - MSYS2 system update (optional); 3 - MSYS2 and MINGW development toolchain; Which components shall be installed? If unsure press ENTER [1,3]
  4. Confirm your installation by opening the Windows Command Prompt and running ruby -v. The output should look something like this:
    ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
    

Give Git Bash Access to Ruby

  1. Open ~/.bashrc or ~/.bash_profile in a text editor (if you do not have either, you will need to make one).
  2. Add this line (you may need to adjust it to match the exact file path to Ruby's bin folder):
    PATH=$PATH:/c/Ruby27-x64/bin
    
  3. Confirm that this worked by restarting Git Bash and running ruby -v. The output should look something like this:
    ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
    
⚠️ **GitHub.com Fallback** ⚠️