Ruby on Rails
RailsOnUbuntuDebianTestingAndUnstable

This page is deprecated by RailsOnUbuntu

Debian’s Postion on Rubygems
The following instructions tell you to run commands as root on your computer. As always, don’t run things as root before you think about them, especially commands that come from a wiki that can be edited by anonymous people.

On Ubuntu Breezy, and probably on others, you can use the “Synaptic” tool to do most of this in a GUI. The package you need to install is “rails”.

Become root, and paste the following command to install the necessary packages:

 apt-get update

Now continue with one of the “Installing…” sections below depending on whether you are running Debian Unstable, Testing, Woody or Ubuntu Warty, Hoary or Breezy.

Installing Rails on Breezy via RubyGems (recommended)

# uncomment the universe repositories from /etc/apt/sources.lst first
# after uncommenting you will need to run sudo apt-get update 
# again or some packages may not be found ('rdoc1.8' for ex.)
sudo apt-get install ruby rdoc1.8 irb libyaml-ruby libzlib-ruby

wget <a href="http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz">http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz</a>

tar xzvf rubygems-0.9.0.tgz
cd rubygems-0.9.0
sudo ruby setup.rb
sudo gem update --system
sudo gem install rails -y
# you may also want to install some defacto gems
# sudo gem install BlueCloth RedCloth capistrano syntax -y
# more fun ruby stuff:
# imagemagick for ruby:
# sudo apt-get install librmagick-ruby
# GD for ruby:
# sudo apt-get install libgd-ruby1.8

If you’re running ubuntu, try:

apt-get install zlib1g-dev

before running ./configure for ruby

Installing on Debian Unstable or Testing, or Ubuntu Breezy

Another good source for a walkthrough is here:
http://fo64.com/articles/2005/10/20/rails-on-breezy

and here:

http://davidwinter.me.uk/articles/2006/02/05/ubuntu-5-10-web-server-howto

apt-get install rails

And you’re done.

Installing on Ubuntu Hoary

Edit /etc/apt/sources.list and add the hoary-backports repository.

# hoary-backports
# This includes packages from Breezy backported to Hoary.
deb http://archive.ubuntu.com/ubuntu hoary-backports main universe

Now you can install rails via apt.

apt-get update
apt-get install rails

And you’re done.

Installing on Ubuntu Warty

First you need to make sure the universe repositories are accessible. Uncomment these lines in your /etc/apt/sources.list


deb http://archive.ubuntu.com/ubuntu warty universe
deb-src http://archive.ubuntu.com/ubuntu warty universe

Then, you’ll need to run apt-get update to get the list of universe packages:

apt-get update

Then install the packages:


apt-get install \
        irb1.8 \
        libbigdecimal-ruby1.8 \
        libcurses-ruby1.8 \
        libdbm-ruby1.8 \
        libdl-ruby1.8 \
        libdrb-ruby1.8 \
        liberb-ruby1.8 \
        libgdbm-ruby1.8 \
        libiconv-ruby1.8 \
        libopenssl-ruby1.8 \
        libpty-ruby1.8 \
        libracc-runtime-ruby1.8 \
        libreadline-ruby1.8 \
        librexml-ruby1.8 \
        libruby1.8 \
        libruby1.8-dbg \
        libsdbm-ruby1.8 \
        libsoap-ruby1.8 \
        libstrscan-ruby1.8 \
        libsyslog-ruby1.8 \
        libtest-unit-ruby1.8 \
        libwebrick-ruby1.8 \
        libxmlrpc-ruby1.8 \
        libyaml-ruby1.8 \
        libzlib-ruby1.8 \
        rdoc1.8 \
        ri1.8 \
        ri \
        rdoc \
        ruby \
        ruby1.8 \
        ruby1.8-dev \
        libmysql-ruby1.8 \
        ruby1.8-examples\
        libfcgi-ruby1.8

Previous list, updated for Ubuntu Edgy Eft (6.10)

In Edgy, it seems an awful lot of packages are rolled into libruby1.8 that were previously separate. The following should work without complaining on a vanilla edgy install:

