Deploying Ruby (and QtRuby) Applications

Important Note
This post is outdated and as David Mullet points out here, ocra is the recommended way for deploying Ruby applications on windows.

Disclaimer
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—–

Luckily there guys like Erik Veenstra who think that “Ruby also means less painful deployment”. Erik wrote two tools:
tar2rubyscript
and
rubyscript2exe

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:
distributingrubyapplications

  1. Install tar2rubyscript and rubyscript2exe:
    gem install tar2rubyscript
    gem install rubyscript2exe
  2. 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:
    Dir.chdir oldlocation
    require 'main.rb'
    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
    www.erikveen.dds.nl/tar2rubyscript/#3.2.0
  3. Pack your application into a single ruby script (assuming that ‘source’ is a directory containing ‘init.rb’ and your application’s source code)
    tar2rubyscript source
  4. Pack your application into an executable
    rubyscript2exe killerapp.rb --rubyscript2exe-verboseThe parameter --rubyscript2exe-verbose will make rubyscript2exe give some information about what it is doing.
  5. 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:

  1. 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.
  2. 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.
  3. When your executable gets started, it extracts all dlls, the Ruby runtime and your application to
    [Current User's Home]\eee\eee.killerapp.exe and 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.

Happy deploying!

28 thoughts on “Deploying Ruby (and QtRuby) Applications

  1. Narasimha Raju

    Hi,

    I gone through your post and i tried “distributing rubyapplications”. but i failed at first step:

    Install tar2rubyscript and rubyscript2exe:
    gem install tar2rubyscript
    gem install rubyscript2exe

    where i am doing mistake.

    can you resolve my problem

    Reply
  2. Narasimha Raju

    Hi Tom,

    Thanks for your quick reply. while Executing first time after 1 hour it gave error like failed to get gems from gems.rubyforge.org network timeout. from next time onwords there is no response forever. My environment is Windows.

    Waiting for your reply,

    Regards,

    Narasimha Raju

    Reply
  3. admin Post author

    That looks like gem cannot reach the gem server. Make sure, that gem is not blocked by your firewall.
    Two more hints that might help you to spot the problem:
    Please try executing
    gem environment
    and make sure that the URL listed under “Remote Sources” is reachable.

    Also try
    gem query –remote –name-matches tar2rubyscript
    The command should yield
    “tar2rubyscript (0.4.8, 0.4.7, 0.4.6, 0.4.5)”
    “A Tool for Distributing Ruby Applications”

    Reply
  4. Narasimha Raju

    Hi,

    Thanks for your reply. i executed the command gem environment and i got the following responce:

    C:\Documents and Settings\ongc>gem environment
    RubyGems Environment:
    – VERSION: 0.9.4 (0.9.4)
    – INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8
    – GEM PATH:
    – c:/ruby/lib/ruby/gems/1.8
    – REMOTE SOURCES:
    http://gems.rubyforge.org

    is it ok for downloading required GEM or i need to edit???

    if edit, how to edit.

    waiting for your reply

    Regards,

    Narasimha Raju

    Reply
  5. Narasimha Raju

    Thanks for confirming,

    Now i am executing the following command in my command prompt:

    gem install tar2rubyscript
    i will be back soon with the result. lets work step by step so that if i did any mistake it is very easy to identify.

    Regards,

    Narasimha Raju

    Reply
  6. Narasimha Raju

    Hi Tom,

    I switched off my system firewall and tried to install gem but there is no response. I waited one hour then also no response., what should i do now. Is there any alternatives to install there gems.

    Waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  7. Narasimha Raju

    Hi Tom,

    Thanks for your reply. I downloaded tar2rubyscript and rubyscript2exe gems. Can you tell me how to install these gems. I never worked on gems so i dont know how to install gems .

    Waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  8. Narasimha Raju

    Hi Tom,

    I gone through some posts and i found that following command to install gem

    >gem install tar2rubyscript.gem

    i executed the it and i got the following output:
    Successfully installed tar2rubyscript, version 0.4.8

    then i executed >gem install rubyscript2exe.gem
    and i got the following output:

    Successfully installed rubyscript2exe, version 0.5.3

    This means i successfully completed first step to create distributingrubyapplications

    What should i do now.

    I am waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  9. Narasimha Raju

    Hi Tom,

    Thanks for sending reference link, i am going through it. meanwhile i am doing step 2 of distributingrubyapplications.

    In that you told that it required to create init.rb file and i did it. next you told that we required to add two lines
    Dir.chdir oldlocation
    require ‘main.rb’

    to init.rb. I added above two lines and executed the following command

    tar2rubyscript

    and it sucessfully generated one .rb file. with the name of .

    what should i do now??? whether my steps are correct or not.

    Waiting for your replly.

    Regards,

    Narasimha Raju

    Reply
  10. Narasimha Raju

    Hi Tom,

    Thanks for your guidence. I sucessfully created .exe of my application. Now i tried to run that .exe file in another system in which no ruby installed, Qt not installed.

    I double clicked on .exe file immidetly it generated the following error

    “This application has failed to start because libsmokeqt.dll was not found. Re-installing the application may fix this problem”

    Can you tell what is this error. How to resolve this error.
    I am waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  11. Narasimha Raju

    Hi Tom,

    I tried the same .exe file of my application in my working system. i did not get any error messages. It started with dos window and waited for some time. then after it closed nothing is happen.

    What is the mean. i did not get it.

    Waiting for your reply and suggestions.

    Regards,

    Narasimha Raju

    Reply
  12. Narasimha Raju

    Hi Tom,

    I think you are busy with your work. I tried all the ways but still i am getting the same error.

    Waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  13. admin Post author

    Hi Narasimha!
    Now that’s a curious problem.
    The error you are getting results in a missing dll that is not packed into the .exe. However, the name of the Dll that contains Smoke is smokeqt.dll on my system. Please check your ruby/bin directory and check, whether you actually have Dll named libsmokeqt.dll. If you don’t, try copying smokeqt.dll to libsmokeqt.dll and generate the .exe again.
    If you do have a Dll named libsmokeqt.dll, please make sure that when running rubyscript2exe the Dll is actually loaded by your program. I.e. click around a little and make sure that some Qt Widgets are opened.
    Regards
    Tom

    Reply
  14. Narasimha Raju

    Hi Tom,

    Thanks for your reply. I searched for that DLL in ruby/bin but i did not found it. How to get that DLL file. What should i do now.

    Waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  15. Narasimha Raju

    Hi Tom,

    Sorry for my late reply. I ran the same .exe file which gave error message in my system. But i did not get any error message. It opened with a dos window and after some time it closed, but no qt windows are not opened.

    I thought that my system is having libsmokeqt.dll. I searched for that DLL but search result is file not found.

    Regarding your previous reply. I gone through your post but i failed to understand. Sorry for that. Please clarify me once again. Even i googled about libsmokeqt.dll but i did not get proper information.

    Waiting for your valuable suggestions.

    Regards,

    Narasimha Raju

    Reply
  16. admin Post author

    Hi Narasimha!
    Instead of suggesting an answer, let me first aks some questions:
    1. When running rubyscript2exe, did you click around in your application to open Qt-Windows and by this making sure, all Dlls are loaded? Did your applicaton work correctly?
    2. Do you have a Dll which filename contains “smoke” in your ruby/bin directory? What is the exact name of that Dll?
    Regards
    Tom

    Reply
  17. Narasimha Raju

    Hi Tom,

    Thanks for your reply. You asked me some questions, i am sending my answers

    ans for Q1: Yes, i did that one and my application is working and all Qt windows are opening.

    ans for Q2: No, there is no such DLL filename contains “smoke” in my ruby/bin directory.

    My application size is just 60KB if possible plz give your mail id i will send it to you and test at your location becoz you have all the supportive files.

    Let us test at your location so that you also know where i did mistake(even in writing code).

    Waiting for your reply.

    Regards,

    Narasimha Raju

    Reply
  18. admin Post author

    Hi Narasimha!
    Please search your computer for *smoke*.dll. It has to be somewhere, otherwise Qt Ruby would not work at all.
    Please do not send me you application. The problem you experience is probably unrelated to your application’s code. To make sure, that your code is not the problem, please compile the Colliding Mice Example (or any other simple Qt Application) of QtRuby into an .exe file and check whether it works on a PC where neither Qt nor Ruby is installed.
    Regards Tom

    Reply
  19. Jorge Daniel Sampayo Vargas

    Hello,

    I have the same problem that Narasimha,

    I’m using ocra, not rubyscript2exe

    I created a simple helloWorld in QT with a pushbutton, deploy the exe, it runs correctly in my system, but in any other computer it says that it doesn’t found libsmokeqt.dll

    It appears than that dll is installed with qtruby4 windows installer: http://rubyforge.org/tracker/index.php?func=detail&aid=13995&group_id=181&atid=761

    And here it is described for what it is used:
    http://www.qtcentre.org/threads/19831-What-is-the-use-of-libsmokeqt-dll-for-windows

    The library in my system is in “C:\WINDOWS\system32\libsmokeqt.dll”

    If I copy that library to the client computer (it works putting it in the exe folder, it is not necessary to copy it to system32), then it ask now for QtCore4.dll, so I started copying one by one to fill the requirements of the powerful HelloWorld program.

    I copied all the dll’s from “C:\Qt\4.3.4\bin”
    This is the list of dll’s needed to be able to run the HelloWorld:
    .
    |– Qt3Support4.dll
    |– QtAssistantClient4.dll
    |– QtCore4.dll
    |– QtDesigner4.dll
    |– QtDesignerComponents4.dll
    |– QtGui4.dll
    |– QtNetwork4.dll
    |– QtOpenGL4.dll
    |– QtScript4.dll
    |– QtSql4.dll
    |– QtSvg4.dll
    |– QtTest4.dll
    |– QtXml4.dll
    `– mingwm10.dll

    Even if the program doesn’t use opengl or sql, it needs the dll’s. My solution was to generate an installer with NSIS, to copy all these dll’s(>26mb) to the install dir where it is my exe generated by ocra (

    Reply
  20. Jorge Daniel Sampayo Vargas

    It appears than my last comment was cut probably due to a limit of chars:

    Even if the program doesn’t use opengl or sql, it needs the dll’s. My solution was to generate an installer with NSIS, to copy all these dll’s(>26mb) to the install dir where it is my exe generated by ocra (1mb).

    I hope this helps someone. Sorry about my english.

    Does anyone know of a way to be able to generate the exe with orca including all of these dll’s? Sometimes a standalone exe is more welcomed than an installer.

    Best Regards.
    Jorge Sampayo.

    Reply
  21. admin Post author

    Hi Jorge!
    Thanks for the information on deploying and the list of required dlls. I think that is very helpful.

    Regarding your question of creating a standalone exe, I suggest to ask the question in the ocra forum. Usually you get an answer pretty quickly.

    The reason why even “Hello World” needs all those Qt dlls is that Qt Ruby is one big chunk. According to the kde-bindings mailing list, Richard Dale is planning to divide Qt Ruby into separate modules (but there is no schedule for that).
    Best Regards
    Tom

    Reply

Leave a Reply to Narasimha Raju Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.