Distributing your Ruby program as a standalone executable (exe)

Since ruby is an interpreted language, whenever you want to release your program you need to release the source code. Also your program users must install Ruby virtual machine before they can run your program. Is there a way to distribute ruby program as a standalone executable?

Erik Veenstra has created a nifty tool called RubyScript2Exe which can convert your ruby program to an executable program. It achieves this by combining ruby interpreter code and your source code files into a single exe file.

First download the RubyScript2Exe tool from here. It is a ruby program (950kb size). Create a simple ruby program called helloworld.rb and save it to the same location where RubyScript2Exe.rb is stored.

puts "Hello World"

From the command prompt, type the following,

ruby rubyscript2exe helloworld.rb

You will see the following output on console. Now you have a standalone executable program (helloworld.exe) which can be executed in any Windows machine! Combined with Win32API, you can create cool command line apps for Windows.

creating windows exe using ruby

The only problem with this executable is that it contains the entire ruby VM and hence is large (helloworld.exe size is around 1.5MB). Also note that this is not really a ruby compiler. It doesn’t convert your ruby code to machine code. It only packages ruby virtual machine along with your ruby code. Hence the code is still interpreted.

RubyScript2Exe can also create executable files for Linux and Mac OS X (Darwin). RubyScrip2Exe is released under GNU GPL license.

3 Responses to “Distributing your Ruby program as a standalone executable (exe)”

  1. $ ruby rubyscript2exe.rb helloworld.rb
    rubyscript2exe.rb:621:in `replace’: can’t modify frozen string (TypeError)
    from rubyscript2exe.rb:621
    from rubyscript2exe.rb:577:in `newlocation’
    from rubyscript2exe.rb:505:in `newlocation’
    from rubyscript2exe.rb:472:in `newlocation’
    from rubyscript2exe.rb:505:in `newlocation’
    from rubyscript2exe.rb:577:in `newlocation’
    from rubyscript2exe.rb:619

  2. Please not that rubyscript2exe is apparently discontinued. Other alternatives include Ocra. Good luck :)

  3. so if you have to include your source, anyone can copy your source and sell it ? How do we protect our code then?

Leave a Reply