# How to compile ruby to executable? (Linux)

**URL:** <https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171>\
**Category:** ruby-talk\
**Created:** [17 December 2010 12:54 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171 "2010-12-17T12:54:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toni\_Tanskanen](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@Toni\_Tanskanen](https://rubytalk.org/u/Toni_Tanskanen)\
**Post date:** [17 December 2010 12:54 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/1 "2010-12-17T12:54:32Z")

</div>

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?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Toni\_Tanskanen](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@Toni\_Tanskanen](https://rubytalk.org/u/Toni_Tanskanen)\
**Post date:** [17 December 2010 13:10 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/2 "2010-12-17T13:10:13Z")

</div>

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...

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![John\_Morrice](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@John\_Morrice](https://rubytalk.org/u/John_Morrice)\
**Post date:** [17 December 2010 13:15 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/3 "2010-12-17T13:15:42Z")

</div>

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.

> **···**
>
> On Fri, 17 Dec 2010 21:54:32 +0900 Toni Tanskanen \<hakoukko@gmail.com\> wrote:
> 
> > 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?

---

<div class="post-metadata">

**Author:** ![Toni\_Tanskanen](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@Toni\_Tanskanen](https://rubytalk.org/u/Toni_Tanskanen)\
**Post date:** [17 December 2010 13:36 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/4 "2010-12-17T13:36:31Z")

</div>

$ 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)  
&nbsp;&nbsp;from /var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5  
&nbsp;&nbsp;from /var/lib/gems/1.8/bin/allinoneruby:19:in `load'  
&nbsp;&nbsp;from /var/lib/gems/1.8/bin/allinoneruby:19

How I can take away that directory from $PATH?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Toni\_Tanskanen](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@Toni\_Tanskanen](https://rubytalk.org/u/Toni_Tanskanen)\
**Post date:** [17 December 2010 14:11 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/5 "2010-12-17T14:11:48Z")

</div>

Is there other compilers than these then?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![John\_Morrice](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@John\_Morrice](https://rubytalk.org/u/John_Morrice)\
**Post date:** [17 December 2010 14:04 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/6 "2010-12-17T14:04:29Z")

</div>

> 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)  
> &nbsp;&nbsp;from /var/lib/gems/1.8/gems/allinoneruby-0.2.11/bin/allinoneruby:5  
> &nbsp;&nbsp;from /var/lib/gems/1.8/bin/allinoneruby:19:in `load'  
> &nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![John\_Morrice](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@John\_Morrice](https://rubytalk.org/u/John_Morrice)\
**Post date:** [17 December 2010 14:22 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/7 "2010-12-17T14:22:14Z")

</div>

> Is there other compilers than these then?

There's a JRuby compiler that I've never used  
[http://kenai.com/projects/jruby/pages/JRubyCompiler](http://kenai.com/projects/jruby/pages/JRubyCompiler)

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

---

<div class="post-metadata">

**Author:** ![Eric\_Christopherson](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/eric_christopherson/32/1849_2.png) [@Eric\_Christopherson](https://rubytalk.org/u/Eric_Christopherson)\
**Post date:** [18 December 2010 15:49 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/8 "2010-12-18T15:49:33Z")

</div>

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

[http://rawr.rubyforge.org/](http://rawr.rubyforge.org/)

> **···**
>
> On Fri, Dec 17, 2010 at 8:22 AM, John Morrice \<spoon@killersmurf.com\> 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](http://kenai.com/projects/jruby/pages/JRubyCompiler)
> > 
> > But that compiles to java class files, rather than linux executables.

---

<div class="post-metadata">

**Author:** ![Charles\_Nutter](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/charles_nutter/32/2567_2.png) [@Charles\_Nutter](https://rubytalk.org/u/Charles_Nutter)\
**Post date:** [18 December 2010 17:36 UTC](https://rubytalk.org/t/how-to-compile-ruby-to-executable-linux/61171/9 "2010-12-18T17:36:10Z")

</div>

> > > Is there other compilers than these then?
> > 
> > There's a JRuby compiler that I've never used  
> > [http://kenai.com/projects/jruby/pages/JRubyCompiler](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/](http://rawr.rubyforge.org/)

Rawr is a great option, if a bit undermaintained. Nick Sieger'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

> **···**
>
> On Sat, Dec 18, 2010 at 9:49 AM, Eric Christopherson \<echristopherson@gmail.com\> wrote:
> 
> > On Fri, Dec 17, 2010 at 8:22 AM, John Morrice \<spoon@killersmurf.com\> wrote:
