Installing Ruby on Rails on your own computer

Note that you are not required to do this to be able to solve the homeworks. You might find it more convenient to do so, but there is no claim that the installation will always work. We will try to help you when we can. In this set up, you install the following software on your computer:

  • Ruby
  • Rubygems
  • Rails
  • Postgres adapter

and then connect from your application to the database server at

csc4380.cs.rpi.edu

RUBY

All of the following are commands to by typed in a computer terminal -see above for discussions on terminal applications.

To get started, you will need to install Ruby on your computer. The version I have (1.8.7) is the latest version. It is not technically necessary to get the latest version of Ruby, but it would not be a bad idea to install the latest version. To check which version of Ruby is installed, type

ruby --version

If you would like to uninstall the current version and install the next version, just search on the Web for your operating system. To install Ruby, point your browsers to:

http://www.ruby-lang.org/en/downloads/

For Mac OS.X, I use MacPorts which makes life a lot easier.

Now, take a break and watch a video Ruby before you continue with the next steps.

RUBYGEMS

Next, you will need to install Rubygems. Rubygems will make it possible to install all the remaining software with simple terminal commands. You must have Ruby installed and running for this part. For installation instructions, go to:

http://www.rubyonrails.org/down

If you have trouble installing rubygems on a Unix based system (such as a Mac), type sudo before the installation command:

sudo ruby setup.rb

RAILS, MONGREL

Once, you have Rubygems, you will be able to install all the remaining software pretty quickly.

To install rails, simply type: gem install rails

Remember that we would like to install the latest version of rails so that we can test everybody. If you have another rails version already installed, you can uninstall it. To check with version you have, type:

rails --version

To uninstall a previous version, such as 2.0.2 for example, you can type:

gem uninstall --version=2.0.2 rails

If you do not want uninstall your current version, install version 2.3.3 and then you will have both versions installed. You will then have to figure out how to run version 2.3.3. You only need to run rail once when you create an application. The remaining operations will then call the correct version of rails (or so I think).

If you are installing or uninstalling software in Mac OS.X or in any Unix machine, you will need to precede the command with "sudo" which will enable you to write/erase files in protected directories. You also will need to provide the administrator password for the machine when prompted. For example, you will need to type:

sudo gem install rails

This is true for all the remaining commands below. If you want to know more about sudo, you can read it here:

Sudo Information

If you are installing things in Windows, just forget about it!.

POSTGRESQL ADAPTER

Finally, to install the postgresql adapter, type:

gem install --include-dependencies postgres-pr

or if you are using a Unix machine, use:

sudo gem install --include-dependencies postgres-pr

And voila, you are done. Now, we are ready to test drive the application.

If you are having problems with the postgresql adapter, try one of the alternatives. Other adapters for postgresql are: pg, postgres, ruby-pg and ruby-postgres. If you cannot find a solution there, try Googling the exact problem you encountered. Most often, you will find that someone has answered your question already. In doing so, write down your operating system in the query to refine the search. Report to me what worked and I'll include it here.

I have received many comments that the following works for a lot of Windows machines:

gem install pg

INSTRUCTION FOR UBUNTU 9.10, from fellow student

These instructions are not tested by me, use them at your risk. Thanks a lot to Eric Pulvino for this contribution to the class.

How to ready an Ubuntu 9.10 system for Database Systems:


############# Getting the Necessary Software ###############

sudo aptitude -y install postgresql-server postgresql-client libpq-dev rails build-essential ruby libopenssl-ruby ruby1.8-dev
sudo gem install pg

#################################################



############# Setting up Postgres ##########################
Creating A Postgres User:

to create a user called "postgres" enter:
sudo -u postgres psql postgres

setting the password for the new user (from the "postgres=#" prompt):
\password postgres

  then enter your new password two times when prompted
  
enter "\q" to leave postgres.
  
Creating a database

To create the first database, which we will call "database_name", simply type :

 sudo -u postgres createdb database_name
  
################################################



############ Testing the Configuration #####################

To test that your connection to the database is working, create a new project

rails test1

Edit the test1/config/database.yml file as follows: 

development:
  adapter: postgresql
  database: <database_name>
  username: <postgres_username>
  password: <postgres_user_password>
  host: csc4380.cs.rpi.edu

Where each one of the fields encased in "<...>" matches the options configured in the previous commands.



Change directory to test1. Now, create a new model:

ruby script/generate model order

and edit the file named "db/migrate/001_create_orders.rb. You will see the following line:

# t.column :name, :string

this line is commented out. You can uncomment it by removing the first character, leaving:

t.column :name, :string

Now, save this file and try the following command:

rake db:migrate

If your system is setup correctly, you will get a success message.

################################################

information taken from multiple sources including:
https://help.ubuntu.com/community/RubyOnRails
https://twiki.cs.rpi.edu/twiki/bin/view/CourseDatabase/Csc4380Configuration
https://help.ubuntu.com/community/PostgreSQL

 

-- SibelAdali - 31 Jan 2010

Topic revision: r2 - 2010-02-21 - 03:26:32 - SibelAdali
 
Copyright © 1824-2009 Rensselaer Polytechnic Institute (RPI)
110 Eighth Street, Troy, NY USA 12180 (518) 276-8326