RSS Feed Subscribe to RSS

Howto: Make a Rails Environment in Ubuntu

In class today, there was a demonstration on how to get Apache/Axis/Tomcat running to demo some SOAP web services written in Java. As I plug Rails again, I was again amazed at the simplicity with which Rails handles all this. I began to think that there might be some interest in Rails web services for those other members in my class, so in an attempt to help them out, I decided to provide instructions on setting up a Ruby on Rails environment.

Now I’m running mine inside a virtual machine with VMWare Server on my Windows Server 2003 box. I won’t get into all the reasons here, but these intructions would work for any VM or for a real install as a host operating system. There are only one or two differences and I’ll point them out as we go along.

1. Start with Ubuntu Server distro. I’m using Ubuntu 6.10 Edgy Eft.
Find the mirror you want, then click the Other Installation Options and find the server. If you must have a graphical environment, you can get the desktop version, but know that youll have to install apache2 and mysql on your own. If you choose the server option, you’ll be asked what kind of install you want to do. Pick the LAMP option. Do all appropriate setup, naming, networks, etc., and I’ll meet you again at the shell after you login.

2. Edit your sources list.

sudo vi /etc/apt/sources.list

Once you get inside, you’ll want to uncomment 4 lines, which will enable the universe repository along with the security universe repository. I typically comment out the cdrom: repository as well. For those unfamiliar with vi, the letter x will delete a single character. Pushing the letter i will put you in insert mode to comment our the cdrom line. Pushing Esc will get you out of edit mode. Pushing :, then wq, and finally Enter will put you back at shell with an edited sources list.

3. Get SSH running
For me this is essential. The interface through VMWare isn’t the speediest thing, and when you’re running over a Remote Desktop connection, things start to feel like molasses. A few things will fix us right up, because through SSH everything runs beautifully.

sudo apt-get install openssh-server

This will install and start the SSH server. Now you may need to configure port-forwarding through port 22 in order to connect to your Rails/Ubuntu server. In addition if you need to forward traffic to your VM, then at your router point port 22 at the host OS and follow my other instructions on port forwarding to a virtual machine.

If you’re happy where you’re at, then you can skip step 3. If you want to do it, then SSH to your new server and continue to Step 4.

4. Update all your packages

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install saidar

Saidar is optional, it’s a neat little monitoring utility that runs at the command line, but tells you about your CPU usage, memory usage, disk usage, and everything else you’d expect from your Task Manager or Activity Monitor. Now it’s time to get down to business.

5. Install Ruby

sudo apt-get install ruby ruby1.8 ruby1.8-dev ri rdoc irb libmysql-ruby libmysqlclient15-dev

If you didn’t choose the LAMP option earlier (or picked a desktop distro) you’ll want to add Apache2 and mysql-server to this list:

sudo apt-get install ruby ruby1.8 ruby1.8-dev ri rdoc irb libmysql-ruby libmysqlclient15-dev apache2 mysql-server

6. Install RubyGems
RubyGems is like the apt-get utility for strictly Ruby packages. This series of commands at the shell will download, install, and clean up the RubyGems package.

wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
tar -xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
sudo ruby setup.rb
cd ~
rm -rf rubygems-0.9.0
rm rubygems-0.9.0.tgz

7. Install Rails

sudo gem install rails --include-dependencies

This will show some errors while installing documentation, but never fear. All is well. We both know that you weren’t planning on reading the documentation anyway.

8. Install Lighttpd with FastCGI

sudo apt-get install lighttpd libfcgi-dev libfcgi-ruby1.8 build-essential

This will show an error that it tried to bind to port 80 and failed. That’s ok, because we have apache running there. What we’ve done is simply install it so that our Rails apps will use Lighttpd rather than the built-in WEBRick.

If like me you really just don’t like errors you can edit the lighttpd.conf file so that it binds to a different port. This is not necessary at this point, but if you plan on running Rails apps in production you’ll have to play with the lighttpd config file at some point anyway.

vi /etc/lighttpd/lighttpd.conf

Find and uncomment the line that says

# server.port = 81

Now we’ll run Stop just to make sure and then Start it up again.

sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/lighttpd start

Now install the fcgi RubyGem:

sudo gem install fcgi

9. Make sure that your FastCGI bindings and MySQL bindings are working properly.
Now to make sure that our fastcgi and mysql libraries are working properly, we’ll fire up IRB. IRB stands for Interactive Ruby. It basically gives us a functional, yet empty ruby environment to play around.

irb
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> require 'fcgi'
=> true

Now, unless you want to do all your mysql configuration from the command line, you’ll need to be able to connect as root to your mysql database from a remote host. See my instructions on how to do that. You may need to set up port forwarding through port 3306 in order to get this to work.

3 Responses to “Howto: Make a Rails Environment in Ubuntu”

  1. benrobb » Blog Archive » Howto: Put WSDL on Rails |

    [...] let’s get down to business. I’ll make the assumption that you’ve got a working Rails environment.  For Mac users, the latest version of Locomotive has everything you need for creating web [...]

  2. Ruby Brasil - » Ubuntu on Rails |

    [...] http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/ [...]

  3. Macca |

    Hey,

    You have a typo here I think:

    sudo /etc/init.d/lightppd stop
    sudo /etc/init.d/lightppd start

    Should read

    sudo /etc/init.d/lighttpd stop
    sudo /etc/init.d/lighttpd start

    cheers

Leave a Reply