Rails on Ubuntu
I’ve just followed a great walk-though on getting Rails up and running on Ubuntu. I now have Eclipse (with the RadRails plugin), mysql, apache, Ruby and Rails all working really well.
A lot of what I post here doubles as a journal of sorts, insuring I don’t lose any of these juicy nuggets when I need them again, so I’m going to do a big ol’ copy and paste. Hopefully that’s cool with the author…
Part I: Installation
Prepare the system for the installation
- Check /etc/apt/sources.list - make sure you have access to the ‘universe’ packages by uncommenting them:
deb <a href="http://us.archive.ubuntu.com/ubuntu">http://us.archive.ubuntu.com/ubuntu</a> dapper universe deb-src <a href="http://us.archive.ubuntu.com/ubuntu">http://us.archive.ubuntu.com/ubuntu </a>dapper universe
- Refresh apt packages to make sure you get the most up-to-date stuff:
sudo apt-get update
Install Ruby related packages
- Install Ruby essentials: ruby, irb, rdoc, ri
sudo apt-get install ruby rdoc ri
- Install gems: download, unpack, install
go to <a href="http://docs.rubygems.org/">http://docs.rubygems.org/</a> download rubygems-0.8.11.tgz (or the latest version) tar -xzvf rubygems-0.8.11.tgz cd rubygems-0.8.11/ sudo ruby setup.rb
MySQL installation and configuration
- Install MySQL:
sudo apt-get install mysql-server
- Install ruby MySQL bindings
sudo apt-get install libmysql-ruby
Install Rails
sudo gem install rails --include-dependencies
Part II: Configuration
Setup the DB
- Add an user, create a test database and grant acces for the user
mysqladmin -u root create test_development
mysql -u root
Into the db shell, write the following commands:
create user 'batman'@'localhost' identified by 'robin' grant all on test_development.* to 'batman'@'localhost';
Don’t forget to replace the username/password (unless you happen to be Batman of course - in this case i suggest to use a different password since this can be guessed easily by social engineers
Create and test the rails app
- generate the app files
Lets denote your working directory (the root directory where your future rails project s will reside rails_projects).
cd rails_projects rails test
- edit config/database.yml
cd rails_projects/test vim config/database.yml
- It should look like this:
development: adapter: mysql database: test_development username: batman password: robin host: localhost
- generate a dummy model
ruby script/generate model Dummy
- edit the migration file
vim db/migrate/001_create_dummies.rb
class CreateDummies < ActiveRecord::Migration def self.up create_table :dummies do |t| t.column :foo, :string t.column :bar, :string end end def self.down drop_table :dummies end end
- run the migration
rake db:migrate
- generate a simple maintenance app
ruby script/generate scaffold Dummy Admin
- start the server
ruby script/server
Post a Comment