SundayMonday
SundayMonday

Reputation: 19767

Where is the Ruby interpreter located?

I'm using Ruby 1.8.7 on OS X. Where is the Ruby interpreter located? My goal is to learn more about Ruby, interpreted languages and interpreting/parsing.

Upvotes: 9

Views: 12491

Answers (3)

Rob v
Rob v

Reputation: 31

whereis ruby in a Terminal window will tell you

Upvotes: 3

Brian Campbell
Brian Campbell

Reputation: 333294

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.

Upvotes: 15

user680244
user680244

Reputation: 175

You should find it under System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
and symlinked to /usr/bin/ruby.

running which ruby will give you the exact location of the ruby being used if there are one or more implementations on your system.

Upvotes: 2

Related Questions