Ubuntu School – which: Finding Ruby

I’ve been getting my feet wet with Ruby the past couple of days and decided to post this as much for my own recollection as anything else. When you’re creating a .rb script file the first line (as with nearly all \*nix script files) contains a reference to the executable which should be used to execute the script.

“`
#!/usr/bin/ruby
“`

But what if you don’t know precisely where that file lives? The [which](http://linux.about.com/library/cmd/blcmdl1_which.htm) command will find it for you. Which is a command which provides you the fully qualified path to shell commands, and this includes script hosts like ruby.

“`
callisto:~ kdmurray$ which ruby
/usr/bin/ruby
“`

This also works for Perl, Python and any number of other executables. Ever wonder where the pwd command lives? or nano? or which itself? Go explore! This command works on most \*nix operating systems including most Linux OSes and Mac OS X.