Yet another "convert ruby script into a portable executable" tool

Hi guys,

I was struggling to find a tool to convert my ruby scripts into portable executable apps. I tried a lot of solutions (crate, releasy, etc) but none of them seemed to work. They are or too complicated for my taste or just broken. So, I wrote my own tool: https://github.com/loureirorg/rb2exe

It supports Rails and Gemfile, btw. It doesn’t compile nor obfuscate the code: it just packages a stand-alone ruby interpreter, plus your project/script, into a self-extracted, self-executable file. This allows to easily distribute and execute the app on machines that don’t have a ruby installed.

I wrote it for my own needs, so it can be considered “limited” for someone purposes, but I’m sharing it here as an alternative.

In case anyone wants to hack it or understand its internals, I also wrote a step-by-step guide:

http://www.learnwithdaniel.com/2016/08/ruby-to-portable-exe-app/

Thanks.

And here are some usage examples:

Install:

gem install rb2exe

Example I - Simple script:
echo “puts ‘Hello world’” > test.rb

rb2exe test.rb
./test

Hello world

``

Example II - Multi source project:
mkdir test
cd test
echo “STR = ‘Hello world’” > a.rb
echo “load ‘a.rb’” > main.rb
echo “puts STR” >> main.rb

rb2exe main.rb --add=.
./main

Hello world

``

Example III - Gemfile support:

mkdir test
cd test
echo “source ‘https://rubygems.org’” > Gemfile
echo “gem ‘faker’” >> Gemfile
echo “require ‘faker’” > a.rb
echo ‘puts “Hello #{Faker::Name.name}”’ >> a.rb

rb2exe a.rb --add=.
./a

Hello Abbigail Okuneva

``

Example IV - Rails support:

rails new myproject
cd myproject

rb2exe --rails
./output

=> Booting Puma

=> Rails 5.0.0.1 application starting in production on http://0.0.0.0:3000

=> Run rails server -h for more startup options

Puma starting in single mode…

* Version 3.6.0 (ruby 2.2.2-p95), codename: Sleepy Sunday Serenity

* Min threads: 5, max threads: 5

* Environment: production

* Listening on tcp://0.0.0.0:3000

Use Ctrl-C to stop

``

Example V - OSX binary:
rb2exe test.rb --target=osx

``

I’d be interested in using this, but the fact that you made it require Ruby version 2.2.2 is a downfall, as I use 2.3.1 How might I make this work with 2.3.1?

Hi Jesse,

Rb2exe project uses Traveling Ruby (TR) binaries:

https://github.com/phusion/traveling-ruby

And unfortunately, it has been 3 years since their last update.

BTW, rb2exe is just a packer for TR. If you use TR, you will end up with a folder with many files. Rb2exe just packs everything into a single auto-executable zipped file.

To update rb2exe with a most recent ruby version, it will be necessary to find another standalone ruby binary. I think it’s possible to either use Ruby Ship or to update Traveling Ruby by reproducing the same steps they have used (link here).

I wish I had more time to update it, but anyways please feel free to contribute.