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

570 views
Skip to first unread message

Daniel Loureiro

unread,
Sep 26, 2016, 4:21:43 PM9/26/16
to Ruby on Rails: Talk
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:

Thanks.




Daniel Loureiro

unread,
Sep 26, 2016, 4:29:40 PM9/26/16
to Ruby on Rails: Talk
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

Jesse Zink

unread,
Oct 8, 2017, 12:54:49 PM10/8/17
to Ruby on Rails: Talk
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?

Daniel Loureiro

unread,
Oct 8, 2017, 7:28:34 PM10/8/17
to rubyonra...@googlegroups.com
Hi Jesse,

Rb2exe project uses Traveling Ruby (TR) binaries:

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.

--
Daniel Loureiro
------------------------------

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/eAxJf-lA-IA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c54f7a25-d0ed-4458-9218-a28e7c5dbbbf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages