Installing Rails

Intro

As a lot of people will be learning Rails and maybe attending the upcoming RailsGirls Delhi Workshop, this post will help them setup a dev environment to code without hassle. This post will try to aggregate other Rails installation blog posts, guiding how to use them properly.

This blog post will not cover the actual steps involved in setting up the environment, but try to collect different resources from the internet to point you to the best way of setting it up on your machine.

List of tools

Here is what we intend to install for a good rails development environment

  • Setup Git and Github - Essential for code versioning and collaboration, helps you cheat
  • Setup Ruby 2.x (x=2,3,4) - Anything above ruby 2.2.3 should be good enough
  • Setup Rails 4.2.x/5.x - Depends on requirements, can be changed easily with a single gem install
  • Setup any version of node.js on the machine (for ExecJS runtime, rubyracer is pain)
  • Setup a database to use with Rails - SQLite works good enough for basic development and is easiest to start with, so let's stick to that
  • Setup a good enough text editor - Sublime/Atom/ - The idea is that the user should be able to code easily in them. Don't use Notepad/Wordpad/Gedit/MS Word/Openoffice etc. PLEASE

Link to other guides

Bored already? Don't trust me? Here are some other guides we recommend (and will be following later)

General Advice

  • For Non-Windows, use RVM to install rubies, it's really easy compared to other methods and makes it easy to switch/upgrade as well.
  • Install SQLite only for now. Focus on first getting the basics right then dive onto MySQL or Postgres or whatever database you want to use.
  • Don't worry about gemsets, and stick to any steps that any guide mentions related to them (Bundler handles gems really good enough, and gemsets aren't needed anymore. This blogpost describes it well)
  • Create a new rails app using rails new myapp, cd myapp and run rake db:create db:migrate followed by rails server to test if everything has been installed and is working (Website should be live on http://localhost:3000)

Getting Started

Setting up text editor

Putting it first cause its the easiest. Just go to https://www.sublimetext.com/3 and download it for your OS.
Want Opensource & Good looking & Slower? https://atom.io/

Setting up Git and Github

Git will be installed in all the methods below.
For Github, create an account and if possible, add your ssh-key to github.
You can also use the Github GUI, if you're into those kinda things.

The real stuff ™

The content down below will now target the following operating systems:

  • Unix/Linux
  • MacOS/OS X
  • Windows + Linux Subsystem
  • Windows
  • Platform Agnostic - VM/Docker
  • Cloud based

Unix/Linux (Read: Ubuntu)

Unix/Linux, especially Ubuntu and Ubuntu based OSes are the easiest to setup. A few good resources are the following

MacOS/OS X

The one I am currently using, it is slightly more difficult due to XCode setup etc., but should work properly and has the largest amount of help

Don't upgrade/downgrade your Mac just for this installation. Rails works fine for all current (10.06+ Maybe)

Windows + Linux Subsystem

Only for Windows 10 with Linux Subsystem enabled.
Not recommended as it may not work properly now or in the future. Try at your own risk. Prefer the other ways mentioned below

  • https://gorails.com/setup/windows/10
    • Looks like the best and only major tutorial to me
    • Use RVM based method (until something goes wrong, then try rbenv)
    • Don't install MySQL (it does work though if you do)
    • Don't bother about Postgres, it doesn't even work in this environment

Windows

Easy way: Switch to linux.

Seriously. You will save yourself and others a tremendous amount of pain by doing so. Ruby/Python/Open-source in general doesn't target windows, sometimes completely ignore it. Many packages that you would want to use in future won't support windows. You will run into errors and you won't be able to find help online. And even if you make things work, they will be hacky and not something you would love. And yes, I find it damn slow.

Another way

Use a VM (requires resources) or a cloud service (requires good internet speed) for your development if you can't manage to install or dual-boot linux.

Hard Way: RailsInstaller

Railsinstaller is perhaps the easiest (hard) way to install ruby+rails on Windows.

You can find the executables here:

http://railsinstaller.org/en

Install the ruby 2.3 version. If it doesn't work, try ruby 2.2. Alternate link for downloads (incase website is not reachable):
https://github.com/railsinstaller/railsinstaller-windows/releases (Get the latest release)

Whenever something installed doesn't work as a command in cmd/bash, make sure it is present in the PATH. More details here

I will just put down some resources on how to install Rails using Railsinstaller, they will help you a lot in troubleshooting.

Platform Agnostic - VM/Docker

This is good way to either run Rails in an environment where native installation isn't possible (or not working) or you need to run the Rails development environment in isolation.

VM will help you setup a linux machine for Rails development. Vagrant can be used to bootstrap the VM.
Docker can help you run the application inside container(s) (in another VM if host is not linux)

VM
Docker

You will need some knowledge of docker to use this method properly. Docker works by creating isolated containers catering to your exact needs rather than a multi-purpose system like a VM, and involve writing scripts to automate the process (Dockerfile). Here are some resources on how to get started with it:

Pro-tip: If you a trying to run an existing application, and it already has Docker configuration ready (Dockerfile and docker-compose), then you can just install docker and run docker-compose up to start using that app.

Using a cloud service

If anything above doesn't work for you, or your machine doesn't have the resources to be a good development box, then using a Cloud based IDE might be good alternative for you. The only problem with them is that you have to be connected to the internet with a good stable connection to work. Here are some services and respective blog posts on how to work on a Rails app on those services. Most of them do have free plans to get started (and should be good enough for beginners learning Rails)

A blogpost explaining various cloud IDEs for rails: http://rubybeginner.com/cloud-ides-ruby-beginners/

Get Help

If you run into errors and if you can't get things running, don't panic. There are plenty of solutions available to these common (many, many people install rails everyday, just like you) problems and they are just a google away.

Google is your friend.

If you are still lost, try contact a real human (like any of the organizers of this workshop) and they will definitely help you out.