Sunday, April 8, 2012

Rails 3 on Ubuntu 11.10 on VirtualBox VM on Windows 7

Okay, so Rails runs pretty well for development on Windows 7 using RailsInstaller, but you're still running in a Windows environment. This is apparently now tolerable, but still not recommended, for two-fisted Rails development. I figure the best approach is to set up a development environment that's similar to the deployment environment. The defacto commercial Rails stacks now consists of some Linux distro, Passenger, Rails, MySQL and Git, so that's what I'll approach in this setup.

In the spirit of (and cribbing from) notes that Alan D. Jackson made while setting up Rails 3 on Windows with Ubuntu on a VM, here's my experience doing the same thing:
  1. If you don't have it already, download and install Putty or Cygwin for the ssh client
  2. Download VirtualBox for Windows Hosts. Based on this comparison of VMs, VirtualBox is the best choice for this application.  
  3. Install VirtualBox. I installed version 4.1.12.
    1. Not knowing any better, I left all of the defaults selected. We'll soon see if that was the right choice.
    2. The install wizard proceeded as expected. Let it start VirtualBox.
  4. Download the latest Ubuntu ISO file.
    1. Hrm, first question. I'm running Windows 7 64-bit, so I guess that means I want 64-bit Ubuntu? I don't know, the VirtualBox setup wizard lets me select either 32- or 64-bit. However, the Ubuntu download page recommends 32-bit. I'll go with the 32-bit for now.
  5. Set up a new VM
    1. Click the "New" VM button, name it "Rails 3.2 on Ubuntu". Helpfully VB selects Ubuntu from the OS list.
    2. Memory: the default is 512Mb. Alan recommends 384. Since I have 3Gb available, I'll splurge on 512Mb.
    3. Virtual Hard Disk: create a new 8Gb disk.
    4. Virtual Disk Creation Wizard: leave the default "VDI" selected as recommended
    5. Virtual Disk Storage Details: leave the default "Dynamically allocated" selected as recommended
    6. Virtual Disk File Location and Size: leave the default values selected
    7. Review the Summary, then click Create
  6. File -> Virtual Media Manager
    1. Select CD/DVD Images
    2. Add the Ubuntu ISO image
    3. click Close
  7. Select the new VM image -> Settings 
    1. Storage
      1. Storage Tree: Select IDE Controller -> Empty
      2. Attributes: click the tiny little CD image to right of the "CD/DVD Drive" dropdown and select the ubuntu ISO image
    2. Network
      1. Select Adapter 2 tab
      2. Check Enable Network Adapter
      3. Select Host-only Adapter
      4. Click OK
  8. Start the VM, then select "Install Ubuntu".
  9. Let the Ubuntu installer do its thing, then reboot the VM.
  10. After the VM reboots, install guest additions to get shared folder?
  11. Install samba (Windows file sharing)
    1. sudo apt-get install samba samba-common 
    2. sudo apt-get install python-glade2
    3. sudo apt-get install system-config-samba
    4. Open Samba Server Configuration from Ubuntu desktop -> Dash home -> Applications -> Samba
    5. In Samba Server Configuration, select File -> Add Share -> Basic
      1. Directory: /home/[your name]
      2. Leave share name and description as is
      3. Select Writable and Visible
      4. On the Access tab, select Allow access to everyone. You'll still have to logon as the user from Windows
    6. In Preferences -> Server Settings, 
      1. change the workgroup name to your PC's workgroup name. You can find the Windows workgroup name in the Windows "System" control panel
      2. Leave all of the other settings at their defaults.
    7. In Preferences -> Samba Users, you might have to set the Samba password for the user account
    8. Close Samba
    9. In windows, browse to \\server\user (e.g. \\ubuntu\philip), then enter the username/password when prompted
  12. Install Open SSH Server
    1. sudo apt-get install openssh-server
    2. ssh from Windows desktop via Cygwin or Putty: ssh you@your_ubuntu
    3. Create a .bash_profile file to source .bashrc for aliases, etc. when you log in via ssh:
      if [ -f ~/.bashrc ]; then
          . ~/bashrc
  13. Dev setup
    1. Install aptitude (if needed): sudo apt-get install aptitude
    2. Install basic packages: sudo aptitude -y install curl git-core build-essential zlib1g-dev libssl-dev libyaml-dev libreadline5-dev sqlite3 libsqlite3-dev autoconf automake nodejs
  14. Install rvm (Ruby Version Manager) 
    1. curl -L | bash -s stable
    2. Reload shell (or close and reopen it): source ~/.bash_profile
    3. Add rvm setup to .bashrc file: 
    4. if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then source "$HOME/.rvm/scripts/rvm" ; fi
  15. Install Ruby and Rails. Insert the latest version numbers:
    rvm install 1.9.3 && rvm --default ruby-1.9.3 && gem install rails sqlite3
  16. Smoke test:philip@ubi:~$ ruby -v && rails -v
    ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
    Rails 3.2.3
  17. Create a Rails test site:
    1. mkdir ~/sites && cd ~/sites
    2. rails new rails_app && cd rails_app && rails s
    3. Browse to http://yoursite:3000/, if all goes well you'll see the default Rails home page
  18. Make Rails faster! Edit this setting in ~/.rvm/rubies/ruby-1.9.X-pXXX/lib/ruby/1.9.X/webrick/config.rb to speed up browsing the rails app from the Windows host:# :DoNotReverseLookup => nil,
    :DoNotReverseLookup => true,
  19. Now the app can be edited from the Samba share on Windows.


  1. Awesome tutorial it got me up and running in no time!

    Thank you so much.

    You add should also add lib-yaml to the basic packages also though to make rails not complain about it at the start


    Thanks again!

  2. Glad it helped, Will. I have added libyaml-dev to the list of basic packages, thanks for that.

  3. philip:

    I could install seamlessly, thx to your detailed steps
    you made my day!


  4. Excellent post. Works flawlessly. Thanks!

  5. Hi, thx for this guide.
    One question: do you often use Ubuntu outside the SSH (i.e. putty)? I think the usage of Ubuntu Server must be enough. Are there any special use cases when we need Ubuntu desktop?

  6. Hi Orest,

    Thanks for your comment! Most often I use the mintty terminal installed with Cygwin to login to the Ubuntu VM. It's an alternative to putty.

    If I took the time to figure it out, I would run Ubuntu in VirtualBox without a GUI. Is that how you are running the Ubuntu VM, as "Ubuntu Server"? If so, have you posted your configuration notes online?

  7. This comment has been removed by the author.


Note: Only a member of this blog may post a comment.