<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Pratt // Metaphors Be With You &#187; cygwin</title>
	<atom:link href="http://www.chrisdpratt.com/tag/cygwin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdpratt.com</link>
	<description>Random thoughts on random topics. What? You wanted predictability?</description>
	<lastBuildDate>Fri, 31 Jul 2009 14:58:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby on Rails Development in Windows via Cygwin</title>
		<link>http://www.chrisdpratt.com/2007/09/17/ruby-on-rails-development-in-windows-via-cygwin/</link>
		<comments>http://www.chrisdpratt.com/2007/09/17/ruby-on-rails-development-in-windows-via-cygwin/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 05:38:09 +0000</pubDate>
		<dc:creator>chrisdpratt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://chrisdpratt.webfactional.com/?p=24</guid>
		<description><![CDATA[Such a love/hate relationship I have with Linux. It has everything but a great editor (Please no flames from the vi and emacs crowd&#8230; those are great editors if you know how to use them properly, but I&#8217;d prefer to spend my time learning Ruby and Rails rather learning how to use a text editor).
Windows, [...]]]></description>
			<content:encoded><![CDATA[<p>Such a love/hate relationship I have with Linux. It has everything but a great editor (Please no flames from the vi and emacs crowd&#8230; those are great editors if you know how to use them properly, but I&#8217;d prefer to spend my time learning Ruby and Rails rather learning how to use a text editor).</p>
<p>Windows, on the other hand, lacks much in the Rails development arena, but has been graced with a really great text editor: e-Text Editor, a TextMate clone for Windows. That&#8217;s just enough motivation to keep me hacking away at Windows (at least until I get a Mac&#8230; then you&#8217;re all on your own).</p>
<p>So on to the actual point of this article. Via Cygwin, I have been able to setup up an acceptable Rails development environment for myself in Windows, but since Cygwin can be a little tricky to setup properly, I decided to get some community service hours in by providing a tutorial.</p>
<p>Without further ado (cue drum-roll and general fan-fare)&#8230;</p>
<h2>Preparation</h2>
<p>I had various things such as Ruby and MySQL already set up on my computer before installing Cygwin. The Windows version of Ruby will have to go the way of the dinosaurs once we bring in Cygwin, but it does play well with the Windows version of MySQL. However, I&#8217;m not sure if that would still be the case if setup after Cygwin (it probably would, but why take any chances?), so our first step will be to setup MySQL.</p>
<h3>Install MySQL for Windows</h3>
<p>There&#8217;s a few million tutorials on how to do this, so I&#8217;m going to cover the bare minimum. If you run into any problems, go make friends with Google.</p>
<p>First, go <a href="http://dev.mysql.com/downloads/mysql/5.0.html#win32">download the current MySQL binary</a>. At the time of this writing, it&#8217;s 5.0.45. You can download either the Essentials or the regular setup executable. I normally go with the regular setup since space is not an issue for me, but I&#8217;ll leave the choice to you. Run the installer, and follow the on screen prompts. The install process is pretty self-explanatory, but I&#8217;ll cover a bit of minutiae.</p>
<p>You can pretty much use the default settings throughout the install. I normally like to keep all my server apps (apache, mysql, etc) in a common directory for ease. If you&#8217;d like to do the same, you can change the install directory when you have the option. After the install finishes, you&#8217;ll be asked if you&#8217;d like to go ahead and configure MySQL. Yes you do, so proceed with that. Choose the development options throughout (the explanatory paragraphs will mention that this setting or that setting is better for either production or development). When you&#8217;re asked if you&#8217;d like MySQL to run as a Windows service, tell it yes. When you&#8217;re prompted to setup accounts, make sure you disable the anonymous account. You can leave the root password blank, as long as you also turn off remote access. The default Rails database config has blank root passwords, so it&#8217;ll save you from having to customize the config every time you start a new app, and it&#8217;s just easier to not have to type in a password every time you want to do something with MySQL. The rest of this tutorial will assume the password is blank, though I&#8217;ll provide little pointers here and there in case you did set a password.</p>
<h2>Install Cygwin</h2>
<p>With that out of the way, we can move on to Cygwin. You can grab the setup at the <a href="http://www.cygwin.com/">Cygwin website</a>. Look for the &#8220;Install or Update Now!&#8221; link around the center of the home page. The setup file is a small download, but go ahead and get a pot of coffee ready for brewing, because the rest will be downloaded during install.</p>
<p>Run the setup program, and click next. You&#8217;re going to want to stick with the default here (Install from Internet), so click next again. The root directory should default to &#8216;C:\cygwin&#8217;. If not, it&#8217;ll make your life a little easier if you change it to that. Leave the two recommended settings checked, and click next again. Now, you&#8217;re going to be prompted for a Local Package Directory. I forget what this defaults to, but I like to set it to &#8216;C:\cygwin\install&#8217; just to keep everything together. Click next again, and you&#8217;ll be prompted for your connection settings. For most purposes you should be fine with the default of &#8220;Direct Connection&#8221;. If that doesn&#8217;t work, and you&#8217;re unsure of what your settings should be, you can try &#8220;Use IE5 Settings&#8221;. If you know you&#8217;re connecting through a proxy, what are you bothering me for? Just enter your information there.</p>
<p>Time for a new paragraph for this rather tedious install process, but we&#8217;re getting close to the end. After clicking next, you&#8217;ll be prompted to choose a download site. I always feel a little bit like I&#8217;m in Vegas at this point in the install, because it&#8217;s basically just a gamble as to which one to pick. FTP is more efficient for file transfer than HTTP, so that weeds it down a bit. Other than that, you can either pick one at random or try to discern one that might be close to you. There&#8217;s alot of college servers there, so if you recognize a college that close to your area, go ahead and pick that one.</p>
<p>Okay, I devoted way more attention than was necessary to picking a mirror. Once you&#8217;ve rolled the dice, click next. The installer is  now going to download a list of available packages and then it&#8217;ll present you with a very cryptic screen. Fortunately, we&#8217;re going to stick with the defaults for most of these, but we will have to make one small change. Expand the &#8220;Devel&#8221; category, and then scroll down in the list until you come to the &#8220;ruby&#8221; package. Click where it says &#8220;Skip&#8221; to set it to install. And with that, you can click next again and go have a cup of coffee.</p>
<p>When the install completes. You&#8217;ll be asked if you&#8217;d like to create a Desktop icon or Program Group, give one or both a check, just to simplify your life, and you&#8217;re done.</p>
<h2>Installing RubyGems</h2>
<p>The process from here ought to be familiar for awhile if you&#8217;ve ever done any Rails development before. However, we do have a few gotchas to take a look at.</p>
<p>First, <a href="http://rubyforge.org/frs/?group_id=126&amp;release_id=11889">download the rubygems archive</a>, which is at version 0.9.4 at the time of this writing. Save it to your desktop to make things easy on yourself. Now, we need to open up a Cygwin command prompt, using one of our handy, dandy shortcuts (either on your desktop or in your start menu&#8230; you did remember to do that right?). In the command prompt, you&#8217;ll already be in your home directory (i.e. C:\Documents and Settings\[your name]\) which is short-handed as &#8216;~&#8217; (Tip: you can run &#8216;cd ~&#8217; at any point to return to your home directory). We need to get to the RubyGems archive we downloaded, so if you followed instructions that&#8217;ll mean running &#8216;cd Desktop&#8217;. Now, run the following command (remembering to change the version to whatever is appropriate):</p>
<p><code> </code></p>
<pre>$ tar -pxzf rubygems-0.9.4.tgz</pre>
<p>After that finishes it&#8217;s work change into the directory that was created:</p>
<p><code> </code></p>
<pre>$ cd rubygems-0.9.4</pre>
<p>And run the setup.rb program:</p>
<p><code> </code></p>
<pre>$ ruby setup.rb</pre>
<p><strong>Note:</strong></p>
<p>At some point either by now or in the next few steps, you might come across a cryptic error resembling:</p>
<p><code> </code></p>
<pre>ruby: no such file to load -- ubygems (LoadError)</pre>
<p>If or when this occurs, you can simply run the following command, and you&#8217;ll be good to proceed:</p>
<p><code> </code></p>
<pre>$ unset RUBYOPT</pre>
<p><strong>Now back to our regularly scheduled tutorial&#8230;</strong></p>
<h2>Install Rails</h2>
<p>Normally, this is a easy as:</p>
<p><code> </code></p>
<pre>$ gem install rails --include-dependencies</pre>
<p>But I have recently noticed, both in Linux and Cygwin that this will return a NoSuchGem error. (Confirmation?). Go ahead and try it the tried and true way first, but if that doesn&#8217;t work, continue on.</p>
<p>Go ahead now and <a href="http://rubyforge.org/frs/?group_id=307">download the rails gem</a>, which is at 1.2.3 at the time of this writing. Save it to your desktop, like before. Back in your Cygwin command prompt change back to your desktop (&#8217;cd ..&#8217;), and run the following command to take care of the dependencies:</p>
<p><code> </code></p>
<pre>$ gem install rake activerecord actionpack actionmailer actionwebservice</pre>
<p>You&#8217;ll be prompted at points to confirm the download of additional dependencies. Of course, you&#8217;ll want to allow those. Grab another cup of coffee, and when it finishes up, run:</p>
<p><code> </code></p>
<pre>$ gem install rails-1.2.3.gem</pre>
<p>With that, we now have Rails up and running.</p>
<h2>Getting Autotest</h2>
<p>Autotest is a very nice feature that will run both your tests and specs automatically based on file changes. It&#8217;s actually just a part of a larger suite of testing tools, though, available through the ZenTest gem. Let&#8217;s go ahead and get that:</p>
<p><code> </code></p>
<pre>$ gem install zentest</pre>
<h2>Creating a Rails App</h2>
<p>Now that we&#8217;ve got all the boring stuff out of the way, let&#8217;s get to the interesting part, setting up a Rails app and bootstrapping it for Behavior Driven Development via the RSpec framework. First, change to whatever directory you want to store your Rails apps in (I like to simply use my home directory) and then run:</p>
<p><code> </code></p>
<pre>$ rails myapp</pre>
<p>(Where &#8216;myapp&#8217; is whatever you want to name your app). Then change into the new app&#8217;s directory, via:</p>
<p><code> </code></p>
<pre>$ cd myapp</pre>
<p>This is where all the fun will happen. But I&#8217;ve gotten a little ahead of myself. Before we continue, we need to take care of a few little things. First, we&#8217;re going to need both a test and development database for our new app. We can take care of that easily with:</p>
<p><code> </code></p>
<pre>$ mysqladmin -uroot create myapp_development</pre>
<p>and</p>
<p><code> </code></p>
<pre>$ mysqladmin -uroot create myapp_test</pre>
<p>Now we need to make a slight change to the database.yml config file for our app, due to some Cygwin/Windows compatibility issues. Open the database.yml file (found in the config folder of your app&#8217;s directory) in your favorite text editor or wordpad (notepad would not be a good choice due to the Unix format line-endings). Once there, replace every occurrence of &#8216;localhost&#8217; with &#8216;127.0.0.1&#8242; (fixes a socket problem with MySQL).</p>
<h2>Install the RSpec and Spec:Rails Plugins</h2>
<p>There, that&#8217;s taken care of. Let&#8217;s bootstrap our app with RSpec. (<em>Oddly enough though, we can&#8217;t seem to do this in Cygwin. I ran into a very weird issue trying. The plugins appear as if they are installing normally, but afterwards, nothing shows up in the vendors/plugins directory of the app. Odder still, if you try to install the plugins again, it will actually error out, saying that the directories already exist. The only way I could get the plugins installed was to backdoor it through a standard Windows command prompt, but that requires keeping a separate version of Ruby on the Windows side. (Confirmation?) Unfortunately, I have not been able to find another way, so for the meantime, I will go ahead and still put the process here. However, be advised that it may not work.</em>)</p>
<p><code> </code></p>
<pre>$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec</pre>
<p>and when that finishes:</p>
<p><code> </code></p>
<pre>$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails</pre>
<p><strong>Note:</strong></p>
<p>If you&#8217;re feeling adventurous, you can download the trunk versions of these plugins instead. As of this writing, this would give you access to the new Story Runner functionality of RSpec, that has not yet been released. Instead of the above commands run:</p>
<p><code> </code></p>
<pre>$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/rspec</pre>
<p>and then:</p>
<p><code> </code></p>
<pre>$ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails</pre>
<p><strong>Now back to our tutorial, already in progress&#8230;</strong></p>
<p>Whichever route you choose above, the next step is to generate the standard RSpec folders and files:</p>
<p><code> </code></p>
<pre>$ ruby script/generate rspec</pre>
<h3>Generating Some Stuff to Play With</h3>
<p>And that&#8217;s all there is to it. But for the sake of instruction let&#8217;s generate a sample controller and model. This will let us run autotest and see how the whole process went. I&#8217;ll be pretending that this app is going to be a blog, but you can go ahead and create something more meaningful here if you want.</p>
<p>The model:<br />
<code> </code></p>
<pre>$ ruby script/generate rspec_model post</pre>
<p>The controller:<br />
<code> </code></p>
<pre>$ ruby script/generate rspec_controller blog</pre>
<p>After these two complete, open the 001_create_posts.rb migration file that was created in the apps db/migrate directory. It will initially look like this:</p>
<p>class CreatePosts &lt; ActiveRecord::Migration<br />
def self.up<br />
create_table :posts do |t|<br />
end<br />
end</p>
<p>def self.down<br />
drop_table :posts<br />
end<br />
end</p>
<p>Modify it to look like this:</p>
<p>class CreatePosts &lt; ActiveRecord::Migration<br />
def self.up<br />
create_table :posts do |t|<br />
t.column :title, :string<br />
t.column :content, :string<br />
t.column :created_at, :datetime<br />
end<br />
end</p>
<p>def self.down<br />
drop_table :posts<br />
end<br />
end</p>
<p>Save and close. Then go back to your Cygwin command prompt and run:</p>
<p><code> </code></p>
<pre>$ rake db:migrate</pre>
<p>followed by:</p>
<p><code> </code></p>
<pre>$ rake db:test:clone</pre>
<p>With that done, we can run autotest and get a glimpse of the rest of our lives in development</p>
<p><code> </code></p>
<pre>
$ autotest
loading autotest/rails_rspec
/usr/bin/ruby -S script/spec -O spec/spec.opts  spec/helpers/blog_helper_spec.rb
 spec/controllers/blog_controller_spec.rb spec/models/post_spec.rb
...

Finished in 0.389 seconds

<span style="color: #33ff33">3 examples, 0 failures</span></pre>
<p>Those three examples are default examples generated for us by RSpec.</p>
<h2>Finally&#8230;</h2>
<p>Take a breather now. You&#8217;ve done alot of work, and accomplished quite alot too. I hope this helps those of you who are stuck programming in a Windows environment.</p>
<p>As always, if something is unclear, feel free to ask for further explanation. I do my best to try and write to the lowest common denominator, but I don&#8217;t always succeed. Thanks for reading. Now get out there and do some coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdpratt.com/2007/09/17/ruby-on-rails-development-in-windows-via-cygwin/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
