Running Ruby And Rake (and albacore) Without Installing Them

One of the more frequent complaints that I’ve heard about using Ruby and Rake to build .NET systems is that you have to install yet another framework and learn yet another language to be able to use it. In a large team or on a project that involves a significant number of computers, installing the runtime may be a time consuming maintenance problem. I’ve even heard of cases where people are just not allowed to install stuff from the internet or from specific places on the internet or whatever. Truthfully, I’ve been very dismissive of this in the past. I’ve just been telling people that they should just get over it and install the tools that get the job done. That’s probably not the best strategy. Instead, I’d like to address the concerns and offer a solution.

In most of these situations you can still take advantage of ruby, rake and albacore. To do this, you need to have at least 1 computer that is allowed access to the internet and has the ability to download and install ruby, the rubygems system and individual gems. Ruby does not have to be “installed” on a computer for it to run. You can download the standard ruby runtime and copy it to a folder of your choosing, running it from that location. If you want to call ruby or any of it’s components from anywhere on your system, you just need to add a reference to the path you copied it to, in your PATH environment variables.  In a Windows environment, the easiest way to get Ruby on your system is to use the installer packages over at http://RubyInstaller.org – but again, you don’t need to use the installer. You can also use the 7zip package and just unpack it anywhere you want.

 

Get The Ruby Runtime

Since the ruby runtime itself is xcopy deployable, this means that every ruby script and binary is also xcopy deployable. You can run your gems and the gem system itself from the same arbitrary path that the ruby runtime is installed into, because ruby and rubygems are smart enough to install all of these packages into the runtime folder structure.

After downloading the ruby runtime (I recommend v1.8.7 at this point), unpack it into your project folder. You should see three folders that represent all of the ruby needs for your system.

image

And that it’s! you’re done! You can now run ruby from the “bin” folder that you just unpacked. Any .rb script file that you want to run can now be run by calling the “ruby” command from this folder.

To verify your ruby runtime, open a command prompt in this folder and you should be able to check the ruby version like this:

 image

Here, you can see that I’m running v1.8.7, with the patch level and release date, etc.

 

Installing Your Gems

The RubyGems system is quite amazing in both it’s simplicity and it’s functionality. It allows you to install pre-packaged scripts and binaries that provide a wealth of new functionality and capabilities for your ruby installation. To install a gem, just run “gems install <gemname>” from the same command prompt that you have open. For example, you can install Albacore like this:

 image

You can see that running “gem install albacore” brought more than just albacore down to the computer. Albacore has provided a list of required gems that it needs to run and the gem system has automatically downloaded and installed them for you. But the best part about this is that albacore and all of it’s dependencies were installed into the ruby folder structure that we executed the gem system from.

image

You can see the entire folder structure for the ruby runtime is set up to be a self contained sandbox. This gives us a lot of flexibility in how we setup and configure specific versions of the ruby runtime, allowing multiple copies of the same version on the same machine even (as I’m writing this, I have 2 distinct copies of ruby 1.8.7 on my machine, plus IronRuby and Ruby 1.8.6).

 

Commit To Source Control And Ship It To Your Team / Build Server

Let’s use a little bit of magic internet time now and fast forward to the point where you have your actual project set up and running inside of the “C:DevMyProject” folder from my example screen shots. Once you’ve got this going and you have your rakefile built, you just need to commit the entire “ruby” folder structure to your source control system. Doing this will allow all other project members – including your build server – to have direct access to the specific version and configuration of the ruby runtime for your project. It is nothing more than another tool that is committed to your source control system, like nant, structuremap, ncover, etc.

If you want to make it easy for people to run your rakefile without having to remember to type in the “rubybin” path, you can create a simple batch file like this:

image

The Rake system was installed with albacore, as one of the dependencies. Running “rubybinrake” from the project’s root folder will tell it Rake to execute the “rakefile.rb” script. Adding a “build.cmd” batch file will make this a no-brainer for the entire team.

 

Other Considerations

For those of you who have been worried about the cost of installing and maintaining the ruby runtime and it’s various dependencies for your rakefile, I hope this will give you some insight into how you can handle that. If your team is worried about using non-Microsoft technologies, you can still get albacore running (though with a few limitations) using IronRuby. IronRuby can be treated as just another ruby runtime, and all of the xcopy deployment that I’ve shown here works the same.

Not every project that runs a rakefile should do this, though. The ruby runtime is a 28 meg folder structure without any of the gems that you’ll need. Smaller projects, open source projects or teams that are already familiar with ruby should probably opt for the team members maintaining their own local installations of the ruby runtime. However, on a larger team where the 28 meg cost is insignificant compared the rest of the project, this setup may help to provide a few more options to the team.


Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs SignalLeaf.com - the amazingly awesome podcast audio hosting service that everyone should be using, and WatchMeCode.net where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in Albacore, Rake, Ruby, Source Control. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • mendicant

    Damn. That’s actually an awesome idea, especially for the build servers. Nice one!

  • http://therightstuff.de/ Alexander Groß

    I’m also a fan of self-contained repositories. That’s why I added the same for Machine.Specifications (and my work projects). It’s great that you don’t have to manage build servers. Plus, for open source development, it lowers the barrier for newbies if they don’t have to install extra tools before compiling.

    My build.cmd is a bit more complex and allows you to re-run the build jst by hitting return (if you don’t build on the server).
    http://github.com/machine/machine.specifications/blob/master/build.cmd

    Alex

  • http://sharpbites.blogspot.com alberto

    Man, this is awesome! Having to rely on manually install ruby and all the required gems was a no-go for me. As you mentioned, with 28 meg it still is a bit of a fat pig, but it not something I would worry a lot about. (except maybe for sucking all my github space)

    Thanks for the great post.

  • http://therightstuff.de Alexander Groß

    Alberto, you can strip down Ruby and Rake considerably – have a look at MSpec, we only require 2,7 MB.

  • http://www.lostechies.com/members/derick.bailey/default.aspx derick.bailey

    @Alexander,

    nice! I was wondering if that was possible, but haven’t had a chance to look into it. glad to know it can be done! that will make the footprint much smaller and more likely to be included in small projects. :)

  • http://sharpbites.blogspot.com alberto

    @Alexander thanks!