# Getting Ruby Path at runtime?

**URL:** <https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538>\
**Category:** Ruby\
**Created:** [July 27, 2007, 11:41am UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538 "2007-07-27T11:41:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 27, 2007, 11:41am UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/1 "2007-07-27T11:41:34Z")

</div>

Is it possible to find out under Windows, which Ruby has been used to  
run a program?  
Example: A program is invoked by

```
C:\inst\ruby186\bin\ruby.exe appl.rb

```

Is it then possible to find out inside appl.rb the whole path

C:\inst\ruby186\bin\ruby.exe

? If not, is it at least possible to find out

- the Ruby version (1.8.6) and
- whether it is executed by Ruby or JRuby?

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 27, 2007, 11:56am UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/2 "2007-07-27T11:56:35Z")

</div>

Le 27 juillet à 11:41, Ronald F. a écrit :

> - the Ruby version (1.8.6) and

You have the RUBY\_VERSION constants and a few others :

> > RUBY\_VERSION  
> > =\> “1.8.6”
> 
> > RUBY\_PLATFORM  
> > =\> “i386-freebsd6”
> 
> > RUBY\_RELEASE\_DATE  
> > =\> “2007-03-13”
> 
> > RUBY\_PATCHLEVEL  
> > =\> 0

And the same, without RUBY\_.

> - whether it is executed by Ruby or JRuby?

You probably have other constants telling you that. I’d suggest you  
inspect the contents of Object.constants to find them.

Fred

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 27, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/3 "2007-07-27T15:09:54Z")

</div>

On Jul 27, 2007, at 4:41 AM, Ronald F. wrote:

> ?  
> Sure:

Firefly:~/Desktop$ /usr/local/bin/ruby find\_ruby.rb  
/usr/local/bin/ruby  
Firefly:~/Desktop$ /usr/bin/ruby find\_ruby.rb  
/usr/bin/ruby  
Firefly:~/Desktop$ cat find\_ruby.rb  
#!/usr/bin/env ruby -wKU

require “rbconfig”

puts File.join(Config::CONFIG[“bindir”], Config::CONFIG  
[“ruby\_install\_name”])

**END**

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 27, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/4 "2007-07-27T15:20:57Z")

</div>

On 7/27/07, Ronald F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ? If not, is it at least possible to find out
> 
> - the Ruby version (1.8.6) and
> - whether it is executed by Ruby or JRuby?

You can do a check for the JRUBY\_VERSION constant. If it exists then you  
are  
using jruby.

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 30, 2007, 9:20am UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/5 "2007-07-30T09:20:45Z")

</div>

> > Is it possible to find out under Windows, which Ruby has  
> > been used to  
> > run a program?

> require “rbconfig”
> 
> puts File.join(Config::CONFIG[“bindir”], Config::CONFIG  
> [“ruby\_install\_name”])

Great!!!

May I ask where I can find a documentation about rbconfig?  
Maybe there is other useful stuff in it.

I checked [http://stdlib-doc.rubyforge.org/rdoc/index.html](http://stdlib-doc.rubyforge.org/rdoc/index.html),  
but rbconfig was not mentioned.

Or does the fact that rbconfig is not mentioned in the  
standard library page, mean, that these configuration  
variables (bindir, ruby\_install\_name) are not part of  
the official Ruby API? I would like to keep my programs  
upward compatible (to future Ruby versions), plus compatible  
to JRuby, as much as possible.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 30, 2007, 9:21am UTC](https://www.ruby-forum.com/t/getting-ruby-path-at-runtime/110538/6 "2007-07-30T09:21:45Z")

</div>

> > […] is it at least possible to find out
> > 
> > - the Ruby version (1.8.6) and
> > - whether it is executed by Ruby or JRuby?
> 
> You can do a check for the JRUBY\_VERSION constant. If it  
> exists then you are  
> using jruby.

Thanks a lot.

Ronald
