In the Ubuntu Intrepid setup articles ( Ubuntu Intrepid - Setup) we secured, updated and personalized the install ready to add some working software.
Ubuntu Intrepid setup - page 2
This article has been updated to use the latest (at the time of writing) version of rubygems which is v2.2.0 as well as rails version 4.0.2.
While ruby is available via package management systems the version available is usually quite stale. While this may take some time the best way to ensure that we get the proper versions for ruby as well as rubygems would be to compile from source.
Prerequisites, these packages will enable us to compile ruby as well as necessities for ruby/rails.
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev nodejs
In order to compile ruby we need to download the source. The best place to do that is directly from the Ruby-Lang website.
This page will have all of the current stable versions of ruby listed, as well as the most currently released stable version. For this guide we will be installing v2.1.0, as it is the most current stable release, however with Rails 4.x you may choose 2.0.0 as well as 1.9.3, all which will compile and install rubygems in the same manner.
Create a directory for our source:
mkdir src && cd src
tar -xzvf ruby-2.1.0.tar.gz
make && sudo make install
Once this has been done you can check the ruby version
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
Because we compiled from source we will also have rubygems installed, check the version with this command:
To make sure rubygems is at the latest version you can run the command:
gem update –system
Now that we have ruby and rubygems correctly installed we can move onto installing the rails framework.
sudo gem install rails
This will take some time and install of the necessary gems required for rails to function normally. After the command has finished running you can check the rails version with the command:
To create an application you can simply run the command:
rails new sampleapp
This will create all of the necessary files and directory structure inside of a new directory ‘sampleapp’.
By default Rails will use sqlite as a database however you can also use MySQL when creating a new application.
In order to do this you will need the MySQL client-dev package, along with the ruby mysql library in order for the database connector to work:
sudo apt-get install libmysqlclient-dev libmysql-ruby
Once that has been installed we can create a new app with the MySQL adapater, first installing the gem, and then creating the application:
sudo gem install mysql2
rails new sampleapp –d mysql
Finally, we need to install postfix so we cansend mail from our Rails applications:
sudo apt-get install postfix -y
Answer the postfix questions as you see fit but the defaults usually suffice for our purposes as we are only using it to send emails and not for receiving mail
You now have a Ruby on Rails stack setup and ready to roll. You are ready to install the server of your choice whether that be Litespeed, Nginx or Apache.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License