How to compile ruby to executable? (Linux)

Hi, everyone!

I’m wondering how I could compile my .rb file to executable? I know that
there’s rubyscript2exe and allinoneruby but I have problem using them.
When I type “rubyscript2exe” or “allinoneruby” to command line, it says
“command not found”.

I installed both with rubygems.

Can anyone help me with this?

When I put…

ruby /var/lib/gems/1.8/gems/rubyscript2exe-0.5.3/lib/rubyscript2exe.rb
./textinput.rb

…it doesn’t make executable file…

$ locate allinoneruby | grep bin

That gives nothing, but I know that it’s in this directory:

/var/lib/gems/1.8/gems/rubyscript2exe-0.5.3/bin

And no I haven’t other executable programs installed with gem.

I did that export with “/var/lib/gems/1.8/bin” directory but now I get
following error message when trying to compile:

/var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5:in
replace': can't modify frozen string (TypeError) from /var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5 from /var/lib/gems/1.8/bin/allinoneruby:19:inload’
from /var/lib/gems/1.8/bin/allinoneruby:19

How I can take away that directory from $PATH?

I did that export with “/var/lib/gems/1.8/bin” directory but now I
get following error message when trying to compile:

/var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5:in
replace': can't modify frozen string (TypeError) from /var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5 from /var/lib/gems/1.8/bin/allinoneruby:19:inload’
from /var/lib/gems/1.8/bin/allinoneruby:19

How I can take away that directory from $PATH?

Why would you want to remove that directory from your PATH?

If you do, then next time you want to run a gem, you’d need to repeat
this process.

But if you insist, then just remove the export statement from
your .bashrc and open a new shell and it should be back to its usual,
non-gem running self.

As I said, I don’t use any of those ruby compilers, so unfortunately I
can’t help you with your error there.

John

Is there other compilers than these then?

On Fri, 17 Dec 2010 21:54:32 +0900
Toni T. [email protected] wrote:

Can you run other programs you have installed with rubygems?

Perhaps they are not in your PATH.

In a shell do:

$ locate allinoneruby | grep bin

To see if you can find where the program is installed.

Then do:

$ echo $PATH

to see your path. Is that directory on the list?

If not then you need to

export PATH=“/path/to/gem/bin/dir:$PATH”

in your .bashrc, or whatnot.

Note:
On my system, ruby executables are installed to /usr/local/bin.

Another note: I have no experience with these particular gems - this is
just what I would normally do when I have this sort of problem.

Is there other compilers than these then?

There’s a JRuby compiler that I’ve never used
http://kenai.com/projects/jruby/pages/JRubyCompiler

But that compiles to java class files, rather than linux executables.

On Fri, Dec 17, 2010 at 8:22 AM, John M. [email protected]
wrote:

Is there other compilers than these then?

There’s a JRuby compiler that I’ve never used
http://kenai.com/projects/jruby/pages/JRubyCompiler

But that compiles to java class files, rather than linux executables.

And rawr makes Linux, OS X, and Windows executables out of JRuby
programs.

http://rawr.rubyforge.org/

On Sat, Dec 18, 2010 at 9:49 AM, Eric C.
[email protected] wrote:

On Fri, Dec 17, 2010 at 8:22 AM, John M. [email protected] wrote:

Is there other compilers than these then?

There’s a JRuby compiler that I’ve never used
http://kenai.com/projects/jruby/pages/JRubyCompiler

There’s generally two reasons to compile Ruby to JVM bytecode ahead of
time:

  • To hide the code
  • To create a “normal” Java class

Neither are necessary to bundle Ruby code into a single executable jar
or exe, as Eric mentions that rawr (and now warbler) can do.

But that compiles to java class files, rather than linux executables.

And rawr makes Linux, OS X, and Windows executables out of JRuby programs.

http://rawr.rubyforge.org/

Rawr is a great option, if a bit undermaintained. Nick S.'s
warbler can also take an arbitrary project/app/lib and bundle it into
an executable .jar file. Then you just need Java installed somewhere,
which is generally pretty easy.

  • Charlie