Where is the Ruby interpreter located?

I am 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 interpretation / parsing.

+8
ruby interpreted-language interpreter
source share
3 answers

You can run which ruby to find out where the ruby ​​will look if you type ruby in the terminal.

If you want to find additional information about the artist, 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, run which ruby and pass the results of this to ls -l , which will show you that this is actually a symbolic link to the binary in the Ruby structure. You can also use file to find out which file it has:

 $ 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 that you are executing a ruby ​​that is in the user's path from the 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 almost all modern systems have an executable in /usr/bin/env that will execute a utility that you pass to it based on your path; so instead of hardcoding /usr/bin/ruby in your script, you can let env look for your path for you.

+13
source share

whereis ruby in the terminal window will tell you

+3
source share

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

running which ruby will give you the exact location of the ruby ​​used if your system has one or more implementations.

+2
source share

All Articles