Ruby comes pre-installed on Macs. To verify and check the version you have, open the Terminal.app in your /Applications/Utilities folder and type
You should get back something like:
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
Don’t worry if the version is not exactly the same as shown here, but you should be on at least ruby 2.0.
You can find out more about your ruby installation by typing
at the Terminal prompt. Hit the
space bar to scroll down and the
'U' key to scroll back up. Hit the
'Q' key to exit the man page.
You can use an interactive ruby shell to run ruby commands within Terminal by typing
control-D on your keyboard to quit the ruby environment.
However, for the most part, we’ll be typing our scripts into their own files, then running the file from Terminal. To do this, you save the script with a .rb extension, then call it with the command ‘ruby’. Let’s have an example.
puts "Hello Ruby World!"
Save the script as
helloworld.rb in your home folder (it’s important that you save it directly in your home folder, not buried inside another folder). In Terminal, type:
You should see the reply:
Hello Ruby World!
OK, we’ve confirmed your Ruby installation is working and that you know how to save and run a ruby script. 🙂