h1

Installing Rails without root

December 9, 2007

Updated the script Jan 6, 2010 to add mkdir INSTALL_ROOT (excellent suggestion), use recent versions of ruby and rubygems (the old script was broken for me), and pull the versions into variables so it is easier to tweak this later.

It might also help to note that you will need the zlib and openssl development packages, and if you plan to use the console you almost certainly want readline as well, and all of that before you build ruby. On Debian these were libssl-dev, zlib1g-dev, and libreadline5-dev.

Some people are concerned with keeping their /usr hierarchy clean. Some people have no root access to the system that they are on. Some people don’t like using /usr/local. These people still want to install and run Ruby and Rails, but it will be best for them if it is done in a way that will keep gem working as it should.

I like to tell these people, “Oh it should be easy,” but I had to really make sure. There is one little trick, which is to make sure you really are using the right ruby when you install rubygems and then the right gem when you install Rails (and forever after).

As much for my own benefit as for anyone else’s, I put together a script so that I don’t forget. This should work on any UNIX that has the build dependencies for Ruby. That includes Linux of flavors Redhat, Ubuntu, Debian, and Slackware for all you Google fans out there. (The guy whose problems prompted me to put this together was using Ubuntu.) I like Debian but have found that Rails changes way too fast for Debian packages to be a viable way to install it. Gem is much better and standard in the Rails community, so you should do a local install of Ruby from source and then install rubygems using that version.

Without further ado, here’s the script that will save you time. You will need to edit it some unless you want /opt/rails. Personally I use /usr/local. It will also leave a build subdirectory in whatever location you use. It is your option to remove it after the fact. I would do so myself.

#!/bin/bash
INSTALL_ROOT=/home/matt/rails

RUBY_PATH=ftp://ftp.ruby-lang.org/pub/ruby/1.8/
RUBY_FILE=ruby-1.8.7-p248.tar.gz
RUBY_DIR=ruby-1.8.7-p248

RUBYGEMS_PATH=http://gemcutter-production.s3.amazonaws.com/rubygems/
RUBYGEMS_FILE=rubygems-1.3.5.tgz
RUBYGEMS_DIR=rubygems-1.3.5

mkdir $INSTALL_ROOT
cd $INSTALL_ROOT
mkdir build

cd $INSTALL_ROOT/build

wget $RUBY_PATH$RUBY_FILE
tar zxvf $RUBY_FILE
cd $RUBY_DIR
./configure --prefix=$INSTALL_ROOT
make
make install

cd $INSTALL_ROOT/build
wget $RUBYGEMS_PATH$RUBYGEMS_FILE
tar zxvf $RUBYGEMS_FILE

# This is crucial. rubygems setup really cares where ruby ran from, and if
# you have a system-wide ruby then it might get confused.
export PATH=$INSTALL_ROOT/bin:$PATH
# Of course you will also want to make sure you include this wherever you
# normally set your PATH.

cd $INSTALL_ROOT/build/$RUBYGEMS_DIR
ruby setup.rb

cd $INSTALL_ROOT
which ruby
which gem

gem install rails

gem environment
which rails
rails --version
Advertisements

6 comments

  1. Thanks for the script, very handy. It might be nice to have a
    mkdir $INSTALL_ROOT
    at the beginning.


  2. why on earth would anyone install this from root?


  3. I doubt anyone would install under /, if that’s what you mean. For myself I typically install under /usr/local as the root user (which is the same as leaving out –prefix).

    I wrote this up when I was trying to help someone who wanted to install it as the root user but under /opt/rails, which is kind of a strange place to put Ruby, but whatever. That particular person was having continued difficulties despite more terse advice about how to use –prefix.

    There are other variations, like system-installed Ruby but with your gems somewhere else, but I wanted to keep it simple here.


  4. That was pretty awesome..!! Earlier I had spent 3 days in installing and even that gave segmentation errors. This script just ran for about 5 minutes and installed Ruby!! Hats off.


  5. Tried these steps and got
    illegal Instruction(coredump)

    When I did:
    ruby setup.rb
    Illegal Instruction(coredump)

    Any idea why?


  6. I am not familiar with the Illegal Instruction(coredump) exception – if it is even a Ruby exception. It looks like it is probably a C-level error.

    I updated the script to use the new versions of ruby and rubygems – don’t know if you had already done that, but if not you may get lucky if you just try again.



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

%d bloggers like this: