Installing Ruby on Rails
From InstallationWiki
| Official Page |
| Project Documentation |
| Download |
|
Contents |
[edit] Getting Started with Ruby and RoR
'Which is the best framework for web application development?' This question is asked in different ways and forms. The answer, however, always remains the same 'The one that enhances productivity'. The next obvious query would be 'In that case which is the framework that enhances productivity?' After some debates and deliberations, we can conclude, 'A framework that reduces Boilerplate code and also reduces the learning curve is the one that increases productivity.'
If you look around, there are an abundance of frameworks that cater to web application development. But most of them fail in one of the two points that govern productivity. Either the framework reduces the Boilerplate code or it is easier to learn. Achieving a balance between the two is seen as a tough task. It is here that Ruby and Ruby on Rails (or RoR as it is fondly called), score above most of their contemporaries.
[edit] Installing and Configuring Ruby and RoR
RoR can be installed in two ways:
- Manual installation after installing Ruby
- One-click installer that installs Ruby and RoR, which includes Apache web-server and MySQL database server
If you already have Apache and MySQL installed, then manual installation is the better way as it installs only RoR.
[edit] Manual Installation
There are three main steps for manually installing RoR, which are:
- Downloading and installing Ruby
- Updating gem
- Installing RoR using gem
In this case, the RoR installation is done over the internet. So from the second step itself, ensure that the internet is connected throughout the installation.
[edit] Downloading and Installing Ruby
First, grab the Ruby installer for windows at http://rubyinstaller.rubyforge.org/wiki/wiki.pl.
The previous figure shows the main page for the one-click Ruby installer (do not confuse it with one-click RoR installer). It provides a list of links that provide details about the one-click installer. Here are the steps for downloading and installing Ruby:
- From the list, select [Download] link.
- On clicking the [Download] link, you will be taken to the page listing the downloadable release version of the installers.
- From the given list, select the .exe link for the latest release and save the file in your preferred location. In our case the version to be downloaded is ruby186-25.exe.
- Double click on the file to be installed to start the installation process.
- The first screen that will be presented to you should be the License Agreement. Read the license carefully and click on I Agree. The next screen will present you with the components to be installed.
- Keep the default choices and click Next. Of these SciTE is a programmer's editor and RubyGems is Ruby's package manager and updater.
- Next, choose where Ruby should be installed. It's always advisable to install in the root of any drive instead of a sub-folder. Ruby commands may not work correctly if the sub-folder is deeply nested. For example, if you want to install it in drive C:, then give c:\ruby as the value for Destination Folder. Also keep in mind not to specify any folder name with spaces in it, as it may create problems while installing RoR.
- Next, provide the name for the Start Menu entry for Ruby installation. Keep the default name and click Install.
- Click on the Next > button to complete the installation process.
- The last screen presented by the installer should give you an option to view the Readme file. If you wish to read it, check the Show Readme checkbox and then click on Finish to complete the installation.
If the installation completes without any problem, then you will see the following screen:
That completes the Ruby installation. The next step is to update the installation using gem.
[edit] Updating Gem
Gem is the name of the utility supplied with Ruby in order to manage, install, and update the Ruby installation in an easy way. The second step in the manual installation of RoR is updating the Ruby installation so that if a new package or an update for any of the package is available, then the complete installation can be made up-to-date.
Before we begin, if you are behind a proxy, open the command prompt and give the following command:
>Set HTTP_PROXY=http://<proxy_address>:<proxy_port>
For example, if the address of the proxy server is 192.168.1.1 and the port number is 9090, then you would have to give the following at the command prompt:
>set HTTP_PROXY=http://192.168.1.1:9090
Next, give the following command at the prompt:
>gem update
You will get the following reply after the last step:
Select the compatible version for your platform. Here I choose option 2 which is the latest for Windows. The difference between and <mswin32> is that the former is a pure Ruby-based package and the latter is the packages natively compiled for Windows. If there is more than one package to be updated, then more 'choice menus' will be presented to you. The point to remember is to choose the number corresponding to the latest version of the package natively compiled for Windows.
That completes the update gem step. Next, let us install RoR.
[edit] Installing RoR
This is the last and the easiest part of the installation process. Just one command and RoR shall be installed. At the prompt, issue the following command:
>gem install rails --include-dependencies
The command should give the messages as shown in the previous figure. Congrats!
RoR is now installed on your system.
For those working on GNU/Linux, only the first step would differ. To install Ruby, grab the latest tar file from http://www.ruby-lang.org/ en/. Then give the following command at the prompt:
tar zxvf <ruby_tar_file>
Then go into the directory created by the tar command. Inside the directory issue following commands:
./configure; make; make install
That's it. Ruby is ready to be explored.
[edit] One-Click RoR Installation
The one-click installer is, in fact, a zip package containing everything that you need. All you need to do is download it and unzip it to a directory of your choice. Even though, it is in a single package, the installation needs to be configured. Therefore, in essence, there are two steps:
[edit] Download and Unzip the Instant Rails
First, go to the following address: http://instantrails.rubyforge.org/wiki/wiki.pl.
- From the links listed on the page click on the [Download] link.
- On the next page, select the package corresponding to the latest release from the list.
- Once the download has completed, unzip the package into the directory of your choice. I use the InstantRails directory.
[edit] Configure Instant Rails Installation
- The first step is to configure the environment of the installation. To do so, click on the InstantRails.exe file within the directory of Instant Rails. You will be presented with the following dialog box:
- When the dialog box just shown appears, click OK. It will configure the environment variables for the Instant Rails directory.
- Once configuration is done, you will be presented with the main application window. What the configuration does is that it updates the configuration files for the Apache web-server and the MySQL database server. It also starts these servers.
- Next, we have to tell Windows about how to find and launch our application. To achieve this we have to change the Window's Hosts File. Click on the button labelled I and choose Configure | Window's Hosts file.
- The host file will be opened in NOTEPAD. The file should contain the following line:
127.0.0.1 localhost
If it is not there, it has to be added manually. Save the changes and exit Notepad.
- Now, we have to set the path to the Ruby directory of the Instant Rails installation. To do so, open the use_ruby.cmd file within the Instant Rails installation directory. Then, add the <Instant_Rails_directory>\ruby\lib; line to the PATH entry in the file, where <Instant_Rails_directory> is the path of the directory where Instant Rails have been installed. Now, Save the file to %WINDIR%\system32 folder. In the case of Windows 2000, %WINDIR% refers to WINNT folder, and in the case of Windows XP, it is the Windows folder. By doing this, giving the command use_ruby enables you to use Instant Rails without changing anything in the installation directory. After the addition, the content of the file will be as follows:
- On giving the use_ruby command, if you get a screen similar to the following, the configuration has been successful. That completes the one-click RoR installation.
[edit] Additional References
- For instructions on Settng Up The Templates for Ruby on Rails, click here
- For instructions on Troubleshooting Rails Deployment, click here
[edit] Source
The source of this content is Chapter 1: Getting Started with Ruby and RoR of Building Dynamic Web 2.0 Websites with Ruby on Rails by A P Rajshekhar (Packt Publishing, 2008).
