What is Ruby?
Ruby is a dynamic, open-source, lightweight, high level programming language similar to Python and Lua. It's very object oriented, is open source and is very easy to learn. Many programmers consider it a beautiful, elegant, gem of a language as its syntax is very unique and it has a bunch of really nice little features that spoil the programmer! Why wouldn't you want to learn it?
Setting Up Ruby
So before we can actually get programming, you need to setup Ruby on your machine - the steps for this vary depending on your Operating System. It's arguably more difficult to setup on Mac and Linux, however these OSes allow for more flexibility in the setup (and generally are the platforms of choice for Ruby development). To make the most out of the setup, the section of this tutorial which deals with the installation on OS X (Mac) and Linux will include the setup of RVM, the Ruby Version Manager (an easy way to have multiple versions of Ruby installed at the same time). So without any more rambling - skip to the section of this document which applies to your Operating System (Mac, Linux or Windows) to get your Ruby environment setup!
Mac and Linux
Even though I claimed that setting up Ruby on a Mac or Linux machine is more complicated than on a Windows machine, it's still reasonably easy. Since we want to use the Ruby Version Manager to allow for a really flexible install of ruby with different environments - let's start with that. To install RVM simply run the following command in the terminal:
After the install has completed, you should be instructed to add a line to your bashrc file. On OS X this file is in the etc folder and named "bashrc" but on Linux this can vary (you may want to Google where yours is located if you don't know). Simply add the line that the terminal told you to add to this file. For me, it was the following (try this if you have issues after finishing the RVM instructions):
Once you've done this, you'll probably want to run the bashrc file to apply the changes we've just made by editing it – you can do this by typing
source followed by your bashrc file name in the terminal (in the case of OS X this will simply be "bashrc") while in the same directory as the file.
Now it's worth checking if RVM has installed correctly because if the installation wasn't successful, the rest of this guide won't work properly. To do this we open a new terminal window and enter the command
rvm –v. If a version number is returned, then RVM is installed correctly – otherwise, try and re-follow the steps above and do some troubleshooting to get RVM installed properly.
Now that RVM is installed we need to install a version of Ruby that we're going to want to use. Since we're using RVM we can run a command much like the following in terminal:
In this case I've chosen Ruby 1.9.2 p290 (it's the latest version when I'm writing this) however you might want to install the latest version of Ruby that's available when your reading this. Let's also set this Ruby version to the default for RVM usage:
And that should be it! Let's just test our Ruby installation was definitely successful before we get started by running
ruby -v. If a version number was returned - Hurrah! Otherwise, try following some of the instructions above again. For more information about RVM, installing another version of Ruby, and switching between Ruby versions via RVM - a quick Google search will probably hold some good results.
Setting up Ruby for Windows is a bit different to the setup on OS X and Linux and as talked about earlier is arguably easier. For Windows there is a nice all-in-one installer over at http://rubyinstaller.org/ -- go there and download the latest version. From there, follow the graphical installation process, and Ruby should be successfully installed! It's as simple as that!
All we need to do now is check that Ruby is installed properly - this can be accomplished by opening up command prompt ('cmd') and then typing
ruby -v. If a version number is returned, Ruby has installed correctly!
Also just a heads up for you Windows users, from now when I reference 'terminal', I am referring to your command prompt.