apt-get install \
        irb1.8 \
        libdbm-ruby1.8 \
        libgdbm-ruby1.8 \
        libopenssl-ruby1.8 \
        libreadline-ruby1.8 \
        libruby1.8 \
        libruby1.8-dbg \
        rdoc1.8 \
        ri1.8 \
        ri \
        rdoc \
        ruby \
        ruby1.8 \
        ruby1.8-dev \
        libmysql-ruby1.8 \
        ruby1.8-examples\
        libfcgi-ruby1.8

Common procedure for Debian Sarge and Ubuntu Warty

(You don’t need to do this if you’re running Debian Unstable or Testing, or Ubuntu Hoary or Breezy)

Download the rubygems package installer, used to install “gems” (ruby packages), from http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz

Extract rubygems:

        tar zxvf rubygems-0.8.11.tgz

Set up rubygems:

        cd rubygems-0.8.11
        ruby1.8 setup.rb

Use the rubygem installer to re-install itself. This will get you the latest revision:

        gem install rubygems-update

OK, now you can install gems for other software. Run this command to install rails:

        gem install rails --include-dependencies

If installation of Ruby Gems fails with the message:

hook /home/dml/dloads/rubygems-0.8.3/./post-install.rb failed:
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.

You need to manually create the directories /usr/lib/ruby/gems and /usr/lib/ruby/gems/1.8

Once this completes, you should have a “rails” command. Test it:

        cd ~
        rails Test
        cd Test
        script/generate controller test
        script/server &

Open your web browser to http://localhost:3000/
You should see a “congratulations” page.

Please email bruce at perens dot com and tell him if these instructions worked, what Debian system you are using (unstable, testing, ubuntu hoary, etc.) and any other comments. Thanks! – BrucePerens

Discussion

Note to the the two people so far who have felt that apt-get is not the appropriate package system to use: please leave apt-get in place. Neither Wajig nor Aptitude are standard components in a Debian system.

Q: How do I install the sqlite db drivers?

sudo apt-get install sqlite

Q: Is this the recommended way to install rails, and not apt-get install rails?

The recommended way definitely is via apt-get install rails. In fact, that’s the main reason for using a Debian based linux distribution—it will manage stuff like that for you. On Debian Sarge, apt-get install rails just doesn’t work at the moment. However it is already available in Debian Unstable.

FWIW, this worked fine for me on Ubuntu Hoary.

For a fresh Ubuntu Hoary install, start with

sudo apt-get install mysql-server

and then set up databases from development, testing, and production, and a user with access to them.

Q: How do I install FastCGI?

We have rails installed and working. And now we can use FastCGI with Apache.

For Apache 1.x, mod_fastcgi is recommended (note that mod_fastcgi hasn’t been updated in years).

For Apache 2.x, mod_fcgid is recommended over mod_fastcgi because it is more reliable with Apache 2.x.

An alternative to Apache 1.x and 2.x is to use Lighttpd-1.4.x web server. But wait until Lighttpd-1.4.11 or later because the current release has annoying bugs.

For Apache 1.x, install mod_fastcgi:

$ sudo apt-get install libapache-mod-fastcgi libfcgi-ruby1.8
$ sudo a2enmod fastcgi
$ sudo /etc/init.d/apache reload

For Apache 2.x, install mod_fcgi:

$ sudo apt-get install libapache2-mod-fcgid
$ sudo a2enmod fcgid
$ sudo apt-get install libfcgi-ruby1.8
$ sudo /etc/init.d/apache2 reload

And then …

$ wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz
$ tar zxvf fcgi-2.4.0.tar.gz
$ cd fcgi-2.4.0
$ ./configure
$ sudo make install

Q: Why do I just see the contents of dispatch.fcgi when using mod_fcgid with the default rails setup?

Change

AddHandler fastcgi-script .fcgi

to
AddHandler fcgid-script .fcgi

in /public/.htaccess


If you get “failed require zlib” (or something like that) when building RubyGems, what you probably need to do is install zlib1g-dev (via Synaptic or apt-get) before you install Ruby.


I tried this and while Rails runs, there are a few caveats. script/console doesn’t work because of the readline dependency. Building it according to the instructions elsewhere in this wiki didn’t work either. Someone with a little more experience in this area should add update this page with the proper procedure.


