# Which ruby is running me?

**URL:** <https://www.ruby-forum.com/t/which-ruby-is-running-me/165925>\
**Category:** Ruby\
**Created:** [April 20, 2009, 1:46am UTC](https://www.ruby-forum.com/t/which-ruby-is-running-me/165925 "2009-04-20T01:46:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [April 20, 2009, 1:46am UTC](https://www.ruby-forum.com/t/which-ruby-is-running-me/165925/1 "2009-04-20T01:46:06Z")

</div>

So I have despaired of getting mutexes, threads and forks to coexist  
peacably in Ruby. (As soon as the child process touches a mutex that  
existed in the parent… Bad Things can happen.)

So Plan B is to

- spin a thread
- to mind a fork
- that just execs  
a new instance of Ruby.

Now I tend to have several versions of Ruby lying around on my Box.

What is the One True Way of finding the path to _the_ instance of ruby  
that is currently executing this script?

GNU “Make” is pretty good about this, it has a $(MAKE) variable that  
gives the exact path of make that is running.

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [April 20, 2009, 1:51am UTC](https://www.ruby-forum.com/t/which-ruby-is-running-me/165925/2 "2009-04-20T01:51:57Z")

</div>

On Apr 19, 2009, at 6:45 PM, John C. wrote:

> What is the One True Way of finding the path to _the_ instance of ruby  
> that is currently executing this script?

I’m pretty sure this always works:

$ ruby -r rbconfig -e ‘p File.join(Config::CONFIG.values\_at(\*%w[bindir  
ruby\_install\_name])) + Config::CONFIG[“EXEEXT”]’  
“/usr/local/bin/ruby”

James Edward G. II

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [April 20, 2009, 3:46am UTC](https://www.ruby-forum.com/t/which-ruby-is-running-me/165925/3 "2009-04-20T03:46:36Z")

</div>

On Mon, 20 Apr 2009, James G. wrote:

> On Apr 19, 2009, at 6:45 PM, John C. wrote:
> 
> > What is the One True Way of finding the path to _the_ instance of ruby  
> > that is currently executing this script?
> 
> I’m pretty sure this always works:
> 
> $ ruby -r rbconfig -e ‘p File.join(Config::CONFIG.values\_at(\*%w[bindir  
> ruby\_install\_name])) + Config::CONFIG[“EXEEXT”]’  
> “/usr/local/bin/ruby”

Thanks! Ooo… a tad ugly though… Ah, well, at least I wasn’t missing  
the obvious for a change. 🙂

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [April 21, 2009, 12:13am UTC](https://www.ruby-forum.com/t/which-ruby-is-running-me/165925/4 "2009-04-21T00:13:02Z")

</div>

On Apr 19, 2009, at 6:44 PM, John C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > $ ruby -r rbconfig -e ‘p File.join(Config::CONFIG.values\_at(\*  
> > %w[bindir ruby\_install\_name])) + Config::CONFIG[“EXEEXT”]’  
> > “/usr/local/bin/ruby”
> 
> Thanks! Ooo… a tad ugly though… Ah, well, at least I wasn’t missing  
> the obvious for a change. 🙂

require ‘rubygems’  
Gem.ruby

$ ruby -rubygems -e ‘p Gem.ruby’  
“/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby”  
$ ruby18 -rubygems -e ‘p Gem.ruby’  
“/usr/local/bin/ruby18”  
$ ruby19 -e ‘p Gem.ruby’ # require ‘rubygems’ is automatic on 1.9  
“/usr/local/bin/ruby19”
