As a Rails developer currently stuck using a Windows environment, I’ve run into a number of problems trying to use gems with native extensions such as RMagick, etc. Fed up with taking twice the time to accomplish the same thing, I decided to get a Linux-based server up and running locally. Since I don’t have a dedicated box lying around, I decided to try virtualization. The end result is a virtualized Linux server into which I can shell, build apps, and test either locally or remotely.
Acquiring the Appliance
The first thing I needed to do was get The VMware Player. This freely available virtualization solution is widely used and allows for easy setup of virtualized operating systems of any kind. Download and install VMware Player using normal options.
Next, I needed to get my base appliance. While there is an existing Rails Appliance for VMware Player, I found that it didn’t give me the flexibility I needed in installing custom gems and caused more problems than it eased. I decided to go with a clean install of Ubuntu Server on top of which I would add everything I needed. Get the Feisty Fawn distro I used here.
Once your distro has finished downloading, extract into desired location and run using the VMware player. The distribution linked in this article has no root, but an account called
notroot with a password of
thoughtpolice. You should obviously either change the password or create a new account for yourself immediately for security purposes.
Get Rails Up and Running
Now it’s time to install ruby, rubygems, rails, and everything else you might need or want for your new web distribution. Note that I am not setting up an elaborate system, just the bare basics needed to run and test rails applications.
Next we’re going to set up our distro with all of the things we’ll need for a basic Rails development box. Do the following in your command shell (References: urbanpuddle.com, rails wiki):
sudo apt-get update sudo apt-get install build-essential ruby rubygems irb1.8 ri rdoc ruby1.8-dev mysql-server libmysql-ruby libmysql-ruby1.8 libmysqlclient15off mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 libmysqlclient5-dev gem install rails --include-dependencies gem install mongrel --include_dependencies gem install mongrel_cluster echo 'export PATH=$PATH:/var/lib/gems/1.8/bin' >> ~/.bash_profile source ~/.bash_profile
That giant block of goodness builds and installs everything you need to get started with your development.We’re installing Ruby, RubyGems, a MySQL server, and the associated development libraries that will let us build native extensions such as the mysql gem if desired.
Now that we have the basics, you should be able to pop open a directory (I used
/var/www) and create your rails application skeletons. Gem installations should work as normal, and you now have a very basic Rails development environment.
SSH and NAT
You may want to be able to shell into your new virtual machine. The first thing you will need to do is install an SSH server:
sudo apt-get install openssh-server
The trickier part comes in configuring the virtual machine’s networking to allow external access. First you need to find out the internal IP for your virtual machine. In your shell, type
ifconfig and write down your IP. Now, if you are running VMware Workstation, open the “Manage Virtual Networks” item in the VMware Start Menu folder. If you are running the free VMware Player, open up vmnetcfg.exe in your install directory.
There’s a lot to this program, but what you want now is the NAT tab. Make sure NAT service is started then click the “Edit…” button. Click through to “Port Forwarding…”. Now you need to add port forwarding for any ports you may want accessible outside the virtual machine. To add a forwarded port, go to add and fill in the IP address you wrote down from ifconfig.
I forwarded port 22 for SSH and ports 3000-3005 for my rails development apps. Once you’ve added all of the ports you wish to forward, hit “OK” and “OK” again and “OK” again. You should now be able to shell into your VM using PuTTy or the like, transfer files with an SCP program such as WinSCP, and visit your Rails apps live once you run a server with
There’s infinitely more to go over in the world of server configuration, but this is a quick and easy way to get a Linux environment on a Windows box.