Getting IronRuby Up and Running

Writing

I wanted to have a little walk-through on getting IronRuby up and running. I am normally a C# guy and this is usually a C# blog, but I think that exposure to dynamic languages is very important. Since .net is starting to get a bit dynamic (with IronPython, Boo (kinda), IronPython, and VB.net 10 (kinda)), I think that developers are going to start seeing this stuff more and more. Because of this I have created this little walk-through, but this month if you are in the Richmond VA area we are going to have our Meet and Code dinner (on the 31st of July 2008) on dynamic languages.

This tutorial may go a little slow, but I wanted to make sure that it is accessible by absolutely anyone. So here it goes…

Step One is a pretty easy one, just go to www.ironruby.com

IronRuby

On there you will find a link to RubyForge.org and it points to here: http://rubyforge.org/projects/ironruby

RubyForge

On RubyForge is where you will find the files, and you are going to need to install TortoiseSVN in order to get them. Well, you don’t *need* TortoiseSVN, but that is what we are going to use in this tutorial. You can get TortoiseSVN here: http://tortoisesvn.net/downloads

Step Two is to use Tortoise to pull down the source.

To start this, we will first create a folder to put our source into:

IronRuby folder

You can then right click on this folder and click “SVN Checkout…”

SVN Checkout

Then once the checkout box pops up, we can then enter the svn url that we got from rubyforge: svn://rubyforge.org/var/svn/ironruby

IronRuby Get

Then you can just sit back and wait for the source to download to your local box. It is pretty big, so it may take a few minutes depending on your connection speed. Once it is done you’ll see this:

IronRuby Get Done

Once you are done getting the source you will next need to fire up Visual Studio 2008. If you don’t have Visual Studio 2008, then you can get the express edition here: http://www.microsoft.com/express/download/

Next you will browse to the folder that you downloaded the IronRuby source to. Here I downloaded it to C:\development\Ruby\IronRuby\. You can see that we have a “trunk”folder which is part of the source download, and then we have our IronRuby.sln which we are going to open.

image

You’ll likely get a warning about Microsoft.Scripting.Core about it being customized, and since it is from Microsoft you should tell it to load normally.

Security Warning

Once the project loads up, you’ll see this:

image

All that is left to do now is to build it. And you’ll hopefully see this:

image 

In order to use IronRuby you will go into the \trunk\build\debug folder (assuming you compiled in the debug mode). You will run IronRuby from the command line like this:

IronRuby command line

The first time you run it, you may get a FileLoadException telling you that it can’t load assembly ir, Version 1.0.0.0.

image

Well, this is because the IronRuby project has signing turned on, and the option for delay signing is turned on. If you look in the properties for each project you’ll see this under the “Signing” tab:

IronRuby Signing

So, what you will need to do is to open up a console window and go to the trunk folder where you downloaded ruby. There is a file there called runfirst.cmd, this contains a few commands, one of which is “sn -Vr *,31bf3856ad364e35”. This will cause the strong name validation to be skipped on the IronRuby project.

image

The first time I ran it, I got this:

image

This was because sn.exe is not in my default path, I resolved this by opening up a Visual Studio Command Prompt (if you are on Vista, right click and say “Run As Administrator”):

image

If you get this, then you need to double check and make sure you ran it as an administrator!

image

Again though, when I ran it, I still got the Strong Name Validation failure. I did a bit of research and the problem is that I am running a 64-bit version of Vista, and by default the 32-bit version of sn.exe is used. The 64-bit version of sn.exe resides in “\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64”. So, I went to the command prompt and ran this command (make sure the command prompt has been run as an administrator):

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64>sn.exe -Vr *,31bf3856ad364e35

And finally! Finally!

image

So, there you have it. IronRuby is now installed and ready to go. Pretty easy huh? Not! This is what you get for wanting to install alpha software!

Now, lets get it setup and tested. Lets add the folder with IronRuby to our path. Go to the ‘System Properties’ in the Control Panel and go to the ‘Advanced’ tab.

System Properties

At the bottom you’ll see the “Environment Variables” button:

image

Click on that, and you’ll get a popup. At the bottom you’ll see this:

System Variables

Edit the Path variable and add a semi-colon (if one isn’t already at the end) along with the path where your ir.exe is built to. Again, in my case, it is ‘;C:\development\Ruby\IronRuby\trunk\build\debug’.

Now you should be able to run ir.exe from any folder using the command line. So, I created a “HelloWorld” folder in my ‘development\Ruby\’ folder and put a HelloWorld.rb file in there.

HelloWorld

Then, from the command line, I can browse to the folder and run this file like this:

image

So, now you have Ruby all setup and in a future post we will look a bit more at setting up and running an IronRuby project. I hope this helps someone!

Loved the article? Hated it? Didn’t even read it?

We’d love to hear from you.

Reach Out

Comments (4)

  1. Thanks! This was the best tutorial I’ve seen on how to install IronRuby and how to get an .rb script running out to the console. Does anyone know how/if you can get intellisense for IronRuby into vs2008? I am starting to play around with IronRuby and Silverlight together.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More Insights

View All