This post is outdated and as David Mullet points out here, ocra is the recommended way for deploying Ruby applications on windows.
This post is about deploying Ruby apps like in “plain-old-ruby-desktop-apps-where-no-rails-is-involved” and covers only MS Windows.
——RANT MODE: ON—–
OK, now you have spent the last few days hacking together your Qt-and-Ruby application. You want to show it to your client to get some feedback on it. So you type: “Dear Mr. Client, attached to this mail you find … eh, ahem” Well, what exactly do you attach to the mail? A howto.txt that describes how to install Ruby and then use the gem command line version to install qt-ruby and whatever other dependencies your application might have? As you already know, there might be tons of problems like: Does your client have admin privileges on his computer? Is he scared to death by a command line? Do you really want to bother your client with such stuff?
No, “Ruby means less painful programming.” they told you. Well they didn’t say anything about deploying, did they?
——RANT MODE: OFF—–
tar2rubyscript takes a folder full of Ruby files (and subfolders full of Ruby files) and creates one single Ruby script that contains your whole application.
rubyscript2exe takes any ruby script, runs it, analyzes the dependencies and packages everything into one .exe file.
So here is how to deploy a Ruby desktop app. I will not go into much detail, since everything is explained very well in the tutorial on Erik’s page:
- Install tar2rubyscript and rubyscript2exe:
gem install tar2rubyscript
gem install rubyscript2exe
- Create a file named “init.rb” that requires you main application start script and put it in your top-level source code directory. tar2rubyscript will use init.rb to start your application. Mine looks like this:
The first line switches the directory, since when starting an application that was packed with tar2rubyscript, it will be extracted to a temporary directory and started from there, but you probably want the current directory to be the directory where the user double-clicked the .exe. I have stolen that line from
- Pack your application into a single ruby script (assuming that ‘source’ is a directory containing ‘init.rb’ and your application’s source code)
- Pack your application into an executable
rubyscript2exe killerapp.rb --rubyscript2exe-verboseThe parameter
--rubyscript2exe-verbosewill make rubyscript2exe give some information about what it is doing.
- You will end up with a file named killerapp.exe. Double clicking it should start your application. On any Windows PC.
This is it. Very simple, eh? However, there are some minor issues that I’d like to mention:
- As stated above, rubyscript2exe starts your application to investigate its dependencies. If you have an application that does not quit by itself, rubyscript2exe will not continue unless you quit the application manually. To avoid that, you may add the following line to the appropriate place in your application:
exit if RUBYSCRIPT2EXE.is_compiling?
Keep in mind, that some dlls do not get loaded by your application unless you really use them so if you use above line, make sure that all dlls that you app depends on have been loaded.
- When you double-click killerapp.exe, a DOS-window appears, showing the output of your application. In case of a command line application this is fine. In case of a Windows application you probably don’t want a DOS-box. Use
rubyscript2exe killerapp.rb --rubyscript2exe-rubyw
to create an executable that starts without a DOS-box.
However, if I switch off the DOS box, my Qt-Ruby application refuses to start.
- When your executable gets started, it extracts all dlls, the Ruby runtime and your application to
[Current User's Home]\eee\eee.killerapp.exeand starts from there. Your application’s dependencies might include some large dlls (e.g. QtGui4.dll which is 8 MB), so the extraction takes some time and your application startup feels somewhat slow.
In case of my application, the directory from which the application is running is 36 MB large and even after the application has quit, not everything is deleted and the dlls take up 21 MB of disk space. This is a HDD memory leak!
That’s it for now. As soon as I make progress on the latter two issues, I will update the post accordingly. I you have a hint, I would welcome your comment.