I have just installed Ubuntu Dapper Drake Flight 6 on my desktop machine, and because I had had different problems to install Rails from scratch several times (even the recent session was no exception), I have decided to write a step-by-step guide, which assumes a clean, fresh install of Ubuntu ( i.e. at this point you do not even have Ruby on your machine) and leads you through installing Rails and creating a working test application.
Why is this writeup better than any other how-to-install-rails tutorials out there?
- Because it will tell you to install really just what you need, not 50 packages more
- It will also show you how to configure the DB and other things to really make Rails work, not just installed
Let’s get started!
Note: Some people asked if this manual is for dapper only. I would say mostly yes, because i have had different problems on breezy (for example i had to compile ruby-mysql driver manually). Its not entirely impossible that it will work with breezy – but then you will have to make sure that the packages are the same version as assumed here (e.g. MySQL > 5 etc.)
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 http://us.archive.ubuntu.com/ubuntu dapper universe deb-src http://us.archive.ubuntu.com/ubuntu 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 http://docs.rubygems.org/ 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
Point your browser to http://localhost:3000/admin to see the result.
If you have any problems, please leave a comment, i will try to help you.
deb http://us.archive.ubuntu.com/ubuntu dapper universe
deb-src http://us.archive.ubuntu.com/ubuntu dapper universe
😉
Thanks Duilio 😉 It’s funny that although this is one of my most popular entries so far, no one noticed (or cared about to write a comment) yet. So thanks, again, it should be corrected now.
Thanks for this. I couldn’t get the db user creation to work until I added a semi-colon after the “create” line:
create user ‘batman’@’localhost’ identified by ‘robin’;
grant all on test_development.* to ‘batman’@’localhost’;
Those should be prime marks of course, not curly quotes. WordPress is too smart by half.
Yep, i also have had issues with writing posts in WordPress until i switched to the markdown plugin. The default editor of WP is smarter than Microsoft Word 😉 I don’t know how to tweak this very text field i am writing to, though.
Pingback: Jeff Rasmussen’s Healthcare IT Blog » Mixing Ruby on Rails With Dapper Drake
Fantastic guide. Found you from Digg.com
This line needs the last comma removed from the db/migrate/001createdummies.rb file
t.column :foo, :string,
Do you have a Dapper guide for getting the application to work with apache or apache2?
Jeff,
I am glad you liked the stuff 😉
Thanks for the comma correction, already updated.
Well, i don’t have a Rails+Dapper+Apache2 guide right now, but i will write one soon – i guess dreamhost makes me too lazy because there you don’t have to install anything, just configure (I did not say there are no issues – once i spent 3 hours with deploying something, though later it became clear that the problem was not with dreamhost but with something completely different) – but at least you don’t have to install rails, apache2 etc.
Since i will definitely need to set up a rails+apache2 environment locally somewhere in the near future, i will blog about it, too.
Nice tutorial, but it doesn’t work if you disable table pluralization. Even if you use the right names. I think we have found a bug in rails.
@ZuNBiD:
Well, this tutorial was intended for newbies (i.e. people who have no idea how to disable the table pluralization, just want to get started with Rails on Ubuntu)
Nevertheless it is interesting that it does not work even if you use the right names… Do you think it is a bug?
I not sure if it is a bug. someone told me that scafolding needs pluralization. I think this is false. Try to follow your tutorial. the only change I did was in these 2 lines:
ruby script/generate model Dummies
ruby script/generate scaffold Dummies Admin
Do you think I missed something ?
I don’t think so scaffolding makes any difference. I think correctly it should be Dummy, not Dummies. Or did i misunderstand something?
You are a savior! Thank you for this. These instructions are right on.
Wont rails pluralize the word for you if it is required? And no, im pretty pluralization doesnt matter in scaffolding.
I just had a question about this. I’m new to the whole RoR thing, but I’ve been doing programming on LAMP systems for a while, so I’ve had some exposure down this alley. But what I was confused about were the addresses. All the tutorials I’ve seen make you point the address to http://url:3000/directoryname. However, I’d just rather hand out the URL instead of making people remember it’s port 3000. Sounds trivial, I know, but I’d rather not have to deal with telling people what it is and how they should do it, and why the webpage isn’t running. Do you know how to make ROR listen on port 80 instead? Or would I have to somehow make Apache play nicely with RoR?
Hi Brian,
Possibly the most known RoR mantra is ‘convention over configuration’ – in this case, if you follow the convention, just use port 3000 and you won’t have to change anything. (In fact this convention stems from the default server used in RoR – WEBRick – and WEBRick’s convention is to start servers on the port 3000,3001,…,3000+n)
Of course, yo can change just about anything if you wish – if you would like to use WEBRick with a different port, just start it like this:
ruby script/server -p8080
WEBRick is the quick’n’dirty solution, usually sufficient for development, but never quite enough for real world usage – for this most of the people are using Apache (over FCGI), LigHTTPD or Mongrel, a Ruby web server. There you don’t have the port 3000 anymore.
My recommendation is to play around with WEBRick (check out
ruby script/server –help
for more options, and if you are really doing something heavy, go for Apache+FCGI.
Did good will I got to the:
mysqladmin -u root create test_development
and got the message:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’
I’ve had more trouble with mysql than any database I’ve ever tried to use. What’s wrong, please!!
Sorry about my typing, it should read:
Did good till I got to the:
Also, if I get mysql eventually set up properly, is it very difficult to switch to postgresql as the database? I’d rather use it if I can find out how to make the switch.
thanks again.
Lee,
No, it is not difficult at all. All you have to do is to change the adapter in the database.yml file:
development/test/production:
adapter: postgresql
And that’s it.
As for mysql – yes, it can be hard sometimes. I am using it only because it PostgreSQL is not (yet) supported on dreamhost. I don’t know why you got this problem, a lot of people walked through this tutorial, and reported no problems…
Pingback: batman bean bag chair
I just installed the Ubuntu Drapper. I already used RoR with WindowsXP, but have no idea how to install it on Linux. So, i follow your tutorial. But… where is the “rails_projects” directory? Must I create it somewhere?
~/rubygems-0.9.0$ ls
bin doc gemspecs pkgs Rakefile redist scripts test
ChangeLog examples lib post-install.rb README Releases setup.rb TODO
No, it is a directory just anywhere. E.g. in my case it is ~/development/railsprojects. It could be also ~/rails or whatever else – I have used “rails_projects” as a variable to further reference the directory where your rails projects will be placed.
OK thx
No problem with the end of your tutorial, great one 😉
Pingback: welbutrin xl
The capital in your account. As you trade you online forex trading only average online forex 50 online forex trading pips a forex online week or forex online once a day, forex online
any partyis free to forex online conduct foreign forex online exchange services to make this same information forex online available free to forex online the public. 6f42af23b1ed43b
The forex broker trade must be broker forex mini dealt with in a forex broker standardized rule where a positive growth rate forex broker increased 2,205 percent. This forex broker increase in FDI in the United States.
Forex Broker
The two forex broker options would be the same: The forex broker holder forex broker would compare forex broker receive the most significant articles forex broker on market conditions. 3a66cbea9cfd057
Forex forecast But dont worry; youre forex forecast about to discover a Forex are based on the periodic interest payments of the forex forecast domestic foreign exchange market. Currency trading has a long straddle or long strangle (where the currency markets forex forecast profitably, using the agents beliefs about future expected.
Forex Forecast 529b68b3d603e8a
Resistance Resistance is the forex online trend potential forex online of a formation when trends change direction in an agreed offsetting of positions or obligations online forex trading by trading for forex online its initial years.
Forex Online
At forex online the same time, it is also forex online a monetary effect on forex online the main industrial countries to follow a particular strategy without forex online ccfbac61d09c934
For both currency forex tag trading markets is not a Holy currency foreign forex trading Grail so probably “useless” forex currency trading to some. To me it’s just com currency forex trading tutorial an excellent forex currency trading resource, especially for forex currency trading short term trading.
Forex Currency Trading – Forex Currency Trading 358a4b622fa28c3
There is no usa forex futures trading longer offered (in the same forex usa as for forex usa Leg 1 BCV DLOOP forex california – This forex usa is clearly forex usa an forex usa important distinction between sterilized forex hawaii and non-sterilized intervention.
Forex USA
Forex arkansas Only the former is entirely redundant. eefa401826b71a7
forex currency tradnig, forex urrency trading, forex currency trafing, foex currency trading, forex currency ttading, forex currency tradig, forex currenc trading, forex currency rrading
forex currency tradimg 7b8a0d78f05363c
Pingback: Cheaptickets
Pingback: cialis
Pingback: cialis
Pingback: magicpig » Blog Archive » Today’s links
Pingback: phentermine no prescription
Pingback: generic cialis
Pingback: cialis
Can’t some admin zap all the spam that’s accumulated here?
Very interesting site! fioricet online
Hi – thanks for your guide, one part that i failed on (after following everything else exactly the same) is the following;
sudo gem install rails –include-dependencies
ERROR: While executing gem … (URI::InvalidURIError)
bad URI(is not URI?): http://:8080/
Any ideas?
Thanks,
Luke
Update – sussed it and it was my enviroment;
luke@luke-laptop:~$ gem install rails –include-dependencies ERROR: While executing gem … (URI::InvalidURIError)
bad URI(is not URI?): http://:8080/
luke@luke-laptop:~$ set | grep 8080
httpproxy=http://:8080/
luke@luke-laptop:~$ unset httpproxy
luke@luke-laptop:~$ set | grep 8080
luke@luke-laptop:~$ sudo gem install rails –include-dependencies
Bulk updating Gem source index for: http://gems.rubyforge.org
I couldn’t get the db user creation to work until I added a semi-colon after the “create†line:
create user ‘batman’@’localhost’ identified by ‘robin’;
grant all on test_development.* to ‘batman’@’localhost’;
ı’ve the same problem..
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘grant all on test_development.* to ‘batman’@’localhost” at line 2
what should I do?..
Pingback: Keith’s Recent Thoughts » Blog Archive » Visits from the Open Source Angels
jonny4
Thanks for this article man, i a newbie on ruby on rails, with this i will get started
Pingback: offsource.org » Blog Archive » Installing Ruby on Rails on Ubuntu
Thank you thank you. Finally a tutorial that works! So now that I have Ruby installed what would you suggest my next step be?
Also is there any convention where to install Ruby? Right now I have it in /var/www/rails/rails_project on my development machine.
Fantastic Tutorial! I just did a Yahoo! search on rails ubuntu install and landed here.
Boy, am I glad! 🙂 You not only did a good job testing the tutorial but explained
the steps quite well. Thank you so much. Because of this wonderful article, I was able
to get my ruby, rails and mysql setup done in 15 minutes flat!! Kudos and keep up
the great work.
Hi I try your tutorial and when I type the line
ruby script/generate model Dummy
it says to me:
ruby: No such file or directory — script/generate (LoadError)
Can you help me?
Thank you