header image

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.

Internet contains huge number of opportunities to earn money online. Simply create a site that you think has the potential to sell hot items using ruby on rails. Register a relevant domain name and purchase a web hosting service through hostgator, one of the better web host out there today. Get a internet connection through one of the wireless internet providers to upload your site. Work on search engine optimization to get a better traffic and also use affiliate marketing program for the same reason. Finally get a free voip phone service to contact customers directly. The pc to phone system is the most effective method of marketing.


If you liked the article, subscribe to the rubyrailways.com feed!  


      

55 Responses to “Getting Ruby on Rails up and running on Ubuntu Dapper”

  1. Duilio Says:

    deb http://us.archive.ubuntu.com/ubuntu dapper universe
    deb-src http://us.archive.ubuntu.com/ubuntu dapper universe

    ;)

  2. peter Says:

    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.

  3. Arthur Says:

    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’;

  4. Arthur Says:

    Those should be prime marks of course, not curly quotes. WordPress is too smart by half.

  5. peter Says:

    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.

  6. Jeff Rasmussen’s Healthcare IT Blog » Mixing Ruby on Rails With Dapper Drake Says:

    [...] Step-by-step instructions for installing rails on Ubuntu Dapper 6.06:  Getting Ruby on Rails up and running on Ubuntu Dapper [...]

  7. Jeff Rasmussen Says:

    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?

  8. peter Says:

    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.

  9. ZuNBiD Says:

    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.

  10. peter Says:

    @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?

  11. ZuNBiD Says:

    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 ?

  12. peter Says:

    I don’t think so scaffolding makes any difference. I think correctly it should be Dummy, not Dummies. Or did i misunderstand something?

  13. Josh Says:

    You are a savior! Thank you for this. These instructions are right on.

  14. seventoes Says:

    Wont rails pluralize the word for you if it is required? And no, im pretty pluralization doesnt matter in scaffolding.

  15. Brian Says:

    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?

  16. peter Says:

    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.

  17. Lee Says:

    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!!

  18. Lee Says:

    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.

  19. peter Says:

    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…

  20. batman bean bag chair Says:

    batman bean bag chair…

    Wow that’s a nice post ….

  21. DliZ Says:

    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

  22. peter Says:

    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.

  23. DliZ Says:

    OK thx
    No problem with the end of your tutorial, great one ;)

  24. welbutrin xl Says:

    welbutrin sr…

    welbutrin sr welbutrin seizures welbutrin weight gain. buy generic welbutrin …

  25. John Smit Jr. Says:

    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

  26. John Smit Jr. Says:

    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

  27. John Smit Jr. Says:

    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

  28. John Smit Jr. Says:

    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

  29. John Smit Jr. Says:

    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

  30. John Smit Jr. Says:

    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

  31. John Smit Jr. Says:

    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

  32. Cheaptickets Says:

    cheaptickets…

    cheaptickets airline cheapticket…

  33. cialis Says:

    cialis…

    buy cialis online 73 no prescription cialis…

  34. cialis Says:

    buy cialis…

    cialis forum cialis drug cheap cialis order cialis …

  35. magicpig » Blog Archive » Today’s links Says:

    [...] Getting Ruby on Rails up and running on Ubuntu Dapper [...]

  36. phentermine no prescription Says:

    phentermine online no prescription…

    phentermine without a prescription. phentermine online no prescription…

  37. generic cialis Says:

    generic cialis…

    generic cialis. cheap generic cialis…

  38. cialis Says:

    cialis…

    buy cialis online. Generic cialis….

  39. Fred Barok Says:

    Can’t some admin zap all the spam that’s accumulated here?

  40. Petrarka Says:

    Very interesting site! fioricet online

  41. Luke Says:

    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

  42. Luke Says:

    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 http
    proxy
    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

  43. collapse Says:

    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?..

  44. Keith’s Recent Thoughts » Blog Archive » Visits from the Open Source Angels Says:

    [...] I was able to create a Virtual PC and installed Linux (I used Ubuntu), mySQL, and Ruby on Rails (this article was indispensable: http://www.rubyrailways.com/getting-ruby-on-rails-up-and-running-on-ubuntu-dapper/). I have yet to make a custom project with it, but it was actually not as hard to get going as I thought. I think I may make a dual boot on my machine. My install of windows is feeling really bloated and sluggish lately. If I really do switch development over to RoR, I may consider getting a Mac for my next machine. The Mac OS has RoR installed by default. [...]

  45. jonny10 Says:

    jonny4

  46. njuki Says:

    Thanks for this article man, i a newbie on ruby on rails, with this i will get started

  47. offsource.org » Blog Archive » Installing Ruby on Rails on Ubuntu Says:

    [...] For installing Ruby on Rails, I found a great tutorial at http://www.rubyrailways.com/ that walks you through the install and setup of both Ruby and MySQL. [...]

  48. israel Says:

    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.

  49. vivek Says:

    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.

  50. deanmor Says:

    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

  51. DrStankus Says:

    collapse,

    that semicolon is supposed to be there after the password. So, you hit on the correct solution. That it isn’t there is probably a misprint.

    Cheers,

    Dr Stankus

  52. SEO Says:

    My main concern is that you can’t guarantee every page of your website will be included in the SERPs. Considering I’m constantly adding new products to my company’s website, I need to be sure that customers can find them as soon as possible.http://www.seoptimizerz.com

  53. pomn Says:

    Very effective. Thanx.4a7d3d609129a9296bf7ac0608c2097

  54. Nicole Says:

    thank you!!

  55. sukeerthiadiga Says:

    uke@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

    thanks a lot …
    i was faced this prob almost one day.. now got solved with this site..
    thanks

Leave a Reply



Comment Preview


Bad Behavior has blocked 1647 access attempts in the last 7 days.