# Static Ruby

**URL:** <https://rubytalk.org/t/static-ruby/45376>\
**Category:** ruby-talk\
**Created:** [24 March 2008 18:39 UTC](https://rubytalk.org/t/static-ruby/45376 "2008-03-24T18:39:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [24 March 2008 18:39 UTC](https://rubytalk.org/t/static-ruby/45376/1 "2008-03-24T18:39:37Z")

</div>

Hi there,

typically I modify CFLAGS variable to include a pure  
static version before compiling, as in:

&nbsp;&nbsp;CFLAGS='-static'

This works for sed, grep, bash etc.. easily, but for ruby,  
this does not seem to work as straight forward.

If i invoke certain scripts that use md5 or similar "add-ons"  
I get errors such as:

&nbsp;&nbsp;[socket.so](http://socket.so): undefined symbol: rb\_eSecurityError

Sometimes different rb\_e\* Errors occur.

Someone else said that I should modify ext/Setup  
but I am wondering whether this is the default route one  
has to follow to get to a static version of ruby?

One reason i'd like to have it all inside one ruby  
binary is that I dont want to have it fail if a host  
lib is missing or broken.  
(The size penalty is of no concern at all to me.)

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

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada1](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@Nobuyoshi\_Nakada1](https://rubytalk.org/u/Nobuyoshi_Nakada1)\
**Post date:** [25 March 2008 06:49 UTC](https://rubytalk.org/t/static-ruby/45376/2 "2008-03-25T06:49:45Z")

</div>

Hi,

At Tue, 25 Mar 2008 03:39:37 +0900,  
Marc Heiler wrote in [ruby-talk:295548]:

> Someone else said that I should modify ext/Setup  
> but I am wondering whether this is the default route one  
> has to follow to get to a static version of ruby?

&nbsp;&nbsp;configure --disable-shared --with-static-linked-ext

See `configure --help' for more info.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Kyle\_Schmitt](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Kyle\_Schmitt](https://rubytalk.org/u/Kyle_Schmitt)\
**Post date:** [25 March 2008 13:26 UTC](https://rubytalk.org/t/static-ruby/45376/3 "2008-03-25T13:26:34Z")

</div>

Along with Nobuyoshi's excellent advice, make sure you look in the  
etc/Setup file. You will probably need to edit it to select which  
libs to include by default. Very useful for making small static ruby  
distributions you can move from machine to machine.

--Kyle

> **···**
>
> On Mon, Mar 24, 2008 at 1:39 PM, Marc Heiler \<shevegen@linuxmail.org\> wrote:
> 
> > Hi there,
> > 
> > typically I modify CFLAGS variable to include a pure  
> > static version before compiling, as in:
> > 
> > &nbsp;&nbsp;CFLAGS='-static'
> > 
> > This works for sed, grep, bash etc.. easily, but for ruby,  
> > this does not seem to work as straight forward.
> > 
> > If i invoke certain scripts that use md5 or similar "add-ons"  
> > I get errors such as:
> > 
> > &nbsp;&nbsp;socket.so: undefined symbol: rb\_eSecurityError
> > 
> > Sometimes different rb\_e\* Errors occur.
> > 
> > Someone else said that I should modify ext/Setup  
> > but I am wondering whether this is the default route one  
> > has to follow to get to a static version of ruby?
> > 
> > One reason i'd like to have it all inside one ruby  
> > binary is that I dont want to have it fail if a host  
> > lib is missing or broken.  
> > (The size penalty is of no concern at all to me.)  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [5 June 2008 09:18 UTC](https://rubytalk.org/t/static-ruby/45376/4 "2008-06-05T09:18:23Z")

</div>

Hi there,

Sorry for the late reply, I didn't get to recompile ruby for some  
time. I did it now with the latest 1.8.7, thanks to Nobuyoshi's hint.

The compile part worked out nicely, the resulting ruby bin/ dir took  
about ~ +1.8 MB in size.  
However there were two problems, and I played a bit with it inside  
ext/Setup as Kyle suggested but to no real avail (uncommenting #openssl  
and #fcntl and recompiling lead to some weird effect ruby was working  
but the sizes inside the ruby bin/ dir were suddenly as small as the  
shared versions...)

One problem was this here:

&nbsp;&nbsp;ssl.rb:19:in `require': no such file to load -- fcntl

The other was OpenSSL related.

&nbsp;&nbsp;openssl/ssl.rb:26: uninitialized constant OpenSSL::SSL::VERIFY\_PEER

I am a bit at a loss now 🙂

Also, if I do a "ldd ruby" i get a lot of libraries listed.  
But if i normally do a ldd on a static binary, like this

"ldd grep"

I get:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;not a dynamic executable

Appreciate more help, and thanks a lot for the pointers so far!

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