Jumat, 28 Juni 2013

Developing Rails in Windows using Linux Server

Developing rails/ruby app in windows is painful as many gems aren't compatible or optimized for windows. But windows is OS that I'm most comfortable with.. Linux (ubuntu) lack some tools that I need and I simply hate OSX (stupid keyboard layout and hardware restriction), so I prefer dealing with gem problems rather than changing OS..

But then it occurred to me, why not just use virtual machine with linux for server? And turns out it's pretty neat.. And I think some people are too use windows as main OS so I posted here the step for setting up linux vm for rails..

Required Software

Installing minimal Lubuntu

  1. Create virtual machine:
    1. Open virtualbox and click new machine
    2. Name it anything you want, Type: Linux, Version: Other Linux
    3. Allocate 1GB ram to it (it's enough for 1 dev server) or more if you can afford it
    4. Create a virtual hard drive
    5. Any hard drive type, the default should be good enough
    6. Dynamically allocated hard drive
    7. Any amount of disk space, the default also good enough
  2. Initial setup:
    1. click File, Preferences, Input: uncheck Auto Capture Keyboard (this feature is useless to us)
    2. right click your virtual machine created in step 1 and click Settings
    3. Open Network tab set Adapter 1 to Host-only Adapter (this will be used so we can access rails server in virtual machine from windows)
    4. set Adapter 2 to NAT (so virtual machine can access internet)
    5. Open Storage tab and mount Ubuntu mini ISO to CD/DVD Drive
    6. Close settings, right click virtual machine and choose Create shortcut on desktop, the if you like pin the shortcut to start menu for easier access
    7. At this point you can close virtualbox manager and use shortcut
  3. Lubuntu installation
    1. Start your virtual machine
    2. In boot menu chooce command-line install
    3. Follow instruction here starting from Method step 4 as I'm too lazy to write it and it will be better updated (pick Lubuntu core installation)

Installing Guest Addition

  1. Run sudo apt-get install build-essential dkms
  2. Start your virtual machine and login if you haven't already
  3. Click Devices, Install Guest Additions.. It will mount a VBOXADDITIONS
  4. Open mounted directory in terminal and run sudo ./VBoxLinuxAdditions.run
  5. Wait until it done and reboot

Adding Shared Folders and others

In virtual machine menu click Devices, Shared Folders, Choose your project folders in Folder Path, then enter Folder Name that will be used in lubuntu, and check make permanent..

Next you want to mount it on start up automatically, edit rc.local file:
sudo nano /etc/rc.local
Add the following line before exit 0: (assuming shared folder name is projects)
mount -t vboxsf projects /home/[your-username]/projects
Then create projects folder inside your home folder:
mkdir $HOME/projects
Reboot and shared folder should be added to your home.

Next enable bidirectional shared clipboard from Devices menu

Installing terminal emulator

Lubuntu by default preinstalled with XTerm terminal emulator, and IMO it's bad.. So I prefer to install gnome-terminal to replace it:
  sudo apt-get install gnome-terminal
or if you like other terminal feel free to install it (although preferable the one that support full screen)

If you're using gnome-terminal you might want to hide menubar by default by going editing profile and uncheck Show menubar by default

Installing required libraries

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libxslt1-dev libcurl4-openssl-dev git-core
also if you use postgresql:
sudo apt-get install postgresql

Installing rbenv

Simply follow installation instruction here:

Editing windows hosts file

Run ifconfig in lubuntu terminal, check eth0 inet IP, it should be something like
Copy it (block, ctrl+shift+c for gnome-terminal)
Then in windows, open C:\Windows\System32\drivers\etc\hosts with your favorite text editor

paste the IP copied earlier and add an address for it, for example:   vm.local
now if you start a rails server in lubuntu you can simply enter vm.local:3000 (if server port is 3000) in windows.


Now everything is done and time to enjoy it.
Things you can do:
  • Press F11 (for gnome-terminal) for full screen so you got similar feel as windows command prompt except better
  • Others useful shortcuts (for gnome-terminal)
    • ctrl+shift+t : open new tab
    • alt+1..9 : switch to tab x
    • ctrl+shift+w : close tab
    • ctrl+shift+c : copy
    • ctrl+shift+v : paste
  • And most importantly.. Code without worry about incompatibility but with the comfort of windows!
What's next?

Tidak ada komentar:

Posting Komentar