Lesson Weekend

Students using PC machines with Windows tend to run into problems installing all the tools necessary for the Ruby and Rails course. Why? There is no "one size fits all" installation setup for Windows machines. Installations can have errors and it can take some time and persistence to get Ruby set up on a Windows machine.

However, many students have gone through the Ruby and Rails course using Windows, and you can do it too! Keep in mind that there will be an in-class troubleshooting session where you can get help from your peers and your teacher. Our best recommendation is to take detailed notes on any issues that come up, the troubleshooting steps you took to address those issues, and any helpful resources you found along the way. You can share these notes with your peers, and they can share their notes with you!

Next up, we'll cover two installation options for installing Ruby.

Using Windows Subsystem for Linux


If you are interested in Linux or have previous experience with using it, you can consider using the Windows Subsystem for Linux. It is much easier to set up all the tools you'll need for Ruby and Rails within the Windows Subsystem for Linux. The downside, however, is that you'll need to teach yourself quite a bit about Linux! We don't provide Linux support at Epicodus so this option is best for students that are motivated to learn Linux on their own.

There are a lot of resources online for using the Windows Subsystem for Linux (WSL) to install Ruby and Rails on Windows 10 and up. We recommend doing some research and reading through some of the online guides to get a sense of using WSL. This can help you decide whether or not to pursue this route. Here are some resources to get you started:

The Way We've Always Installed Ruby and Rails on Windows


The following installation instructions cover what you need to do to set up all the Ruby tools you need on your Windows machine. Keep in mind that our instructions are broad because there's no "one size fits all" installation setup for Windows machines. It's likely that you will run into problems that you will have to troubleshoot. This is the approach we used for many years and it does work.

On Windows, the easiest way to install Ruby is with the RubyInstaller, which includes Ruby and a few other tools we'll use throughout these lessons. Make sure to install the Ruby+Devkit 2.6.9-1 version, to have a compatible version with the tools used in the curriculum. There is both a 64 bit (x64) and 32 bit (x86) version available. The built-in System Information program on Windows machines has information on which System Type your machine is using. Because the instructions on where to find this information vary based on your Windows version, if you don't know how to find this information, we recommend a quick Google search to determine with version you should download.

After you've downloaded the correct Ruby+Devkit 2.6.9-1 from RubyInstaller, you should run the installer and follow along with the installation prompts. We recommend selecting the defaults for all options, except we don't recommend downloading the Ruby documentation. Why? There's better documentation is available online.

Generally speaking, we recommend reading through terminal output and any error logs that come up in the installation process, as they can point what to look into that may be missing or causing an issue.

Verify Your Ruby Installation

In your GitBash, run this command:

$ ruby -v

You should get a response similar to: ruby 2.6.9p207 (2021-11-24 revision 67954) [x64-mingw32].

Also, confirm that you can acces IRB (a REPL, which we'll learn more about soon):

$ irb
irb(main):001:0>

To exit IRB, enter exit.

Resolving the Error this input device is not a TTY

Some Windows users run into issues using irb. When accessing irb and you get an error similar to this one:

the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'.

This happens to some Windows users when they try to start an interactive terminal. This interactive terminal could be for Node, Ruby, Rails or another technology. The solution to this issue is exactly what the message suggests: prefix the command with winpty.

Using our example of accessing irb, the command should look like this:

$ winpty irb

So, what's happening here? Under the hood, Git Bash uses MinTTY as a terminal emulator, and MinTTY is not compatible with Windows console programs. This is where winpty comes in. winpty is a program that provides an interface so that software like MinTTY can communicate with Windows console programs. When we spin up an interactive terminal like irb on Windows, it sometimes runs into this communication issue and needs the help of winpty.

So, anytime you see the message about prefixing a command with winpty, do just that.

Alternatively, you can enter this command in GitBash so that it automatically handles this issue:

$ echo $'alias irb=\'winpty "$(which irb).cmd"\'' >> ~/.bash_profile

What this code does is set up an alias for the irb command, so that every time you enter irb in GitBash, it actually executes winpt irb.

Install Rails

Finally, verify that you can install Rails at the same version we use at Epicodus:

$ gem install rails -v 5.2.0

Then, verify that Rails is working by navigating to the desktop and creating a new project:

$ rails new test_project

It will take a little time for Rails to spin up a new project. After you confirm the project has been created, delete the test_project directory.

And with that, you're ready to go!

Possible Rails Install Error with freedesktop.org.xml

When installing Rails and you get an error similar to this one:

Could not find MIME type database in the following locations:
["/usr/local/share/mime/packages/freedesktop.org.xml",
"/opt/homebrew/share/mime/packages/freedesktop.org.xml",
"/opt/local/share/mime/packages/freedesktop.org.xml",
"/usr/share/mime/packages/freedesktop.org.xml"]

Ensure you have either installed the shared-mime-info package for your
distribution, or
obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to
the location
of that file.

Try following these troubleshooting steps based off of this Stack Overflow:

  • Open GitBash, and enter touch ~/freedesktop.org.xml
  • Next enter code ~/freedesktop.org.xml to open this new file in VS Code.
  • Copy and paste the contents of this website into the freedesktop.org.xml file, save, and exit.
  • Next, enter this into GitBash: echo 'export FREEDESKTOP_MIME_TYPES_PATH="/c/Users/brook/freedesktop.org.xml"' >> ~/.bash_profile
  • Next, restart GitBash with source ~/.bash_profile (or just restart your GitBash).
  • Next, retry the rails installation: gem install rails -v 5.2.0

Optionally, Install Ruby Version Manager


As long as Windows users have installed Ruby+Devkit 2.6.9-1, there should be no need for a version manager for the Ruby/Rails curriculum at Epicodus. However, you should consider installing a Ruby Version Manager at some point so that you can switch between Ruby versions, especially if for your internship you will be working with Ruby. For this, we recommend Ruby Version Manager, a Ruby version manager that is compatible with Windows.

Why Use A Version Manager?

In an ideal world, developers would always use the latest, most perfect version of a language. In reality, updating older projects is often a huge pain point, especially in very large or dated projects. The version of Ruby you use for projects now will likely be different from the one you use a year from now, which in turn will be different from the version you use five years from now. However, you may still need to maintain past projects (especially if they're work-related), which means you'll need the ability to switch between different versions of Ruby in your personal environment.

This issue may also come up at Epicodus particularly for Mac users. Macs come with a version of Ruby that is installed globally, and this may conflict with the version of Ruby that we use in the coursework. You shouldn't be expected to downgrade the Ruby version in your global environment in order for your projects to be compatible with Epicodus coursework; however, you should be able to use the same version we use at Epicodus. After all, it would be poor etiquette in the workplace to expect your work to use your version of Ruby instead of the other way around!

Like we mentioned above for Windows users, it's not important to have a Ruby version manager for the Ruby/Rails coursework, as long as Windows users have installed Ruby+Devkit 2.6.9-1. However, it is important to get a version manager installed at some point, especially if you plan on contributing to open source Ruby projects or doing an internship that focuses on Ruby.

Lesson 4 of 7
Last updated March 31, 2022