Inside a ruby script, how do I get the path to the ruby interpreter?
Example script:
#!/path/to/ruby
puts `#{RUBY_INTERPRETER_PATH} -e \"puts \'h
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"
To get the path of the currently running ruby interpreter:
require 'rbconfig'
RUBY_INTERPRETER_PATH = File.join(RbConfig::CONFIG["bindir"],
RbConfig::CONFIG["RUBY_INSTALL_NAME"] +
RbConfig::CONFIG["EXEEXT"])