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
- Setup any version of
node.json 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)
- 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 myappand run
rake db:create db:migratefollowed by
rails serverto test if everything has been installed and is working (Website should be live on http://localhost:3000)
Setting up text editor
Setting up Git and Github
The real stuff ™
The content down below will now target the following operating systems:
- MacOS/OS X
- Windows + Linux Subsystem
- 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
- They have nice script to automate most of the stuff, if it works, good enough, else try the other ways
- Install ruby 2.3
- Install it using RVM (Click on the rvm button)
- Skip MySQL and Postgres setup
- Ignore the adds, poor guy is trying hard to monetize his tutorials
- Don't create gemsets, skip all those steps completely
- Don't worry too much about all the extra stuff. Your goal should be to achieve what we described above, the rest will settle itself with time
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)
- LGTM (Looks good to me), Suggests a modern way to install for newer versions, while uses railsinstaller for older versions
- More or less same as above, less descriptive
- https://railsapps.github.io/installrubyonrails-mac.html or https://gorails.com/setup/osx/
- IMHO, too descriptive, might help with some errors and stuff if things go south. RailsApps tutorial uses RVM based method which I strong prefer over rbenv as mentioned in gorails.
- Skip the gemset steps in rails apps, just ignore those lines
- Skip the installation of MySQL and Postgres in GoRails
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
- 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
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.
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:
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.
- Later steps with bash might not work, don't panic
- Misses some of the fixes required to run the environment, refer to the links above for 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)
- A nice handy guide
- Another nice guide
- https://github.com/railsbridge/railsbridge-virtual-machine, https://github.com/railsbridge-boston/railsbridge-vm and https://github.com/rails/rails-dev-box
- Have (Vagrant) scripts to help you bootstrap the VMs.
- Read the READMEs for more details
- Uses vagrant and chef to provision the VM. A little advanced, use if you know what you are doing
- Another dead simple way would be to download VirtualBox, create an Ubuntu VM, and then follow the steps mentioned above in Ubuntu section.
- Again, if you know what you are doing (with ansible in this case): https://railsbox.io/
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 upto 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/
- Cloud9 - https://c9.io/
- One click setup for rails environment after signing up
- https://railsapps.github.io/rubyonrails-cloud9 (might be outdated)
- Codeanywhere - https://codeanywhere.com
Koding- Free plan discontinued and open-sourced: https://github.com/koding/koding
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.