Walk through the necessary steps to install Sinatra.
- [Instructor] In this movie, we're going to learn how we install Sinatra so that we can use it. In order to use Sinatra, we're going to need three pieces of software installed: Ruby, RubyGems, and Sinatra. Sinatra depends on having Ruby and RubyGems. You can find out how to download Ruby or RubyGems by going to their websites, or we also have courses in the lynda.com training library to teach you how to do it. You can go to the Installing and Running Ruby on Rails 5:Mac or Installing and Running Ruby on Rails 5: Windows courses, and then just follows all the movies up through RubyGems, and that's because the requirements for Ruby on Rails and Sinatra are the same.
They both depend on having Ruby and RubyGems, so the beginning steps of that process are exactly the same. It's also worthwhile to review the movie on text editor choices while you're there. We're going to be using the Atom text editor in this course, but I go through some of the other options that you could choose there as well. So here I am on those other courses, Installing and Running Ruby on Rails 5: Mac. You can see in chapter one I walk you through the process step by step til we get Ruby and RubyGems, and then you can stop. You don't need to install Ruby on Rails or MySQL or the web server.
And down here's that movie I was talking about that talks about text editor choices that you could use. And then in the Installing and Running on Rails 5: Windows course, you have the same thing. I walk through the steps to get it installed on Windows, and you can stop once you get to RubyGems. There's no need to install Ruby on Rails, MySQL, or anything after that. If you scan down here, you'll see I also have a movie about text editors that are there as well. Once you have Ruby and RubyGems installed, then you'll be ready install Sinatra. Now, the reason why you need those is because Sinatra, again, is written in Ruby, and Sinatra is a RubyGem, so the way we install it is by telling RubyGems to do it.
We do that with the Gem command gem space install space sinatra. It's really that easy. Just tell RubyGems to install Sinatra, and it'll do the rest. Now, before we go and actually try that, we should also talk about installing Thin. Thin is a lightweight, fast web server, and it's a perfect companion to our lightweight, fast framework. It's recommended by the Sinatra website, and Sinatra's got code in it that will pick up on the fact that Thin is installed and automatically use it if it's there, so it's a good idea to have it.
It's going to make things faster, and it's super easy to install because it's also a RubyGem. gem install thin will give us everything we need. So we're just going to install Sinatra and Thin using RubyGems. The way that we're going to interact with RubyGems is from our command line. On Windows, that's going to be the Command Prompt application. On Mac, that's going to be the Terminal application, which is where I am now, and I'm going to start out just typing ruby space -v, and that'll tell me what version of Ruby I have. You don't have to have exactly the same version as me.
If you have something later, that's always okay. I would recommend that you try to have something that's at least Ruby 2 or later. 2.3 is the latest at the time I'm recording this, and it's a good, stable release. It's a worthwhile one to have if you don't. Now, once I have that, let's check on RubyGems. I'll type gem space list, and it will list out all of my currently installed RubyGems. I just have a basic set here. These are the ones that come with RubyGems. I need to still install Sinatra. So the way I can do that is with gem install sinatra.
Now, before I hit return, I'm going to also add a couple of extra options here. They're not required, you can leave them out, but I think they're helpful. Space --no-ri and space --no-rdoc. ri and rdoc are types of documentation. This is documentation that gets installed on your computer, and you're never going to look at. It just wastes time installing it and takes up hard drive space, so whenever possible, I like to remove those ri and rdoc documents. They're really not necessary.
It will make the install process go much faster too. Once I hit return, then you can see it goes out to the RubyGems server, it gets Sinatra, downloads it, and installs it for me. Now let's do the same thing. gem install thin. Let's also tell it that we don't need any of its documentation installed on our computer. Goes out, says it's building native extensions. This could take a while. You see that it's bringing back eventmachine gem. It needs the eventmachine gem in order to run Thin. Now, if you have any problems with this and for any reason the eventmachine gem doesn't install or Thin doesn't install, remember that this is optional.
You don't have to have it in order to work with Sinatra. You're just giving Sinatra a speed boost. Okay, so now we've got everything installed. Let's type gem list, and let's just make sure that it's there, and you can see that we have both Sinatra and Thin installed. Now, if you have later versions of either one of those, again, don't worry about it. Those later versions are going to have the same core features. They're just going to have bug fixes, security fixes, and things like that added into them. The basic of working with Sinatra is still going to be the same. Okay, now that we have everything we need to work with Sinatra installed, in the next chapter, we'll talk about how we can start using it.
- Installing Sinatra
- Launching the server
- Defining routes
- Using route patterns and parameters
- Redirecting requests
- Rendering dynamic templates
- Using partial templates and layouts
- Defining custom helpers