Ubuntu LTS - MySQL and RoR

In the previous Ubuntu LTS setup articles page 1 and page 2 we secured, updated and personalised the install ready for some action.

Now we can install MySQL and Ruby on Rails with subversion and postfix support.


MySQL install

Right, let's get on and install MySQL:

sudo apt-get install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby -y

Password

MySQL installs without a password for the root user (don't confuse this 'root' user with your Slice root user - it is simply the MySQL user that has administration rights to all the databases, not to your system).

Let's add a password straight away:

mysqladmin -u root password YOURMYSQLPASSWORD

InnoDB

If you are not going to use InnoDB with your MySQL databases, then it is a good idea to turn it off right at the start. It uses a lot of memory and, if not going to be used, this is wasted memory.

Open the main MySQL config file:

sudo nano /etc/mysql/my.cnf

Search my.cnf for the heading:

# * InnoDB

Then, to turn off InnoDB, simply uncomment (remove the #) on this line:

skip-innodb

Ruby on Rails install

We'll begin by installing ruby from the apt repositories and then installing rubygems via source code:

sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby -y

Symlink

We need to create some symlinks from the install to locations every programme would look. Each line below is a separate command:

sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Update

This articles has been updated to use the latest (at the time of writing) version of rubygems which is v1.2.0.

This version of rubygems has finally fixed the memory issues seen on smaller Slices.

You can now install, update and administer all your rubygems from within a 256Slice with no issues.

Rubygems

Let's go ahead and download the source code into our sources directory. If you haven't got a sources directory, you can simply create one:

mkdir ~/sources
cd ~/sources
...
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz

Then unpack it and move into the newly created folder:

tar xzvf rubygems-1.2.0.tgz
cd  rubygems-1.2.0

Now we can go through the simple process of compiling it and creating a symlink:

sudo ruby setup.rb
...
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Update

Whenever you need to update the installation just enter the following:

sudo gem update
sudo gem update --system

Rails

Now we can install rails with the command:

sudo gem install rails

The basic Ruby on Rails install is now completed! Let's continue the install with imagemagick and a quick ruby test as follows:

sudo apt-get install imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev xml-core -y

Testing

Now we can do a quick test to see if the install works (thanks to brainspl.at for this idea).

irb
#irb(main):001:0>
require 'RMagick'
#=> true
#irb(main):002:0>
require 'mysql'
#=> true
#irb(main):003:0>
exit

Obviously, if the output does not return 'true' for each 'require' command, then something has gone wrong. If the result is correct and returns 'true' then we have a working ruby install.

Postfix and subversion

Finally, we need to install postfix (if we don't do this now, other programmes will install exim and all sorts of unneeded email help). Once done we can install subversion so we can 'check-out' plugins and other goodies for our Rails applications:

sudo apt-get install postfix subversion -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.

That's it

You now have a MySQL, Ruby on Rails and subversion stack setup and ready to roll.

Now you are ready to install the server of your choice whether that be Litespeed, Nginx or Apache.

PickledOnion.

Article Comments:

Todd commented Mon Oct 22 18:35:11 UTC 2007:

I noticed that Ruby version is 1.8.4 and Rails recommends 1.8.6. Are there any issues with using 1.8.4?

iain commented Sun Oct 28 22:00:09 UTC 2007:

This is a very useful tutorial, but I think I would have found it sooner if it had not said mysql + ror. Maybe it would be cool to break this out into a mysql general article with details on what one might do to prepare for ruby, python, perl, or php access?

PickledOnion commented Mon Oct 29 09:00:50 UTC 2007:

Hi Iain,

There will be some separate MySQL articles which include setting up and optimisation.

Thanks.

PickledOnion.

Frank commented Thu Nov 29 20:04:32 UTC 2007:

"I noticed that Ruby version is 1.8.4 and Rails recommends 1.8.6. Are there any issues with using 1.8.4?"

I second that question...

Dragosh commented Tue Dec 11 19:45:05 UTC 2007:

To upgrade from ruby 1.8.4 to 1.8.6 http://scoop.cheerfactory.co.uk/2007/11/02/upgrading-ruby-on-ubuntu-dapper/

iain commented Sun Nov 02 20:32:46 UTC 2008:

Wow...two iains at slicehost...very rare to see it spelled "iain"

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)