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.
3 Answers
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.

- 322,767
- 57
- 360
- 340
whereis ruby
in a Terminal window will tell you

- 232,980
- 40
- 330
- 338

- 31
- 1
-
3Generally, `which` is more reliable than `whereis`. `which` will find the one that's actually in your path, while `whereis` will look in certain standard directories; if you have non-standard directories in your path (like `/opt/local/bin` for MacPorts), `whereis` won't find what you're looking for. – Brian Campbell Nov 27 '11 at 17:11
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.

- 85
- 1
- 9