
The Learning Lab is working on a new project, Byrd, which will allow students to give real-time feedback to their instructors during a lectures. Byrd will be the first project that our group will develop using Ruby on Rails. As the only member of my group who does not use a Mac, I had a bit of a challenge trying to install things properly and get a working Rails development environment.
What follows is a recount of what I had to do to get things working.
First I installed VMware Player, a free product from VMware, onto my Windows laptop. Then I downloaded an .iso for the installation of Ubuntu 10.04 LTS. In VMware Player I created a new virtual machine using this Ubuntu iso file. When the machine was created, I started it up and I let Ubuntu run its initial software update.
Now the challenging part… getting a Rails project to work!
First, on my Ubuntu machine, I opened a terminal window and ran the following command to install some necessary libraries.
sudo apt-get install curl git-core build-essential zlib1g-dev libssl-dev libreadline5-dev
I chose to use RVM(Ruby Version Manager) rather than installing Ruby directly on my machine.
Detailed RVM installation instructions can be found on the RVM website.
I’ve included only a brief summary of these instructions.
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
Now I close this shell and open a new shell.
$ rvm list known #should list all kinds of ruby versions to choose from
$ rvm pkg install zlib
$ rvm pkg install readline
$ rvm pkg install openssl
$ rvm install 1.9.2 --with-openssl-dir=$HOME/.rvm/usr
$ rvm --default use 1.9.2
$ gem install rails
Hooray, Ruby on Rails is installed using RVM!
Now you need a few more things in order to get rails project working, such as a database engine and a Java runtime environment.
Rails uses SQLite by default so you much install this to your machine
sudo apt-get install sqlite3 libsqlite3-dev
gem install sqlite3
Now make your first rails app:
rails new <your app name>
cd <your app name>
open up the file Gemfile and add these two lines
gem 'execjs'
gem 'therubyracer'
then in the terminal
bundle install
Now try out the following to make sure that they work:
rails server
rails generate model Dummy id:integer name:string
rake db:migrate
rails destroy model Dummy
Hopefully everything is good so far. For the Learning Lab’s Byrd project we will use the MySQL database instead of SQLite. Here is how to do that:
I open up my config/database.yml file and deleted/commented everything in it. Then I added the following.
development:
adapter: mysql2
encoding: utf8
database: testapp
pool: 5
username: root
password:
socket:
Next I install MySQL on Ubuntu
sudo apt-get install libmysqlclient-dev mysql-server
I left my root without a password, if I added one I would need to add that password in my config/database.yml.
Next I open up my Gemfile and add the line
gem 'mysql2'
Now finally I should be able to run the following commands
rake db:create
rake db:migrate
And voila! I have a working Rails project on my Ubuntu virtual machine that uses a MySQL database.
An afterthough – I installed the programs Meld and SQL Query Browser. I find both very helpful for my Rails development.
Good luck!
Some of my specs:
VMware Player 3.1.4
Ubuntu 10.04 LTS
Ruby 1.9.2 p290
Rails 3.1.0
MySQL
Thanks to the following sites:
http://beginrescueend.com/rvm/install/
http://www.web2linux.com/05/installing-rails-3-on-ubuntu-10-04-lucid-lynx/