Use Windows or Linux to Start Work with Ruby on Rails

Use windows or linux to start work with Ruby On Rails?

If your current dev machine is running Windows, and you don't have access to a Linux environment right now, don't let that stop you from getting started with Rails. Definitely, definitely, definitely install the DevKit first thing (if it's not included in RubyInstaller yet). See https://github.com/oneclick/rubyinstaller/wiki/Development-Kit for that.

If you get deep into Rails development, or even start doing it for a living, you will inevitably drift towards using Linux on your dev machine. The problem is not Rails, but the many binary gems which are difficult or impossible to install on Windows.

The most popular Ruby library for manipulating images (ie. generating thumbnails) is RMagick, but trying to install it on Windows is enough to make a strong man cry. Paperclip is very nice for dealing with images and other attachments, but it is also a problem. Then there is a popular JSON parsing library which is also problematic on Windows. Unicorn (a popular Rails server) won't run at all on Windows, and Thin (my favorite) may also give you headaches. And so on, and so on.

You can get pretty far with Rails development on Windows these days, but at times you will find yourself having to test code on a remote server, rather than locally, and it can waste a lot of time.

Developing Ruby and Rails in Windows? Or Linux VM

You should also checkout the vagrant project which creates headless (non-gui) VMs and makes it easier to work with your files, etc in Windows while the code actually gets run on the Vagrant VM. Also, since its headless, the graphical UI isn't eating up resources and has less impact on your host machine.

Check out these resources:

http://www.vagrantup.com/

http://blog.dcxn.com/2013/07/12/introduction-to-vagrant-for-rails-developers/

http://railscasts.com/episodes/292-virtual-machines-with-vagrant

*Also if you're learning Rails, you MUST checkout Railscasts http://railscasts.com/

Is there anyway to run Ruby on Rails applications on a Windows box?

Windows is not the usual place to deploy production Rails apps, but there are people who do it. Mongrel was originally written to give better deployment options for Windows. As it turned out the UNIX deployment options weren't that good either. :)

Start with the Ruby One Click installer so you have a sane installation of ruby and rubygems.

From there, you install the rails gem and the gem for your database like you normally would. Most if not all of the databases have Windows gems.

Make sure to install mongrel_service to be able to control each mongrel like a normal windows service. See mongrel_rails service::install -h for details.

Once you have your mongrels set up, it's similar to a UNIX deployment. You set up a reverse proxy, such as Apache2 and you're set.

You might run into some gems (such as BackgroundRB) that will not work under Windows because they have C code that either rely on UNIX libraries or expect a UNIX-like build system at installation time. However, all of the really important Rails gems, such as Mongrel and the database adapters, have gems with pre-built binaries available, so you'll be fine.

Run Rails App In Windows and Linux with different gemfiles

I think you'll probably have to use that answer in the :platforms question and just ignore the fact that the gemfile.lock is regenerated. There's not much point in keeping the lockfile in your repository when it will be different on each platform. However, you can still maintain some of the control that the lockfile provides by manually specifying specific versions and dependencies in the gemfile.

How to run 'rails credentials:edit' on Windows 10 without installing a Linux Subsystem

I would suggest you switch to non-windows based system if you're trying to do any rails development as I used to work on a windows machine until I caved in and switched entirely to Mate Linux. It would be so much easier to develop Rails application on Linux platform since you would see almost all gems compiling without any issue and all the rails terminal commands are working without further setup.

However, if you would like to edit your credentials, you need a text editor (Usually vim on Linux) setup before running credentials:edit.

First run SET EDITOR="notepad_path" and then try running rails credentials:edit

You can change notepad_path to any other text editor you prefer. However, some editors like Atom was giving weird issues for me.

Limitations in running Ruby/Rails on windows

Here's an overview of the current issues with Rails on Windows:

  • Ruby and Rails are slower on Windows than they are on Unix-like OS's.
  • A few gems and libraries don't work on Windows.
  • Some Unix-isms aren't available on Windows (examples).
  • The community is mostly on either Mac or Linux (This is a particularly hard one to deal with; nobody wants to be alone on one island when the rest of the tribe are partying, having fun and getting along great over on the other island. Community is important. It seems that most Windows developers that start with Rails quickly switch to a Mac or Linux. However, the small community of Windows Ruby users that do persist are extremely friendly, dedicated and knowledgeable - go say hi.)

Note much of the advice that follows is now outdated due to the magnificent efforts of the RubyInstaller team in bringing stability, compatibility and performance to Ruby on Windows. I no longer have to use VirtualBox, which says a lot about how far Ruby on Windows has come.

If you want more technical detail, the following are required reading. :

  • Ruby for Windows - Part 1
  • Is Windows a supported platform for Ruby? I guess not
  • Testing the new One-Click Ruby Installer for Windows
  • Still playing with Ruby on Windows
  • Chatting with Luis Lavena (Ruby on Windows)

Choice quote from that last one is:

AkitaOnRails: The most obvious thing is that any Gem with C Extensions without proper binaries for Windows will fail. Trying to execute shell commands will fail and RubyInline as well. What else?

Luis Lavena: Hehe, that's just the tip of the iceberg

Having said all that, I don't find developing with Rails on Windows too painful. Using Ruby is, for the most part, a pleasure. I'd avoid InstantRails because, to be frank, it's just as easy to install Ruby properly using the one-click installer, then doing a gem install rails. If you need Apache and MySQL, WAMP is a good bet, although even these aren't required if you just stick with Mongrel and SQLite.

What I've taken to doing recently is running VirtualBox with an instance of Ubuntu Server that closely mirrors the deployment server. I map a network drive to the Ubuntu Server, then I edit and run my code directly on the VM. It uses hardly any memory (it's currently using ~43MB; contrast that with Firefox, which is using ~230MB) and Rails actually performs better than running it natively on Windows. Plus you can experiment with your virtual server in relative safety. It's a really nice setup, I highly recommend it.

Finally, here are a couple of Ruby/Rails blogs aimed at Windows users:

  • DEV_MEM.dump_to(:blog) (Luis Lavena)
  • Softies on Rails
  • Ruby On Windows


Related Topics



Leave a reply



Submit