iwan
iwan

Reputation: 7569

Package and distribute Ruby batch application

I need to package Ruby application (a batch job), and distribute to other users. Ideally I don't need user to setup Ruby, and the package shall contain all the dependencies in it.

Is there easy way to do this? I am using Ruby v1.9.3.

Upvotes: 0

Views: 325

Answers (1)

Walton Hoops
Walton Hoops

Reputation: 864

Your not clear in your question, so I'll assume the following are true:

  • You and your users are on Windows
  • This is a short script with few dependencies

Given that, your best bet is probably the 'ocra' gem. With it you can package your script into an .exe using ocra <script>.rb. That will bundle your Ruby runtime, any gems your script uses, and your source into a <script>.exe file, like so:

    C:\Users\Walton>cat hello.rb
    puts 'Hello World!'

    C:\Users\Walton>ocra hello.rb
    === Loading script to check dependencies
    Hello World!
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467: Use RbConfig instead of obsolete and deprecated Config.
    === Including 52 encoding support files (5179608 bytes, use --no-enc to exclude)

    === Building hello.exe
    === Adding user-supplied source files
    === Adding ruby executable ruby.exe
    === Adding library files
    === Compressing 14898286 bytes
    === Finished building hello.exe (3261400 bytes)

    C:\Users\Walton>hello.exe
    Hello World!

Since it packages your existing ruby runtime, you should probably be running a 32-bit Ruby to ensure that your executable can run on both 32 and 64-bit platforms.

If you need something more than ocra can provide, your best bet is going to be to build an installer that packages Ruby and your application.

Upvotes: 3

Related Questions