Posted by: rusteddev | October 8, 2010

How to – Create your first Rails App

Today, I’ll tell you how to install Ruby On Rails on Ubuntu. It’s quite simple if you follow this steps and are aware of some tricks.

Prerequisites are :

  • Ubuntu 10_04 (Lucid Lynx)
  • Internet Connection (for updates of packages and gems)

Here it is :

  1. Update your system to download latest versions of packages. Go to System / Administration / Update Manager. In Tab Ubuntu Software Make sure you have Community-maintained Open Source Software (universe) checked. Check Install updates. Restart if needed.

    Update your packages to last version available

  2. You can also update with command line using :

     sudo apt-get update
    
  3. Install complementary tools :
  4. sudo apt-get install curl git-core build-essential zlib1g-dev libssl-dev libreadline5-dev
    
  5. Now we will install RVM (Ruby Version Manager) which will be used to install ruby. The following command will download last version from git and install it. More info here.
  6. bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    

    Add the following line in your .bashrc file : this will make your rvm usable. Without this you will get a No command ‘rvm’ found message. Don’t forget to restart your terminal window.

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.
    
  7. Then you can install last ruby version 1.9.2. DO NOT USE sudo with rvm. When using sudo you are considered as root and gems for instances do not go in the expected directory. It becomes quickly a mess. See here for explanations. Have a coffee as it takes a while…
  8. rvm install 1.9.2
    

    and then this to set default ruby version as 1.9.2.

    rvm 1.9.2 --default
    

    at any time, check ruby version with ruby -v

  9. Now time as come to install rails. I suggest using gem. Don’t press Ctrl-C to fast as gem is not verbose by default. Let it be :
  10. gem install rails
    

    You can append –version 2.3.4 if you want a specific version of rails. Type rails -v to check if the good version is succesfully installed.

  11. Now you can try your first app :
  12. mkdir $HOME/workspace
    cd $HOME/workspace
    rails mytestapp
    

    Rails will show you the files created.

  13. Then run the web server : depending the version of Rails you should use :  ./script/server from mytestapp home dir if you have 2.3.4 rails or rails server if 3.0.0. Go to the URL indicated and you should see this :
  14. Your rails app is up and running !

    Great ! but if you try to click on “About your software environment” link : it will fail.

    Error using test app

    That’s because your database is not ready, see the server log.

    Error in server log : No Such FIle To Load sqlite3

    To correct this :

  15. Install libraries :
    • Ruby v1.9.1 is not supported and throw you segmentation faults. Do Not use it.
    • Your firewall might be annoying : to pass firewalls : Use -p http://your_proxy:port parameter with gem or apt-get
  16. sudo apt-get install sqlite3 libsqlite3-dev
    gem install sqlite3
    

    Start again your server. You’re done. Rails is OK and you can follow rails suggestions and start modifying your app (migrate data, modify routes, pratice scripting and tests…).

    And one more thing….. keep this in mind  :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: