Installing Ruby On Rails - Step By Step Guide
Greetings forks!!!
Welcome to Installing Ruby on Rails 5 on Windows. In this blog, we will learn to install Ruby on Rails, the popular open source web development framework. This blog is designed to get everything set up so that you can either start building projects with Ruby on Rails or continue learning with other Ruby on Rails pages, such as Ruby on Rails Essentials. In this blog, we will learn to use the command line to install Ruby on Rails, MySQL and all of the supporting software that's going to be required and to consider the web server and text editor options that we can choose.
Welcome to Installing Ruby on Rails 5 on Windows. In this blog, we will learn to install Ruby on Rails, the popular open source web development framework. This blog is designed to get everything set up so that you can either start building projects with Ruby on Rails or continue learning with other Ruby on Rails pages, such as Ruby on Rails Essentials. In this blog, we will learn to use the command line to install Ruby on Rails, MySQL and all of the supporting software that's going to be required and to consider the web server and text editor options that we can choose.
Let's get started installing Ruby on Rails.
Installing Ruby
Ruby on Rails requires that we use Ruby version 2.2.2, or later. 2.2.2 is the first version which includes all of the features that Ruby on Rails 5 is going to need; however, development has continued and a few more improvements to Ruby have been released. As I'm writing this, the newest version is 2.4.0. You should try to use that version or any version that's newer.
The newer version will not include many changes to Ruby and it won't make much difference for Ruby on Rails either but, what you will get is stability and speed improvements, and those are worth having, so choose the newest version that you can. Windows do not include Ruby so unless you've installed it previously, you're going to need to install it now. In order to install it, we'll first go to the Ruby website. That's www.ruby-lang.org and that's going to be the best place to find out the current information about Ruby, what the latest version is, and get instructions on how to download it.
Right now, if you go there, you'll see that the recommended way to install it is going to be to use the Ruby installer and that's maintained at rubyinstaller.org. So that's where we're going to end up going. But we always want to go to the Ruby-Lang website first, just to make sure that there's not some new information that's come out in the meantime, so let's go there now. So go to the ruby-lang.org website and you should go there to the downloads link, so we click on Downloads. That'll give you information about downloading Ruby and about installing Ruby.
There are ways of installing Ruby. And you can see there, on Windows machines, you can use RubyInstaller, so that is still the recommended way. There's also a link there for installation, to the installation page. Click that as well. And if you scroll down a bit, it gives you different options for how you can install on different systems and then you see there RubyInstaller (Windows) and so that's a link that's going to take us to the information about the RubyInstaller. Just jump straight over to RubyInstaller for Windows, rubyinstaller.org. You can see there that there is a link for download.
This is going to allow you to download the version you want and you can see that there's a number of different versions that you can choose from there. So you might have Ruby 2.3.3, 2.3.3 (x64), 2.2.6, and so on. Now we know that we definitely need 2.2.6 or later. Really, it's 2.2.2 or later, but, we don't want to use any of these, 2.1 won't work for us, 2.0 won't work; we need to have one of these top four versions that are listed here. We're going to go with the most recent version, 2.3.3.
That's going to give us the most current version of Ruby. So, which one of these should we download? The one that says x64 or the one that doesn't? Well, it depends on what kind of computer you have. If you have a computer that has a 64-bit processor, which most of them do, you're going to want to download the x64 version. If you have one that has a 32-bit processor, then you're going to want to download the other one. It's just a matter of speed and how it's compiled. You can go into your system information to find out more information, to see if you can tell which version you have, the 64 bit or the 32 bit.
Most times, on most updated, modern computers, you're going to be working with a 64-bit. So, when we click on it, it is going to download for us and it's going to offer us the chance to save this .exe file. So you want to say yes, now save that file, that'll save it into your downloads directory.
Alright, so now rubyinstaller-2.3.1.exe and just double click that. That'll launch it. And this will run the installer. It's going to install Ruby. That's why it's called RubyInstaller, right? So it'll just take a minute while it pops up. So to start out with, it's going to ask some questions and, in general, you want to use the default settings for all of these. So it asks what language you want to use; Click OK. Next, it comes up with a License Agreement. You can read through that license and then if you want to, you can accept the license.
So click license agreement toggle button and click Next. Then it comes up and asks where you want to install Ruby and the best practice is to install it where it wants to. You can give it a different name if you want if you know better, but the best thing is to let it choose which one. There should a couple of checkboxes and you should choose a couple of them. Choose one that says Add Ruby executables to your PATH and the one below it that says Associate .rb and .rbw files with this Ruby installation. Those are going to be nice conveniences that we're going to appreciate later on so set both of those, and then, once set, choose Install.
Now, you can just sit back and wait while it does the installation process. It might be a good time for you to go get a cup of coffee. 😉 Once the installer's complete, you can click Finish and you'll now have Ruby 2.3.3 installed. Close up that window and go and close up browser as well and then, go into our command prompt, and try things out there. Now, one good way to find out if you have Ruby installed is from the Command Prompt to simply type ruby -v, for version.
Now notice it comes up and it says that Ruby is not recognised, it's not a command that it recognises. So what's going on here? The thing is that we told Windows that it should include the path to Ruby in the setup but we haven't restarted our system. If you restart or you logout and come back in, those changes will take effect.
So again, once you restart, that new path variable should take effect and it should automatically look in this side this directory in order to figure out what the Ruby command is. So now that you should see that it's installed, Instead of -v make it -e (ruby -e), and then space, and then inside double quotes, put, "puts 1+1", and then double quotes again. Basically, what we're doing is putting a simple Ruby statement and we're telling it that it should execute it, that's what the "e" does, and we get back two as a result.
ruby -e "puts 1+1"
ruby -e "puts 1+1"
So now you know that Ruby is installed and running correctly. Once you have Ruby working, you're ready to install the Ruby DevKit.
Installing DevKit
You learned how to install Ruby. But there's one more component that you need to go with it, and that's called the Ruby DevKit. DevKit is short for Development Kit, and it's essentially a piece of software, a toolkit that developers can use in order to build and use code that's written in C and C++. Essentially these are extensions, primarily used by RubyGems, which we're going to be installing the next. And that code is going to be written in C and C++ so it can be as fast as possible.
So essentially you want Ruby Code to be able to work with code that's written in C and C++. And you need the developer tool kit to do that. So, the best way to find out information about the tool kit is from the GitHub Wiki page about it. It will give you all of the information about downloading it, installing it, and troubleshooting it. The URL is there at the top, github.com/oneclick/rubyinstaller/wiki/Development-Kit. You also can just simply Google for GitHub Ruby DevKit, and you'll find it that way.
Now, these instructions are going to tell that the first thing you should do is go back to that RubyInstaller page where you installed Ruby just a moment ago. And from that page, you'll be able to click Download, just like you did before. And you'll get links that will allow us to download the Ruby DevKit. So on the download page, you had the Ruby installations there, but if you scroll down just a bit more down the page, you'll see Development Kit, right? And there are several different versions you can choose from. There's also a bit of information over here on the right side which says, Which Development Kit? And it says there are several different versions.
You want to make sure you get the right version for the version of Ruby that you picked. So since you picked Ruby 2.3.3 x64, then you want to pick the Ruby 2.0.0 and above x64, the 64bit version, and this is the name of the file that you should look for. If you had picked the non-64bit version, then it would be the one right above that. So just make sure that you find the correct name. Click on that. It'll pop up and ask about downloading it. Save the file.
Again, that's going to go into your downloads folder. Once it downloads the file, You can open that up, You can click on the folder to go straight to your downloads folder. And then inside your downloads folder, you just need to double-click on that installer, the DevKit installer. Open that up. Now it's offering me the chance to extract this to a location inside your user directory. This is one time you do not want to accept the defaults. It's very important that you choose a different location here. And the best advice is to put it in a directory C:\DevKit You can also call it RubyDevKit if you want.
Extract it. And that's going to put all those files in that DevKit directory. Take just a moment while it does it. Once that process is done, all the files will be in that directory that you created. But it won't have actually done anything with them. You have to continue the install process. If you go back over to the instructions on the Developer Kit website, the Wiki, you'll see that there's a quick start there that tells you what you need to do. Extract it, then we cd (change directory) into it, we run this command, and run another command.
So the first thing you have to do is to go to cd \DevKit or whatever directory you have just created.
The backslash tells it that it's at the root of the hard drive, so that's where it goes. And then inside there, you could type dir to see the contents. And then the command that it wanted you to issue, to get things started, is ruby dk.rb init. So type that line and hit return, and now it's going to run that dk.rb script. You can actually see that sitting there in that directory. So it's going to run that dkrb script, and tell it to run the initialization. When it did that, it generated a config.yml file.
Now type dir again. You can see now, there's a new file there. config.yml up there at the top. That's the configuration file that it's going to need for the installation. You can actually take a look at what's in that file by using type config.yml, and you can see the contents. And you can see, most importantly it found this version of Ruby. It located that version for us. It's very important that it knows which version of Ruby there is. Now that it's located it, you're ready to actually install the DevKit.
And you do that with another command, ruby dk.rb that same part at the beginning, but then space install (ruby dk.rb install). So the first one was init, the second one is install. And then it actually installs the DevKit. So now you have both Ruby and the Ruby DevKit installed. And that's going to give you the parts that were needed in order to work with RubyGems. And that's what we're going to see next.
RubyGems
Now that you have Ruby and Ruby DevKit installed, you're ready to learn about RubyGems. RubyGems helps to manage the different Ruby libraries that you'll be needing. RubyGems is the name of the package manager. A single RubyGem or just a gem for short is simply Ruby code which has been packaged up for easy distribution using the RubyGem package manager. Rails makes extensive use of RubyGems, and as you'll see, Rails is itself, in fact, a gem. RubyGems are included in the Ruby installer, so it should've installed RubyGems for us at the same time that it installed Ruby.
Now if for any reason you don't have RubyGems, the main resource for RubyGems is RubyGems.org. You can go to that website, you can download the software, you can install it using the instructions, you can also look up information in their user guides, frequently asked questions, and learn everything you might want to know about RubyGems. You can also search for different RubyGems, that is, different libraries of Ruby code that you might want to add to your projects. For now, since you already have it installed, go to your command line and let's check it out. The way that you interact with RubyGems is with the command GEM, gem, and then space dash V, for version (gem -v).
This will tell you if you have it installed, and if so, what version is installed. You can see that you might have got 2.5.1. That's a good version, but it's not the latest version. You have to update it in just a second. Before you do, though, you can type gem space list (gem list) and it'll list off the currently installed RubyGems. At the moment this might be just a starter set that just comes with RubyGems when you first get it. It's the basic gems that you might want to use. Don't worry about what each of these is, we're going to be installing your own gems a little later on.
For now, you can update RubyGems using gem space update space dash dash system (gem update --system). Hit return, and it's going to go out to the RubyGems server, find out if there's a newer version of RubyGems, and try to install it. This is always a good idea to do from time to time.
The last thing to point out to you is that you can type gem dash dash help (gem --help), and you can get a help menu for RubyGems at any point that will come up and help you with more stuff, and you can actually type gem help commands and find out information about commands, gem help examples, and so on.
So this is a good way for you to get interactive help if you ever get stuck with RubyGems. Okay, now that we have RubyGems installed, it's going to be really easy to install not just Rails, but also other libraries that we can use when developing in Rails.
That's all you have to do to install any RubyGem. You can go to the RubyGems website, find out the name of the RubyGem, and then you just type gem install and the name of the RubyGem. Now add an additional option here, though, which is a Space and then --version Space 5.0.0 (gem install rails --version 5.0.0), that's the version of Ruby on Rails that this blog is going to be for. Now if you just type gem install rails, by default it's going to get the latest version, and I don't know when you're reading this. Version 5.0.4 might be out, or 5.1 might be out, right? But so you can follow along and have consistency with the blog, I'm going to have you install version 5.0.0.
You're free to try something else if you want to try it with a newer version, but if you use this it'll ensure that you can follow along precisely. And then I'm going to add another option here, this is the same thing we added in the last para if you ran into that problem, Adding a -no-rdoc option and then --no-ri. RDOC and RI are basically documentation, it's documentation for Rails, and you're not going to be using this documentation, so it would just clog up your hard drive with unnecessary files, right.
(gem install rails --version 5.0.0 -no-rdoc --no-ri)
So now it's going to go out to the internet, it's going to look up all the code libraries on the RubyGems server which make up Rails, and then it's going to download them. It may take about five minutes if you want to walk away and come back in a bit. Okay, so it's finally done. You'll notice that a couple of times in there it said that it was compiling software, that it was actually creating native extensions, that's when it's using those C libraries that are in that Dev kit, that's why it's so important that we have that Dev kit installed.
Okay, so now check to see if it's there, type gem list, and you'll see that you get a much longer list than you got before, and most importantly you'll see that Rails 5.0.0 is installed. Now there are lots of other parts of Rails if we scroll up, you'll see that it had lots of other things that it put in here, we're going to chat more about some of these up here at the top, activerecord, activesupport, actionview, and so on, those are all parts of Rails, you can see they're also version 5.0.0, and they are support files that go with this main library.
So in addition to installing the Gem for Rails, it also installed a small command line program called Rails that you're going to be using. So Rails is both a library of Ruby code that can power your web applications, but it's also a small program that helps you to interface with that library of Ruby code from the command line. So you can get to that by just typing rails, rails Space -v (rails -v) will come back and tell you what version of Rails we have installed, and sure enough, you have Rails 5.0.0. Now you have Rails and all of the libraries that it needs installed, and you're ready to use it.
That's all about installing Ruby on Rails.!!!
Happy Coding!!
Installing Ruby on Rails
Now that we have RubyGems installed, it's going to make it really simple for us to install Ruby on Rails because Ruby on Rails is itself a RubyGem. Go to the command line and see how. You already have RubyGems installed, you saw that in the last para, so now you just want to install Ruby on Rails, and you can do that with gem Space install and then rails. (gem install rails)That's all you have to do to install any RubyGem. You can go to the RubyGems website, find out the name of the RubyGem, and then you just type gem install and the name of the RubyGem. Now add an additional option here, though, which is a Space and then --version Space 5.0.0 (gem install rails --version 5.0.0), that's the version of Ruby on Rails that this blog is going to be for. Now if you just type gem install rails, by default it's going to get the latest version, and I don't know when you're reading this. Version 5.0.4 might be out, or 5.1 might be out, right? But so you can follow along and have consistency with the blog, I'm going to have you install version 5.0.0.
You're free to try something else if you want to try it with a newer version, but if you use this it'll ensure that you can follow along precisely. And then I'm going to add another option here, this is the same thing we added in the last para if you ran into that problem, Adding a -no-rdoc option and then --no-ri. RDOC and RI are basically documentation, it's documentation for Rails, and you're not going to be using this documentation, so it would just clog up your hard drive with unnecessary files, right.
(gem install rails --version 5.0.0 -no-rdoc --no-ri)
So now it's going to go out to the internet, it's going to look up all the code libraries on the RubyGems server which make up Rails, and then it's going to download them. It may take about five minutes if you want to walk away and come back in a bit. Okay, so it's finally done. You'll notice that a couple of times in there it said that it was compiling software, that it was actually creating native extensions, that's when it's using those C libraries that are in that Dev kit, that's why it's so important that we have that Dev kit installed.
Okay, so now check to see if it's there, type gem list, and you'll see that you get a much longer list than you got before, and most importantly you'll see that Rails 5.0.0 is installed. Now there are lots of other parts of Rails if we scroll up, you'll see that it had lots of other things that it put in here, we're going to chat more about some of these up here at the top, activerecord, activesupport, actionview, and so on, those are all parts of Rails, you can see they're also version 5.0.0, and they are support files that go with this main library.
So in addition to installing the Gem for Rails, it also installed a small command line program called Rails that you're going to be using. So Rails is both a library of Ruby code that can power your web applications, but it's also a small program that helps you to interface with that library of Ruby code from the command line. So you can get to that by just typing rails, rails Space -v (rails -v) will come back and tell you what version of Rails we have installed, and sure enough, you have Rails 5.0.0. Now you have Rails and all of the libraries that it needs installed, and you're ready to use it.
That's all about installing Ruby on Rails.!!!
Happy Coding!!
Comments
Post a Comment