Step 1. Install
Learn to install and setup everything you need to work with a language!

Dapper Drake


For the purposes of this book I've decided to show you how to get Ruby on Rails working on the Ubuntu Dapper Drake distribution of Linux. Your experiences may be similar on other linux distributions, but I know this process to work on Ubuntu. Ubuntu comes with the apt package manager, which is akin to the port installer for Mac OS X, it handles dependencies of the packages you ask to be installed, and uses an online repository to get the binary files from. For Ubuntu, we need to get Ruby, and the Ruby Header files. The Header files are used to build Ruby Gems which need to be manually downloaded and compiled against these header files. Let's get started:

Installing Ruby

Step 1, we need to get the latest stable Ruby release that Ubuntu has, including the header files, and we need to get the RDoc release too. RDoc is the application that takes commented source code and creates web pages out of it, for your viewing pleasure. The online Ruby on Rails api documentation is the perfect example of this here.

$ sudo apt-get update
$ sudo apt-get install ruby1.8, ruby1.8-dev, rdoc1.8, libruby1.8

This instructs apt to get the latest list of files that the online repository holds, and then requests Ruby, Ruby Header files, RDoc, and the Ruby library files. If we'd have skipped of the libruby1.8 request we would have been prompted to include it, because apt is an intelligent little application and it know that Ruby depends on this library. All we need to do now is link the filename that Ubuntu has used, with the typical ruby command, so we don't have to type ruby1.8 every time we want to use it.

$ sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby

You can test that this is working by doing the following: irb is the interactive Ruby shell, if this runs we know Ruby is installed correctly.

$ irb
irb(main):001:0>exit

Installing Ruby Gems

Ruby on Rails, and many of the additional extras you'll use in the future, are mostly controlled by the Ruby Gems package manager. On Ubuntu we need to download this manually and compile it against the header files that we installed in the last step. Using FireFox navigate to the download site and download the latest stable source, and extract the files within the download to a folder, we'll delete this later. Open up a terminal at that folder and we can go ahead and compile Ruby Gems and then install Ruby on Rails.

$ sudo ruby install.rb
$ sudo gem install rails

As with the other installation sections, you're now ready to get going with Rails, however, you won't get far without a database. Let's install MySQL 5 which will set us in good stead.

$ sudo apt-get install libmysql-ruby1.8, mysql-server-5.0

To stop and start MySQL you need only run /etc/init.d/mysql start or /etc/init.d/mysql stop. You can use any text editor of your choice to edit the Rails files, and use WEBrick to run the server.

Comments

No comments yet

Log in to add a comment