Ruby on Rails on Windows (and without wsl2)
Don't get me wrong, I still think that working on a Unix-based system is the best way to go for this server development environments since I'm almost sure that the code will be running in some Linux distro in production.
But being able to play with code in my windows pc is still helpful! Sometimes you just want to throw some code and play with it at that moment, and switching OS/computers may now be suitable always.
And if you want to teach someone to code, it's going to be way painless to the newcomers to just stick with their OS (and for my students that is windows 99% of the time)
Development with rails on windows in 2020 is surprisingly easy, way faster than it was in the past, and the setup experience (with the LTS versions) is smooth.
How to - First steps
First, you will need to install some dependencies to get started with your development environment.
- Download a good text editor like VS Code or Sublime Text
- Download and install git for windows. You will be using the git bash terminal from it! while installing stick with the default options.
- Download and install node.js for windows (in the last step of the installer you can opt-in to install some extra dependencies like chocolatey and python, 3 birds in one shot)
- Download and install yarn which is the package manager for javascript that Rails is using nowadays.
Now we are ready to start with the ruby magic!
Download version Ruby+Devkit 2.6.6-1 (x64) from RubyInstaller. Don't download a newer version unless it is in bold fonts and with an arrow on the left of the name. The version with those indicators is the stable one, and for windows, you need maximum compatibility. A newer version may work, but some gems are still not updated for windows+latest ruby version (like nokogiri, at the time of the writing).
While installing, click next and stick with the defaults. The last step will start a bash console where you are prompted to select one of the 3 options. Since this is your first installation, press 1 and then Enter
Now let's install rails 6 like you always do: gem install rails
And that's it!
Just a few gems may depend on libraries that don't play nice with windows all the time, so it's not a perfect solution, but for my day to day use cases, it works excellent! (and there's a lot of support from the community at StackOverflow and relatives GitHub issues)
Hack a nice day.