Ruby on Rails 3 Work Environment – Ubuntu

Ruby on Rails 3 can be hard to get up and running, especially on Windows. That’s why I changed to Ubuntu. You can too, by running a virtual machine.

    You can install and use Ubuntu on Windows using a virtual machine. Just download the latest Ubuntu and then run it on the virtual machine – pretty straightforward.

    Once you have Ubuntu installed you can get the rails environment up and running. I recently found out that Heroku (my rails host of choice) like postgreSQL instead of mysql (you can use mysql but you have to link it to Amazon RDS). so I have added a second link to help you setup postgreSQL – NOTE the postgre gem didn’t work for me, but the ‘pg’ gem did (that’s right – it’s a gem called pg. It’s actually made by the creator of Ruby).

    How to install rails 3 on Ubuntu 9.10 x64

    Installing Ruby on Rails with Postgresql on Ubuntu Jaunty

    The rest of this post is for when you have installed RVM.

    RVM is perfect for the developer who wants to dabble in new versions of rails, but still be able to create/edit their ongoing older rails applications.

    The reason for this post is that I happened to spend around 10 hours in a confused state trying to get this all set up on Ubuntu. There is a maze that one can easily fall into, and struggle to get out. Here are some rules to stop you falling into that maze:

    To install a ruby version, say ruby 1.9.2 go:

    $ rvm install 1.9.2

    Once rvm is installed you can go:

    $ rvm 1.9.2 --default

    This will put you into ruby 1.9.1 and sets it to default. To see that it worked type in:

    $ rvm info

    To change ruby to the version originally installed on your system:

    $ rvm system

    To install a gem on all your ruby versions:

    $ rvm gem install haml

    To install a gem on the version you are currently in:

    $ gem install haml

    To install a gem on a different version:

    $ rvm 1.9.1 gem install haml

    So you don’t use ‘sudo gem install’ – just ‘gem install’ (after loading your ruby environment).

    Sudo apparently pulls you out of the carefully tuned rvm environment.

    Install Rails 3

    $ rvm 1.9.2 --default
    $ gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
    $ gem list
    # If you get an error when just typing in 'gem install rails', try this:
    $ rvm 1.9.2 gem install rails

    So your gems will be different for each ruby version. This is because if they all use the same gems – things go wrong.

    Note – Rails asset versioning causing me problems in Ubuntu:
    When editing CSS in rails, I found that when I made edits and refreshed the page, my rails app would suddenly not recognise any of my css files. This is because of the timestamps rails puts on the end of the files – for some reason Apache is not reloading the new, updated files.

    Fix:

    Turns out it was WeBrick. ‘gem install mongrel’ and then ‘script/server mongrel’ makes it work.

    Tagged: , , , ,

    About the Author

    Plattsi | Other Articles

    A twenty something web developer and entrepreneur from Sydney, Australia. Loves building web applications that are both easy and fun to use (and don't require manuals).

    • Kevin DeVrou

      Being a new rails developer myself, this guide has helped me iron out some of the problems with my setup. Thanks for the great articles and please keep them coming.

    • Anonymous

      Thanks Kevin