How do I tell which Ruby interpreter I'm using?
Nowadays, all mainstream Ruby implementations set the RUBY_ENGINE
pseudo-constant. The values for the various implementations which I can remember off the top of my head are:
- Rubinius:
rbx
- JRuby:
jruby
- TruffleRuby:
truffleruby
- Opal:
opal
- MRuby:
mruby
- YARV: confusingly,
ruby
- MRI: even more confusingly, also
ruby
- MagLev:
maglev
- IronRuby:
ironruby
- MacRuby:
macruby
- Topaz:
topaz
How do I find the ruby interpreter?
These days (1.9+) you can use built-in methods (which are supposed to work with Jruby, etc.) like this:
RbConfig.ruby
or
Gem.ruby
$ irb --simple-prompt
>> RbConfig.ruby
=> "C:/installs/Ruby193/bin/ruby.exe"
>> Gem.ruby
=> "C:/installs/Ruby193/bin/ruby.exe"
Where is the Ruby interpreter located?
You can run which ruby
to find out where the ruby is that will execute if you type ruby
in the Terminal.
If you want to find more information out about the executable, you can run:
$ ls -l $(which ruby)
lrwxr-xr-x 1 root wheel 76 Nov 8 12:56 /usr/bin/ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
That is, execute which ruby
, and pass the results of that into ls -l
, which will show you that it's actually a symlink to the binary in the Ruby framework. You can also use file
to find out what kind of file it is:
$ file $(which ruby)
/usr/bin/ruby: Mach-O universal binary with 2 architectures
/usr/bin/ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/ruby (for architecture i386): Mach-O executable i386
If you want to make sure you execute the ruby that is in the user's path from a script, instead of hardcoding where Ruby is, you can use the following interpreter directive at the top of your script:
#!/usr/bin/env ruby
This works because pretty much all modern systems have an executable at /usr/bin/env
which will execute the utility that you pass to it based on your path; so instead of hardcoding /usr/bin/ruby
into your script, you can let env
search your path for you.
Ruby interpreter name
Here is a Linux-only solution:
p File.open("/proc/self/cmdline") { |f| f.read.sub(/\0.*/m, "") }
For Ruby 1.8, ruby.c
defines VALUE rb_argv0;
which contains this information, but that variable is not available in Ruby scripts.
How to fix Unknown ruby interpreter version (do not know how to handle): RUBY_VERSION.
Coincidentally today I am also trying to setup Jekyll and am seeing the same problem. I am using RVM and it otherwise works fine (running multiple Rails dev sites locally). When I run env | grep 'RUBY'
I get:
$ env | grep 'RUBY'
MY_RUBY_HOME=/Users/myusername/.rvm/rubies/ruby-2.0.0-p247
RUBY_VERSION=ruby-2.0.0-p247
However, I just continued and ran bundle install
, then bundle exec jekyll serve
and the site booted up without issue.
How can I get current depth of the Ruby interpreter stack?
Probably like this using caller
:
caller.length
Keep in mind that starts at a certain depth when your program spins up, so you may want to subtract that from your count.
Related Topics
How to Get Attributes That Were Defined Through Attr_Reader or Attr_Accessor
Error Installing Nokogiri 1.6.0 on MAC (Libxml2)
Using a Class Object in Case Statement
Custom Ruby Gem in Gemfile on Heroku
What Is the "Equals Greater Than" Operator => in Ruby
Ruby 2.0 How to Uninclude a Module Out from a Module After Including It
Rails 3.1 with Postgresql: Group by Must Be Used in an Aggregate Function
Getting Viewable Text Words via Nokogiri
Devise Custom Messages When Validation Fails
In Ruby, How to Output JSON from Hash and Give It Line Breaks and Tabs
Ruby - Dynamically Add Property to Class (At Runtime)
Has_Many While Respecting Build Strategy in Factory_Girl
Creating a Capistrano Task That Performs Different Tasks Based on Role
Render an Erb Template with Values from a Hash
Rbenv: Surviving Without Gemsets