Welcome to the Comprehensive Ruby Programming book! I'm excited to go through all the materials and walk you through this great programming language.
I've been a programmer for more than a decade, and I started Ruby about five years ago. Since then, I absolutely fell in love with Ruby for a wide array of reasons. As you learn the language you'll discover that you spend less time worrying about the syntax and more time coding, which adds to the fun. By the time you're finished with this course I hope you'll love this language as much as I do!
In this chapter, we'll take a high level view of the Ruby programming language, learn how to install it on your system, and get it up and running so you can start building Ruby programs. By the end of this chapter, you will have learnt the following:
- Describe the high level concepts of the Ruby programming language
- Construct the configuration to run Ruby programs
- Define how to work with multiple Ruby versions
Ruby is an open source programming language, which means that it's free to use, and it was developed by a large community of developers.
So what can you do with Ruby? By leveraging the Ruby programming language you can build many different types of applications. If you're interested in building dynamic web applications you will most likely want to learn the Ruby on Rails web framework. Since Rails is built on top of Ruby, it's beneficial to understand how to program in Ruby before you can use Rails properly.
So what sites use Ruby?
- hulu.com: A popular destination to watch TV shows and movies online
- twitch.tv: A video game-viewing site that was acquired by Amazon
- lumosity.com: A popular learning platform
- weheartit.com: A great entertainment site
- bloomberg.com: An application that processes news and financial data to give financial insights to users
- github.com: One of the most well-known Git repositories, GitHub enables developers from all over the world to host their code and collaborate with others
Now that you know the kind of applications that we can build with Ruby, let's get started!
Before we can start programming, you'll need to get Ruby installed on your system. I'm going to walk you through how you can install it on your computer regardless of your operating system, and I'll also give you alternate options if you don't want to install Ruby locally (however I highly recommend installing it).
Let's start by going to http://ruby-lang.org:
When you click on the Download Ruby button, it will take you to the following page:
This page gives you information on how to install Ruby on your system.
If you are using the Windows operating system, follow these steps:
- Go to rubyinstaller.org:
- From this list, you can pick the stable version you want, I recommend that you go with the latest stable version. When you click on any of these links, the installer will run and you will be ready to go.
If you're using macOS, Ruby is already installed on your system. To check this follow these steps:
- I created a file called do_I_have_ruby.rb, which has only one line of code in it:
puts "Yes, you have Ruby!"
- Next, go to your Terminal (make sure that you're in the same directory as your Ruby file) and run the file with the following command:
This should display your string, if Ruby is properly installed:
One thing that you can do if you are using the Mac or Linux operating systems is to use the Ruby Version Manager (RVM). This gives you the flexibility to use different Ruby versions for different projects.
To install RVM, go to http://rvm.io, and here you will find the Terminal commands that you can simply copy and paste in your Terminal:
Once you've installed RVM, type rvm list and this should list out all the Ruby versions on your system. If you want to change versions you can call the use command. For example, type in your Terminal to switch to Ruby version 2.4.0:
If you don't want to install Ruby on your local system, but still want to learn how to build Ruby programs, you can go to http://repl.it/languages. This should give you the list of languages available in the repl.it dashboard. When you click on Ruby, it will take you to a Terminal that will render all your Ruby code.
I tend to use this site if I have to quickly debug an algorithm or a confusing script. It's a great tool because you're able to get a side-by-side perspective on your code with its output:
So that's how you install Ruby! Now with that installed, you're ready to start learning how to build Ruby programs!
If you're interested in using RVM to manage multiple versions of Ruby on your system, I want to give some more detailed instructions on how you can accomplish this:
- Start out by going to your Terminal and typing the following command:
If you have RVM installed, this will bring up all of the versions of Ruby that you have access to on your computer.
- If there is a version of Ruby that you want and that you don't already have on your system, simply type this in to the Terminal:
rvm install 2.3.0
Running this command will install the 2.3.0 version of Ruby for you:
You can do this for any versions of Ruby that are available via RVM. This makes it easy to ensure you're always using the most up-to-date version of the language. Using RVM is also helpful if you have different projects that utilize various versions of the language. For example, I have some legacy Ruby projects that use Ruby version 1.9.3, while all of my new projects use Ruby 2.3.0 (at the time of writing this guide).
By leveraging RVM, I can quickly switch between different versions of Ruby with a simple Terminal command. Alternatively, if you're not a fan of RVM, you can also use rbenv, which is a similar service.
In this chapter, we discussed what Ruby is and the popular applications that utilize the Ruby programming language. We also looked at the step-by-step approach of installing Ruby on your computer. With Ruby installed, we also acquired the tools needed to run Ruby programs and go through this book. We later extended our system's functionality and walked through how to install multiple versions of Ruby on our computers, which can be a helpful tool when working with multiple applications that require varying versions of the language.
In the next chapter, we will dive into how to work with variables in Ruby, which will give us the ability to store data and work with it in Ruby programs.