# $: - where does it get its initial values?

**URL:** <https://rubytalk.org/t/where-does-it-get-its-initial-values/7259>\
**Category:** ruby-talk\
**Created:** [6 August 2003 20:23 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259 "2003-08-06T20:23:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tuan\_Bui1](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@Tuan\_Bui1](https://rubytalk.org/u/Tuan_Bui1)\
**Post date:** [6 August 2003 20:23 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/1 "2003-08-06T20:23:35Z")

</div>

Howdy,

Where does $: get its values from? The book says that it contains an  
array of places to search for loaded files and that it is “initialized  
to the list of standard directories, plus any additional ones you  
specify using RUBYLIB and -I.” Where does ruby get these standard  
directories? I realize that I can set up RUBYLIB in my environment if I  
want to search directories I specify, but I am mystified as to the  
origin of the directories originally in $: . Any help would be welcome.

Thanks,  
Tuan

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [6 August 2003 20:33 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/2 "2003-08-06T20:33:51Z")

</div>

They are figured out during Ruby build by configure and then hardcoded into  
the resulting executable. If your ruby is installed in /usr/local you can  
check it with

$ strings /usr/local/bin/ruby | grep /usr/local  
/usr/local/lib/ruby/site\_ruby/1.6  
/usr/local/lib/ruby/site\_ruby/1.6/i686-linux  
/usr/local/lib/ruby/site\_ruby  
/usr/local/lib/ruby/1.6  
/usr/local/lib/ruby/1.6/i686-linux  
/usr/local/bin:/usr/ucb:/usr/bin:/bin:.

Gennady.

> **···**
>
> ----- Original Message -----  
> From: “Tuan Bui” [tuanbui@cray.com.nospam](mailto:tuanbui@cray.com.nospam)  
> Newsgroups: comp.lang.ruby  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Wednesday, August 06, 2003 1:23 PM  
> Subject: $: - where does it get its initial values?
> 
> > Howdy,
> > 
> > Where does $: get its values from? The book says that it contains an  
> > array of places to search for loaded files and that it is “initialized  
> > to the list of standard directories, plus any additional ones you  
> > specify using RUBYLIB and -I.” Where does ruby get these standard  
> > directories? I realize that I can set up RUBYLIB in my environment if I  
> > want to search directories I specify, but I am mystified as to the  
> > origin of the directories originally in $: . Any help would be welcome.
> > 
> > Thanks,  
> > Tuan

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [6 August 2003 21:56 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/3 "2003-08-06T21:56:50Z")

</div>

In ruby.c, look for rb\_load\_path and calls to ruby\_incpush; it is set from a  
series of compile-time constants and/or environmnet variables.

```
if (rb_safe_level() == 0) {
    ruby_incpush(getenv("RUBYLIB"));
}

```

#ifdef RUBY\_SEARCH\_PATH  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_SEARCH\_PATH));  
#endif

```
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));

```

#ifdef RUBY\_SITE\_THIN\_ARCHLIB  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_SITE\_THIN\_ARCHLIB));  
#endif  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_SITE\_ARCHLIB));  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_SITE\_LIB));

```
ruby_incpush(RUBY_RELATIVE(RUBY_LIB));

```

#ifdef RUBY\_THIN\_ARCHLIB  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_THIN\_ARCHLIB));  
#endif  
ruby\_incpush(RUBY\_RELATIVE(RUBY\_ARCHLIB));

```
if (rb_safe_level() == 0) {
    ruby_incpush(".");
}

```

> **···**
>
> On Thu, Aug 07, 2003 at 05:23:35AM +0900, Tuan Bui wrote:
> 
> > Where does $: get its values from? The book says that it contains an  
> > array of places to search for loaded files and that it is “initialized  
> > to the list of standard directories, plus any additional ones you  
> > specify using RUBYLIB and -I.” Where does ruby get these standard  
> > directories?

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Ben\_Giddings](https://rubytalk.org/u/Ben_Giddings)\
**Post date:** [6 August 2003 20:57 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/4 "2003-08-06T20:57:33Z")

</div>

This may have been the cause of problems I had when using ruby-mysql. My Ruby  
binary was compiled for generic i386, but mysql was compiled for i686 so it  
wanted to go in /usr/local/lib/ruby/site\_ruby/i686-linux. The end result was  
that I had an i386-linux and an i686-linux directory, but only one was being  
searched. I got around that by using -I and/or setting an environment  
variable… but it seems like it should be possible for Ruby to “figure this  
out”. Am I asking too much of it?

Ben

> **···**
>
> On Wed August 6 2003 4:33 pm, Gennady wrote:
> 
> > They are figured out during Ruby build by configure and then hardcoded into  
> > the resulting executable. If your ruby is installed in /usr/local you can  
> > check it with
> > 
> > $ strings /usr/local/bin/ruby | grep /usr/local  
> > /usr/local/lib/ruby/site\_ruby/1.6  
> > /usr/local/lib/ruby/site\_ruby/1.6/i686-linux  
> > /usr/local/lib/ruby/site\_ruby  
> > /usr/local/lib/ruby/1.6  
> > /usr/local/lib/ruby/1.6/i686-linux  
> > /usr/local/bin:/usr/ucb:/usr/bin:/bin:.

---

<div class="post-metadata">

**Author:** ![Marko\_Schulz](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Marko\_Schulz](https://rubytalk.org/u/Marko_Schulz)\
**Post date:** [6 August 2003 21:25 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/5 "2003-08-06T21:25:45Z")

</div>

:

How do you know, all strings with /usr/local in the ruby-executable  
make up this path? Isn’t easier, just to print out $: without any  
-I or RUBYLIB?

$ (unset RUBYLIB; ruby -e ‘p $:’)  
[“/usr/local/lib/site\_ruby/1.6”, “/usr/local/lib/site\_ruby/1.6/i386-linux”, “/usr/local/lib/site\_ruby”, “/usr/lib/ruby/1.6”, “/usr/lib/ruby/1.6/i386-linux”, “.”]

> **···**
>
> On Thu, Aug 07, 2003 at 05:33:51AM +0900, Gennady wrote:
> 
> > They are figured out during Ruby build by configure and then hardcoded into  
> > the resulting executable. If your ruby is installed in /usr/local you can  
> > check it with
> > 
> > $ strings /usr/local/bin/ruby | grep /usr/local  
> > /usr/local/lib/ruby/site\_ruby/1.6  
> > –  
> > marko schulz

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [6 August 2003 21:35 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/6 "2003-08-06T21:35:43Z")

</div>

> > They are figured out during Ruby build by configure and then hardcoded  
> > into  
> > the resulting executable. If your ruby is installed in /usr/local you  
> > can  
> > check it with
> > 
> > $ strings /usr/local/bin/ruby | grep /usr/local  
> > /usr/local/lib/ruby/site\_ruby/1.6  
> > :
> 
> How do you know, all strings with /usr/local in the ruby-executable  
> make up this path? Isn’t easier, just to print out $: without any  
> -I or RUBYLIB?

I did not mention that they ALL make up LOADPATH, I just showed the way to  
see that whatever makes up the default path is hardcoded during make  
process.

> $ (unset RUBYLIB; ruby -e ‘p $:’)  
> [“/usr/local/lib/site\_ruby/1.6”,  
> “/usr/local/lib/site\_ruby/1.6/i386-linux”, “/usr/local/lib/site\_ruby”,  
> “/usr/lib/ruby/1.6”, “/usr/lib/ruby/1.6/i386-linux”, “.”]

The original question was just this: why $: is what it is?

> **···**
>
> ----- Original Message -----  
> From: “Marko Schulz” [in6x059@public.uni-hamburg.de](mailto:in6x059@public.uni-hamburg.de)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Wednesday, August 06, 2003 2:25 PM  
> Subject: Re: - where does it get its initial values?
> 
> > On Thu, Aug 07, 2003 at 05:33:51AM +0900, Gennady wrote:
> 
> > –  
> > marko schulz

---

<div class="post-metadata">

**Author:** ![Anders\_K\_Madsen1](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Anders\_K\_Madsen1](https://rubytalk.org/u/Anders_K_Madsen1)\
**Post date:** [6 August 2003 21:43 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/7 "2003-08-06T21:43:43Z")

</div>

[snip]

> This may have been the cause of problems I had when using ruby-mysql. My  
> Ruby binary was compiled for generic i386, but mysql was compiled for i686 so  
> it wanted to go in /usr/local/lib/ruby/site\_ruby/i686-linux. The end result  
> was that I had an i386-linux and an i686-linux directory, but only one was  
> being searched. […]

Couldn’t you have solved that by symlinking  
/usr/local/lib/ruby/site\_ruby/i686-linux to  
/usr/local/lib/ruby/site\_ruby/i386-linux?

> **···**
>
> On Thu, 7 Aug 2003 05:57:33 +0900 Ben Giddings [ben@thingmagic.com](mailto:ben@thingmagic.com) wrote:
> 
> –
> 
> - Anders K. Madsen \* [http://lillesvin.linux.dk](http://lillesvin.linux.dk) \*
> - madsen@sjovedyr.dk \* Linux, Ruby, PHP and SQL \*

---

<div class="post-metadata">

**Author:** ![Marko\_Schulz](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Marko\_Schulz](https://rubytalk.org/u/Marko_Schulz)\
**Post date:** [6 August 2003 22:02 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/8 "2003-08-06T22:02:04Z")

</div>

Even though you compile it for i686, the installer should know, that  
he has to put it in /usr/local/lib/ruby/site\_ruby/i386-linux. This is  
AFAIK what mkmf.rb does, by using rbconfig: It queries the paths, ruby  
was build with.

> **···**
>
> On Thu, Aug 07, 2003 at 05:57:33AM +0900, Ben Giddings wrote:
> 
> > This may have been the cause of problems I had when using ruby-mysql. My Ruby  
> > binary was compiled for generic i386, but mysql was compiled for i686 so it  
> > wanted to go in /usr/local/lib/ruby/site\_ruby/i686-linux. The end result was  
> > that I had an i386-linux and an i686-linux directory, but only one was being  
> > searched. I got around that by using -I and/or setting an environment  
> > variable… but it seems like it should be possible for Ruby to “figure this  
> > out”. Am I asking too much of it?
> 
> –  
> marko schulz

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Ben\_Giddings](https://rubytalk.org/u/Ben_Giddings)\
**Post date:** [6 August 2003 21:50 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/9 "2003-08-06T21:50:55Z")

</div>

Sure, had I known that mysql-ruby’s RPM was going to install into i686-linux  
(and/or create it). There are all kinds of easy ways to fix it after it has  
been installed – I’m just suggesting that if the default for installing Ruby  
binaries is to have them in an “arch-os” directory, it would make sense that  
it also knows that if arch is i686, i386 binaries will also work.

Ben

> **···**
>
> On Wed August 6 2003 5:43 pm, Anders K. Madsen wrote:
> 
> > Couldn’t you have solved that by symlinking  
> > /usr/local/lib/ruby/site\_ruby/i686-linux to  
> > /usr/local/lib/ruby/site\_ruby/i386-linux?

---

<div class="post-metadata">

**Author:** ![Anders\_K\_Madsen1](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Anders\_K\_Madsen1](https://rubytalk.org/u/Anders_K_Madsen1)\
**Post date:** [6 August 2003 22:43 UTC](https://rubytalk.org/t/where-does-it-get-its-initial-values/7259/10 "2003-08-06T22:43:56Z")

</div>

Ehrm, correct me if I’m wrong, but couldn’t you just have moved the content of  
i686-linux to i386-linux and then made the symlink?

Best regards  
madsen

> **···**
>
> On Thu, 7 Aug 2003 06:50:55 +0900 Ben Giddings [ben@thingmagic.com](mailto:ben@thingmagic.com) wrote:
> 
> > On Wed August 6 2003 5:43 pm, Anders K. Madsen wrote:
> > 
> > > Couldn’t you have solved that by symlinking  
> > > /usr/local/lib/ruby/site\_ruby/i686-linux to  
> > > /usr/local/lib/ruby/site\_ruby/i386-linux?
> > 
> > Sure, had I known that mysql-ruby’s RPM was going to install into i686-linux  
> > (and/or create it). There are all kinds of easy ways to fix it after it has  
> > been installed – I’m just suggesting that if the default for installing Ruby  
> > binaries is to have them in an “arch-os” directory, it would make sense that  
> > it also knows that if arch is i686, i386 binaries will also work.
> 
> –
> 
> - Anders K. Madsen \* [http://lillesvin.linux.dk](http://lillesvin.linux.dk) \*
> - madsen@sjovedyr.dk \* Linux, Ruby, PHP and SQL \*
