Rails Installation Guide - Windows
It’s a bit tedious to setup Ruby and Rails on Windows. Windows doesn’t have a package manager built in, and doesn’t have support for some native gems. But Ruby development is still possible, and for the purposes of this book, it’s perfectly fine to use.
This guide has been verified with Windows 10, Ruby 2.6.6 and Rails 6.0.2.
We’ll be taking the approach of installing Ruby via RubyInstaller, and then installing DevKit that enables you to build many of the C/C++ extensions available.
To start with, we’re going to install Ruby using RubyInstaller. Visit the RubyInstaller website, and grab the latest version for your operating system - we’re using the 'Ruby 2.6.6' version. It’s the one in bold here:
Follow the instructions in the RubyInstaller, making sure to tick the checkbox that says "Add Ruby executables to your path" on the final step before completing the installation process.
The installer will then open a command prompt that prompts you to install the MSYS2 development tools:
For this, select the first option.
After installation, open the command prompt (which you can do by right-clicking
on the Windows icon in the bottom left corner, and clicking "Command Prompt")
ruby -v. You should see something like this:
ruby 2.6.6p146 (2020-03-31 revision 67876) [x64-mingw32]
Node.js + Yarn
On top of this, more recent versions of Rails use a gem called Webpacker, which works in a similar manner.
To get the full power of the asset pipeline or Webpacker, you need to have Node installed. To get Node, go to https://nodejs.org/en/download, and select the "LTS" (Long Term Support) version:
Run this installer to install Node. During the setup, you’ll be prompted to install additional tools:
Make sure you check this box!
Once the installer has finished, you’ll be prompted to install those additional tools. Continue through these prompts until they’re finished.
Open a new command prompt and then run
node -v. If you see "v12.16.2", then Node has been installed.
The next thing we need to install for Node is a package manager called Yarn. This is used by Rails to install files for Webpacker. We can install Yarn with this command:
npm install -g yarn
Verify this has been installed by running
yarn -v. As of this time of writing, Yarn’s version is 1.22.4. If you see any version number, then that is fine.
New Rails applications start out as Git repositories, and so we will need to install Git.
If you do not do this step, when you generate a new Rails application it will only generate some of the files. You’ll be missing a bunch, and your Rails app will not work.
You can do this by going to https://git-scm.com/download/win and downloading the "64-bit Git for Windows Setup" version. Run through this installer.
To verify Git has been installed, start the Command Prompt and run:
You should see something that looks like:
git version 2.26.2.windows.1
So now you have a working Ruby. What about Rails?
Ruby comes with its own package manager called RubyGems, and this is what we can use to install Rails. Gems are just little bundled-up packages of Ruby code, and Rails is just a gem. We can install Rails with this command:
$ gem install rails -v "~> 6.0.0" --no-document
This will install the latest version of the
6.0.x branch of Rails. At the current and all of its
dependencies. It’ll take a while, as it figures out the dependencies, installs
the gems, and then parses and installs documentation. (You can skip the
documentation install by running the command with
install rails --no-document. But hey, you might want it one day!)
When it’s done, verify the installation by running
rails -v - it should tell
you that it’s using a version starting with "6.0". Hooray!
However, there are a couple more things you will need to do, before starting an app. These are minor gotchas, that simply exist because Rails gives you a lot of choice in what libraries you use with your app.
One of those choices is of a database library. By default, when generating an app, Rails will try to configure the app to use SQLite, a simple file-based database system. This is a decent choice for learning, and will work out of the box on Windows.
However, once you get going with the application you may wish to switch to using a different database system, such as MySQL or PostgreSQL. These won’t work out of the box on Windows - you’ll need to fetch and install the database systems yourself.
If you wanted to use MySQL, you’ll need to visit the MySQL website at http://mysql.com, and go to the Downloads page. There, under MySQL Community Edition, you can click through and download the MySQL Community Server. If you wanted to use PostgreSQL, you’ll need to visit http://postgresql.org, and download the Windows binary package from the Downloads page.
Starting a Rails application
Once all that complicated setup is done, starting a new Rails app is trivial. Simply enter in your terminal:
$ rails new my_awesome_app
Which will create a new app using SQLite, in the
my_awesome_app directory of
your current folder. This will also install Once that’s complete, you can start the Rails server:
$ cd my_awesome_app $ rails server
Once Puma tells you it has loaded on port 3000, you can open up a browser and visit http://localhost:3000.
You should see "Yay! You’re on Rails!"