# Sudo ruby loosing environment?

**URL:** <https://www.ruby-forum.com/t/sudo-ruby-loosing-environment/138051>\
**Category:** Ruby\
**Created:** [May 19, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/sudo-ruby-loosing-environment/138051 "2008-05-19T21:08:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [May 19, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/sudo-ruby-loosing-environment/138051/1 "2008-05-19T21:08:21Z")

</div>

My Ruby installation is from the Ubuntu package repository. Yesterday,  
I upgraded my system to Heron and since then one of my Ruby scripts  
stopped working. I traced the problem to this:

$ ruby -e"p ENV[‘ROLL\_PATH’]"  
“/home/trans/Company/TigerOps/programs”

$ sudo ruby -e"p ENV[‘ROLL\_PATH’]"  
nil

At first I though it might have something to do with sudo itself, but:

$ echo $ROLL\_PATH  
/home/trans/Company/TigerOps/programs

$ sudo echo $ROLL\_PATH  
/home/trans/Company/TigerOps/programs

So that’s not it. Anyone have any idea what’s going on?

My current version of Ruby is now:

$ ruby -v  
ruby 1.8.6 (2007-09-24 patchlevel 111) [x86\_64-linux]

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [May 19, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/sudo-ruby-loosing-environment/138051/2 "2008-05-19T21:47:21Z")

</div>

On Tue, May 20, 2008 at 04:07:13AM +0900, Trans wrote:

> At first I though it might have something to do with sudo itself, but:  
> Yes, it’s sudo. Your test is flawed.

> $ echo $ROLL\_PATH  
> /home/trans/Company/TigerOps/programs
> 
> $ sudo echo $ROLL\_PATH  
> /home/trans/Company/TigerOps/programs

$ROLL\_PATH is interpreted by the shell before sudo is ever invoked.

> So that’s not it. Anyone have any idea what’s going on?  
> […]

This is unrelated to Ruby or Ubuntu. This is how sudo works. Read the  
sudoers man page, looking for env\_keep. You will need to edit the  
/etc/sudoers file (with visudo, not directly).

> Thanks,  
> T.  
> –Greg

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [May 20, 2008, 4:01am UTC](https://www.ruby-forum.com/t/sudo-ruby-loosing-environment/138051/3 "2008-05-20T04:01:38Z")

</div>

On May 19, 3:46 pm, Gregory S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> $ROLL\_PATH is interpreted by the shell before sudo is ever invoked.
> 
> > So that’s not it. Anyone have any idea what’s going on?
> 
> […]
> 
> This is unrelated to Ruby or Ubuntu. This is how sudo works. Read the  
> sudoers man page, looking for env\_keep. You will need to edit the  
> /etc/sudoers file (with visudo, not directly).

Ok. That makes sense. Though I don’t yet understand what changed --it  
was working fine before the dist-upgrade.

Thanks,  
T.