If you are running Ubuntu Hoary and want to install rails using rubygems you will need to install libopenssl-ruby with apt. (see http://rubyforge.org/pipermail/rubygems-developers/2005-January/001343.html)

Otherwise the install will fail with “SSL is not installed on this system” message.


History: This page was created from the page RailsOnDebianUnstable. It was done in order to rename the page which is not possible without admin rights. Please look at RailsOnDebianUnstable for the history of this page!—Tomas Pospisek


As far I’m aware there is no “rails” package in the Ubuntu Hoary backports (anymore?). Please correct me if I’m wrong, but I had to install rails the “Warty” way. And if one does that, an extra package needs to be installed to make fast-cgi work: libfcgi-ruby1.8. Once that is installed, libapache2-mod-fastcgi can be installed.

As of September 27, 2005, there is a “rails” package in hoary-backports.


History: This page previously contained a slew of work arounds for an Ubuntu Hoary bug (https://bugzilla.ubuntu.com/show_bug.cgi?id=12613).

This has been resolved by backporting ruby (and rails) from Breezy.
Workarounds have been removed and instructions for installing the backport are above.


If you find the above guide not working 100% properly on a clean Ubuntu Hoary (5.04) install (no script/console, unable to do “gem install mysql”), you might want to read a more detailed installation instructions here: http://paulgoscicki.com/archives/2005/09/ruby-on-rails-on-ubuntu/


srmaddox@gmail.com

I’m having a problem using ./script/generate scaffold. It creates some files and then quits with an error: “No such file or directory – /tmp/mysql.sock”. What gives?

Answer here: MySQL


One caveat I ran into, moving a Rails app from my Debian Sid home system (rails .deb) to a CentOS work system (self-compiled ruby 1.8.2 w/ a rails gem) was that I needed to uncomment require ‘rubygems’ unless File.directory?(”#{RAILS_ROOT}/vendor/rails”) line in config/environment.rb in order to get things running on the non-Debian system.



I tried following this procedure on Ubuntu 4.10, and rails failed to execute reporting:

root@none:~ # rails Test

Rails requires Ruby version 1.8.2 (2004-12-25) or later.
You're running 1.8.2 (2004-08-24); please upgrade to continue.

Larry Young
lyoung@zedak.com

Question: How to modify Apache2/Rails setup to also allow PHP to work for certain sites? PHP/Rails must learn to play nicely together.

Nice question, I’d like to have php, too :) I think the solution is something related to http://wiki.rubyonrails.com/rails/pages/HowToCreateVirtualHostsForRailsAppllications
or if it is just for test http://assente.altervista.org/?q=rails_and_php_on_apache_without_virtualhost

For the past few days I have been working on getting my new Ubuntu 5.10 (Breezy) development server set up. I need MySQL, PHP, Ruby on Rails, and Apache2 as major components. I am also evaluating Lighttpd and several other smaller tools as I go. This Howto and several other documents have been a big help, but there are a few notes that might help others, so here they are:

Ubuntu – Just use the standard distro. You will need to enable all the repositories before it is over, so go ahead and get used to that. Lots of the code comes with the OS, but there are many parts by can apt-get or use Synaptic for from non-core sources. I think the notes here make that plain. I would also suggest you go ahead and get used to running gksudo for nautilus and gedit. It is not very nice to play root, but it does let you edit and alter files faster with the GUI. I found this a big help.

MySQL – I decided to just use the 4.02x version. For me that was not a deal-breaker yet. I want to update to the 5.x release, but my current dB needs are not that complex just now. I also wanted to minimize the chance for confusion as I built up the system. If you must get the newer versions there are binaries if you search for them. Of course you could build it, but I find that a pain much of the time. I find there are a lot of errors in the MySQL Admin GUI that comes with the current Ubuntu release. This appears to be a MySQL problem, not isolated to the Ubuntu version of MySQL being old (from notes on the MySQL site). I am using PHP MyAdmin or the command line most of the time now. I also suggest going ahead and creating some non-root MySQL dB logins (users) so you can avoid using the MySQL root account. This is just the right way to do it.

Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories

Computers – Computer Add-Ons
Computers – Desktops
Computers – Handhelds & PDAs
Computers – Notebooks

Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers

PHP - OK I did go with 5.x here – it was available and it is working for me. When you get PHP you will notice it causes a downgrade on the Apache2-mpm-worker threading system. I got worried about this but there is not a lot of choice unless you want mucho pain in the config, so I took the downgrade. I have not seen any critical errors yet, but this is not a production box. For personal development servers I suggest you not worry about it too much. Honestly, PHP installed so fast I did not have time to notice. Once installed it just worked the first time. My test app for PHP was WordPress 2.0, and then I added PHP MyAdmin. Both worked right the first time using only the readme included with the packages. I did have to do some Apache2 configuration to put them where I wanted them, and access them as I wanted, but this was a helpful experiance after all the pain of the past few days with RoR configuration. I got to know Apache2 beter with apps I have used in the past, so I came back to my RoR problems feeling like I knew how to fix them.

RoR – Actually I did not have much trouble getting or installing RoR and GEM. The instructions above did it for me very well. I would recomend creating a small non-dB RoR app and a small dB RoR app for testing. I wrote a little non-dB app, and downloaded Typo as a test dB app for RoR. The real issues I have were not RoR related – they were Apache2 config related. Seeing these test apps work in Webrick was a big relief as I beat on the config…

Apache2 – Well, this is what took the time. Between the pain of getting and installing FastCGI, and re-learning the new Debian/Apache2 way of doing virtual sites I had a mess on my hands. At this point I am still running with FastCGI (not FastCGID), but I will change that over the next few days. Once I got all the parts to work independently I had to fit them together. It was clear that adressing virtual sites and the re-write rules were causing problems, but the answers were about a clear as mud.

What I finally did was to restore my default site to /var/www/. I had lost my 000-default config by accident (I typed before I thought). I had to re-build that. Do yourself a favor and be sure you read the /etc/apache2/readme that you get with Ubuntu. Track down some notes on the Debian/Ubuntu/Apache2 config changes. Learn to use the a2enmod and a2ensite tools. you will need to use these to be sure you have FCGI enabled (or any other mod – like re-write,etc…). I will leave it to the notes above to get you past apt-get install of fcgi or fcgid.

I am setting up a personal development server. Most of the notes I find are written for people setting up on remote servers. The problems are similar, but not quite identical. They both boil down to path and URL issues. What I decided to do was to create a set of subdirectories under my /var/www/ directory for my projects. On a shared production box most of this would be under your user area. For me, I created a simple HTML index page to idnetify my root (/www/var/) so I could see what I was doing. I then created directories like /var/www/foo/ and /var/www/foo2/ (where ‘foo’ is some name that means something to you like ‘blog’ or, ‘rubytestapp1’ or, ‘PHPtools’. I then created a seperate little Apache2 virtual site config file in /etc/apache2/sites-available/ for each site I wanted. One at a time I used a2ensite to build a link into /etc/apache2/sites-enabled. I then bounced the server and edited my /etc/hosts file so I had an entry for each site. The /etc/host enties look like this:

127.0.0.1    localhost.localdomain    localhost    my_server_name
127.0.0.1    localhost.localdomain    localhost    foo

The /etc/apache2/sites-available/foo file looks like this:
<VirtualHost *>
    ServerName foo

    DocumentRoot /var/www/foo/public/ 
    ErrorLog /var/log/apache2/error.log

    <Directory /var/www/foo/public/>
      Options ExecCGI FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all

    </Directory>
  </VirtualHost>

Yes this is a working dB enabled RoR app, and no, I do not have FCGI on this one as part of my Apache config. I could do that, but I choose to let that come from the /foo/public/.htaccess file. You can move all that stuff into the Apache2 virtual site, but you don’t want to have it all in both places. This is a key concept – put the commands in one place and know where you put them. If you have conflicting directives you will get odd results and you will get lost. I speak from expericance on this. In the long run, I suspect I will move most things out of the .htaccess file, but for now that is how it is. What does that look like for the foo app? Here it is:
# Redirect all requests not available on the filesystem to Rails
RewriteEngine On

# Uncomment this if you're not running Typo in the root of your
# webserver's URL space (i.e. <a href="http://www.example.com/blog">http://www.example.com/blog</a>):
#
# RewriteBase /foo/

# try to suggest current rss subscribers that the url moved permently
RewriteRule ^xml/([a-z]+)$ /xml/$1/feed.xml [R=301]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
ErrorDocument 500 "<h2>Application Error</h2>Typo could not be reached

If you don’t want the classic ‘can not reach rails’ sort of error you need to note the line
 # RewriteBase /foo/

Notice that using Apache2 virtual sites and /etc/hosts we set foo to think it was an app at a base address. Do not uncomment this line in this case! In my browser I can just enter ‘http://foo’ and I see the foo app since I am pointing to the /var/www/foo/public/ dir. It took me a moment to realize this. Well, a lot of moments in all.

Do I need to do more to test CGI/FCGI/FCGID/SRR/etc… sure I do. But for now I have a working development system that has PHP running and RoR working under Apache2. I have Lighttpd installed and running, and once I configure it to point to the right place and use FCGID I will be able to indegrate that as well.

I hope these notes help other people. It tool lots of fussing, and looking on many sites to realize how Apache2 virtual sites should be working on Ubuntu, and I then had to understand what is actually going on in the .htaccess file (extending the virtual site apache2 config), and make sure the two were meshing. I also had to catch the need to set the /var/www/foo/config/environment.rb file to point at ‘production’, and of course to set the /var/www/foo/config/database.yml to my settings for the correct user and dB.

The big confusion is that there is no one way to do the path and virtual directory stuff. Several approaches work, and if you check lots of sites for help, you have to integrate the overlapping stuff or it gets overwhelming and confusing. Much of this will go away when RoR gets into the basic Ubuntu distribution, but untill then, good luck to us all! – cthornhill@juggernit.com


for running rails edge on breezy try

deb http://de.archive.ubuntu.com/ubuntu/ dapper main restricted
deb http://de.archive.ubuntu.com/ubuntu/ dapper universe multiverse

apt-get  install ruby1.8 ruby1.8-dev ri1.8 rdoc1.8 irb1.8 ruby1.8-elisp ruby1.8-examples libdbm-ruby1.8 libgdbm-ruby1.8 libtcltk-ruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8

If you want to upgrade to Dapper’s Ruby, but still stay on Breezy for the rest of your packages:

1. Add dapper to /etc/apt/sources.list (see above)

Make sure /etc/apt/preferences looks like

Package: *
Pin: release a=breezy, v=5.10
Pin-Priority: 900

Package: *
Pin: release a=breezy-security, v=5.10
Pin-Priority: 900

Package: *
Pin: release a=breezy-updates, v=5.10
Pin-Priority: 900

Package: *
Pin: release a=dapper
Pin-Priority: 90

This will tell apt to get all packages from Breezy unless told to get them from Dapper.

Then, whatever packages you want from Dapper, use ’-t dapper’

sudo apt-get install -t dapper irb irb1.8 libpgsql-ruby1.8 libreadline-ruby1.8 libredcloth-ruby1.8 libruby libruby1.8 libyaml-ruby


works fine for me,

it gives

scolex@wurm:~$ ruby --version
ruby 1.8.4 (2005-12-24) [i486-linux]

after rails said

 Rails does not work with Ruby version 1.8.3.
    Please upgrade to version 1.8.4 or downgrade to 1.8.2.


After having installed FastCGI, make sure you change the .htaccess of your railsroot/public to use FastCGI to execute the CGI code. If you want to execute your application under production environment, you will need to add the following line to /etc/apache2/mods-available/fcgid.conf, inside the IfModule block:

DefaultInitEnv RAILS_ENV production

A complete walkthrough can be found at Claudio’s hideout . Very good article.

Another great walkthrough can be found at Brainspl.at


Information about running Rails on XAMPP can be found at RailsOnXampp.


Here’s how to compile a local $HOME copy of Ruby 1.8.5 on Debian and FreeBSD as Dave Thomas briefly describes on pages 35-36 of the Agile book.
compiling ruby 1.8.5 with openssl, iconv, and readline support on Debian (Etch/testing) and FreeBSD in $HOME



Q:When i test
script/generate controller test

There’s a error
 
./script/../config/boot.rb:29: undefined method `gem' for main:Object (NoMethodError)
        from script/generate:2

How should i do?