# ENVnot changing env

**URL:** <https://www.ruby-forum.com/t/envnot-changing-env/111759>\
**Category:** Ruby\
**Created:** [August 10, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759 "2007-08-10T16:26:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TDR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@TDR](https://www.ruby-forum.com/u/TDR)\
**Post date:** [August 10, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759/1 "2007-08-10T16:26:49Z")

</div>

Ruby 1.8.6 on solaris 9.

I am a newbie.  
I need to set LD\_LIBRARY\_PATH within my script as follows:

ENV[‘LD\_LIBRARY\_PATH’] = ‘/usr/local/mysql/lib/mysql:/usr/local/  
easysoft/unixODBC/lib:/usr  
/local/easysoft/lib’

but it doesn’t seem to be “taking”. I get the error I would expect to  
get when LD\_LIBRARY\_PATH is not set:

[s00c166.ssa.gov](http://s00c166.ssa.gov)# ruby -r debug process\_ond.rb  
Debug.rb  
Emacs support available.

process\_ond.rb:29:def lookup\_cid(off\_id)  
(rdb:1) b 95  
Set breakpoint 1 at process\_ond.rb:95  
(rdb:1) c  
Breakpoint 1, toplevel at process\_ond.rb:95  
process\_ond.rb:95:ENV[‘LD\_LIBRARY\_PATH’] = ‘/usr/local/mysql/lib/  
mysql:/usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib’  
(rdb:1) n  
process\_ond.rb:99:$dbh\_ditm = DBI.connect(“DBI:Mysql:ditm:localhost”,  
“ditmusr”, “xxxxxx”)  
(rdb:1) n  
/usr/local/lib/ruby/site\_ruby/1.8/dbi.rb:344: `Could not load driver (ld.so.1: ruby: fatal: libmysqlclient.so.15: open failed: No such file or directory - /usr/local/lib/ruby/site_ruby/1.8/sparc-solaris2.9/ mysql.so)' (DBI::InterfaceError) from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:344:in `load\_driver’  
from /usr/local/lib/ruby/site\_ruby/1.8/dbi.rb:227:in  
`_get_full_driver' from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:213:in `connect’  
from process\_ond.rb:99  
/usr/local/lib/ruby/site\_ruby/1.8/dbi.rb:344: raise  
InterfaceError, “Could not load driver (#{$!.message})”  
(rdb:1)

But when I set LD\_LIBRARY\_PATH in my shell, prior to running the  
script, I don’t get this error:

[s00c166.ssa.gov](http://s00c166.ssa.gov)# setenv LD\_LIBRARY\_PATH ‘/usr/local/mysql/lib/mysql:/  
usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib’  
[s00c166.ssa.gov](http://s00c166.ssa.gov)# ruby -r debug  
process\_ond.rb Debug.rb  
Emacs support available.

process\_ond.rb:29:def lookup\_cid(off\_id)  
(rdb:1) b 99  
Set breakpoint 1 at process\_ond.rb:99  
(rdb:1) c  
Breakpoint 1, toplevel at process\_ond.rb:99  
process\_ond.rb:99:$dbh\_ditm = DBI.connect(“DBI:Mysql:ditm:localhost”,  
“ditmusr”, “xxxxxx”)  
(rdb:1) n

What am I doing wrong here?

TDR

---

<div class="post-metadata">

**Author:** ![TDR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@TDR](https://www.ruby-forum.com/u/TDR)\
**Post date:** [August 10, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759/2 "2007-08-10T16:36:50Z")

</div>

On 8/10/07, TDR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but it doesn’t seem to be “taking”. I get the error I would expect to  
> Breakpoint 1, toplevel at process\_ond.rb:95  
> from /usr/local/lib/ruby/site\_ruby/1.8/dbi.rb:344:in  
> script, I don’t get this error:  
> (rdb:1) c  
> Breakpoint 1, toplevel at process\_ond.rb:99  
> process\_ond.rb:99:$dbh\_ditm = DBI.connect(“DBI:Mysql:ditm:localhost”,  
> “ditmusr”, “xxxxxx”)  
> (rdb:1) n
> 
> What am I doing wrong here?
> 
> TDR

Just setting LD\_LIBRARY\_PATH in your Ruby script won’t help, as it  
doesn’t  
update the environment of the current runner (see it as nested  
environments). So what you’re doing is setting the child’s environment,  
but  
it’s the parent that goes out and loads up libraries like mysql.so.

So what you need to do is re-execute your process after setting  
LD\_LIBRARY\_PATH; something like this:

unless ENV[“LD\_LIBRARY\_PATH”].grep /easysoft/unixODBC/  
ENV[‘LD\_LIBRARY\_PATH’] =  
‘/usr/local/mysql/lib/mysql:/usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib’’  
exec(ARGV)  
end

I don’t think the above is exactly right, maybe you need \*ARGV, but it  
gets  
the point across. You need to restart the script with the appropriate  
environment settings.

Jason

---

<div class="post-metadata">

**Author:** ![TDR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@TDR](https://www.ruby-forum.com/u/TDR)\
**Post date:** [August 10, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759/3 "2007-08-10T17:09:56Z")

</div>

On Aug 10, 2007, at 8:25 AM, TDR wrote:

> ENV[‘LD\_LIBRARY\_PATH’] = ‘/usr/local/mysql/lib/mysql:/usr/local/  
> easysoft/unixODBC/lib:/usr  
> /local/easysoft/lib’

you may be clobbering an existing (required) env setting - try this:

ENV[‘LD\_LIBRARY\_PATH’] = [  
‘/foo’,  
‘/bar’,  
ENV[‘LD\_LIBRARY\_PATH’],  
].join(‘:’)

a @ [http://drawohara.com/](http://drawohara.com/)

---

<div class="post-metadata">

**Author:** ![TDR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@TDR](https://www.ruby-forum.com/u/TDR)\
**Post date:** [August 31, 2007, 8:02pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759/4 "2007-08-31T20:02:25Z")

</div>

On Aug 31, 10:10 am, TDR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in this posting, it turns out, is specific to LD\_LIBRARY\_PATH.  
> You can usually avoid setting either one (on Solaris, at least) if the  
> underlying libraries have been built with the runtime library path set  
> properly. In some case this means running the configure script, then  
> hand editing the Makefile and adding “-R /path/to/lib”.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![TDR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@TDR](https://www.ruby-forum.com/u/TDR)\
**Post date:** [August 31, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/envnot-changing-env/111759/5 "2007-08-31T18:13:10Z")

</div>

On Aug 10, 10:22 am, TDR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> get whenLD\_LIBRARY\_PATHis not set:  
> I had originally assumed this to be a problem with setting any  
> environment variables. It turns out LD\_LIBRARY\_PATH is a special  
> case. The syntax for setting environment variables in ruby worked  
> fine for TNS\_ADMIN.

Moreover, I came across a posting somewhere today that explains why  
not to use LD\_LIBRARY\_PATH, but rather LD\_RUN\_PATH. So the situation  
in this posting, it turns out, is specific to LD\_LIBRARY\_PATH.

Hope this helps someone.
