RSS
 

Posts Tagged ‘speedtrain’

Installing Ruby 1.9.2 & Rails 3 on Ubuntu with a single command

07 Mar

I wrote a script that installs Ruby 1.9.2 with RubyGems, Rails 3 and sqlite on Ubuntu with a single command. This script makes it very easy to get started developing Rails applications on Ubuntu. Its also an easy way for non-ruby developers to run popular Rails applications.

This is a script I originally wrote, a while ago for Ruby 1.8.7 and Rails 2, I recently realized that most of the traffic coming to my blog were people looking to setup Rails on Ubuntu. So I decided to update the script for Rails 3 and Ruby 1.9.2. So please enjoy.

I remember about 2 years ago, when I got kicked out of a shared hosting account because I was using too much CPU time, I was forced to move my high traffic web service to EC2. I was still new to Linux, it was my first time deploying a Rails app in production, and I was going to go live with thousands of users instantly. It was a nightmarish weekend. That’s why I write scripts like this, to help new users from Windows and OS X get comfortable with the Linux world.  Although Ubuntu 10 is much easier than 8.10, and Ruby 1.9.2 is a big improvement, Rails 3 with bundler is also a big relief, this is a script I wish I had 2 years ago while deploying my first Rails app.

Assumptions Made by the script

The script assumes you don’t have an older version of Ruby like (1.8.7) installed on the system. If you already have an older version of Ruby installed, use RVM instead of this script. To check if you have an older version of Ruby installed type

ruby -v

Installing and setting up Rails with a single command

Step 1: Install Git if you don’t already have it

 sudo apt-get install git-core

Step 2: Download the script from Github

 git clone git://github.com/obi-a/speedtrain.git

Step 3: Change to the speedtrain directory (the script is called speedtrain)

 cd speedtrain

Step 4. Make the script executable

 chmod +x speedtrain

Step 5. Run the script

 ./speedtrain

This will install Ruby 1.9.2,RubyGems, Rails 3 and Sqlite. It will create a folder in your $HOME directory for your Apps called rails_apps. It will also create a sample Rails App called testapp.

To run the sample Rails app. Type…

 cd $HOME/rails_apps/testapp
 rails server

To view the app, open a browser and type http://localhost:3000/

To create a new Rails app. Type..

 cd $HOME/rails_apps
 rails new myapp

Who should use this script

  • Rubists from MS Windows and OS X getting into Ruby/Rails/Linux
  • Non-Rubists that need to run Rails apps on Ubuntu
  • Newcomers to the Ruby/Linux World
  • Rubists that only need Ruby 1.9.2

Related Posts:

Ubuntu, Ruby, RVM, Rails and You

Source code for the script: https://github.com/obi-a/speedtrain/blob/master/speedtrain

 
 

Installing Rails + Apache + Passenger on Ubuntu 10.04 with Speedtrain

08 Aug

[Update 3/7/2011] Check the updated version of the speedtrain script for Ruby 1.9.2 and Rails 3 here: http://obi-akubue.org/?p=922 and https://github.com/obi-a/speedtrain. This version doesn’t install Apache, Passenger yet.

I have written a new version of the Speedtrain script. This version now includes an option to install Rails with Apache and Phusion Passenger ready for production. By default the script will install Ruby, Rubygems, Rails, Sqlite and a Sample app. But by using the advanced option, the script will also install apache and phusion passenger with directions to deploy the Sample app on passenger.

Usage:
Step 1. Download the script

wget http://whisperservers.com/speedtrain

Step 2. Make the script executable

chmod +x speedtrain

Step 3. Option 1
For a basic rails setup for development, which install Rails (Ruby,Rubygems) and Sqlite. simply run the script

./speedtrain

Option 2. For a production type Rails setup, which install Rails (Ruby,Rubygems), Sqlite, Apache and Phusion Passenger run the script with a -p switch.

./speedtrain -p

After the installation the script will create a folder in your $HOME directory called rails_apps. This is the folder where you can create and store your rails apps. The folder is at $HOME/rails_apps. The script will also create a sample Rails app at $HOME/rails_apps/test_app. You can run the sample app by typing

cd $HOME/rails_apps/testapp
ruby script/server

Then open your browser and type http://localhost:3000/

If you used the option to install Apache and Passenger, you will be guided interactively through the Apache + Passenger installation. After the installation, follow the simple steps displayed on the screen to deploy Rails apps on passenger. Very easy steps:)

This script is ready to run on most Ubuntu 10.04 installations. Works great and easy on ubuntu as host OS on a machine. Using virtual box Apache gets some permission issues but should be easy to fix if one digs deeper. It works perfectly on Amazon EC2 Ubuntu 10.04 instances.

To install Rails with Passenger on an EC2 instance with this script you can use this Ubuntu AMI image# ami-2d4aa444 or choose one from here

Using these AMIs the username is literally “ubuntu” as in
ssh -i yourkeyname.pem ubuntu@ec2-123-45-67-89.compute-1.amazonaws.com. I found this in the comments after some digging.

Have fun.

The source code for the new speedtrain script.

#!/bin/bash
#:Title   :Speedtrain on Rails
#:Date    :
#:Author  :Obi Akubue
#:Version :0.1
#:Description: This script installs Ruby on Rails on Ubuntu 10.04 with the option to install Apache and Phusion Passenger. (It creates a test rails app)
 
#Usage Option 1: To Install Rails (Ruby + Rubygems) + sqlite. Simply run the script by typing ./speedtrain
#Usage Option 2: To Install Rails (Ruby + Rubygems) + Sqlite + Apache + Passenger. Run script by typing ./speedtrain -p
 
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m' #light blue
cyan='\e[0;36m'
CYAN='\e[1;36m'
GREEN='\e[1;32m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color
 
#begining  messages
 if [ "$1" = "-p" ]; then
    #option to install Apache + Passenger
        echo  -e "${GREEN} Welcome to Speedtrain on Rails"
        echo " Installing Rails (Ruby + Rubygems) + Apache + sqlite + passenger ..."
        echo " This will take a few minutes to complete.."
        echo -e "${WHITE} Press ENTER to continue or Ctrl-C to Quit"
 
        echo -e "${NC}"
 
    else
        echo  -e "${GREEN} Welcome to Speedtrain on Rails"
        echo " Installing Rails..."
        echo " This will take a few minutes to complete.."
        echo -e "${WHITE} Press ENTER to continue or Ctrl-C to Quit"
        echo -e "${NC}"
   fi
 
 read key
 
echo -e "${RED} updating system..."
echo -e "${CYAN}"
sudo aptitude update
 
echo -e "${RED} Installing build essential..."
echo -e "${CYAN}"
sudo apt-get install build-essential
 
echo -e "${RED} installing ruby..."
echo -e "${GREEN}"
sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev
 
echo -e "${RED} installing rubygems..."
echo -e "${CYAN}"
cd /usr/local/src
sudo wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz
sudo tar xzvf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ruby setup.rb
 
echo -e "${RED} updating rubygems..."
echo -e "${GREEN}"
sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
sudo gem update --system
 
echo -e "${RED} installing rails..."
echo -e "${CYAN}"
sudo gem install rails
 
echo -e "${RED} installing sqlite..."
echo -e "${GREEN}"
sudo apt-get install libsqlite3-dev sqlite3 sqlite3-doc
sudo gem install sqlite3-ruby
 
echo -e "${RED} creating dev directory..."
echo -e "${CYAN}"
mkdir ~/rails_apps/
 
cd ~/rails_apps/
echo -e "${RED} creating dev test app..."
echo -e "${GREEN}"
rails testapp
 
if [ "$1" = "-p" ]; then
#if the passenger switch is set
echo -e "${RED} installing Apache..."
echo -e "${CYAN}"
sudo apt-get install apache2
 
echo -e "${RED} installing passenger..."
echo -e "${GREEN}"
sudo gem install passenger
 
#install apache development headers
#required by passenger
#Apache 2 development headers --
sudo apt-get install apache2-prefork-dev
 
#Apache portable Runime (APR) development headers --
sudo apt-get install libapr1-dev
#install passenger
sudo passenger-install-apache2-module
fi
 
#ending message
if [ "$1" = "-p" ]; then
#if the passenger switch is set
echo -e "${YELLOW}"
printf "Your Apache Configuration file is /etc/apache2/httpd.conf\n"
echo -e "${NC}"
fi
 
echo -e "${CYAN}"
echo "Rails has been successfully installed"
echo -e "${GREEN}"
echo "Your Apps directory is $HOME/rails_apps"
echo "We created a Test Rails App for you at $HOME/rails_apps/testapp/"
echo "To run the Test App type"
echo -e "${YELLOW} cd $HOME/rails_apps/testapp"
echo " ruby script/server"
echo -e "${NC}"
 
if [ "$1" = "-p" ]; then
#if the passenger switch is set
echo -e "${GREEN}"
echo "To deploy the Test Rails app on passenger "
echo "Edit the Apache Configuration file and add the following virtualhost"
echo -e "${YELLOW}\n"
 
echo ""
echo "  ServerName www.yourhost.com"
echo "  DocumentRoot $HOME/rails_apps/testapp/public"
echo " "
echo "     AllowOverride all"
echo "     Options -MultiViews"
echo " "
echo ""
echo -e "${NC}"
echo -e "${GREEN}"
echo "then Restart Apache: sudo /etc/init.d/apache2 restart"
echo "and Open on your browser: http://yourdormain.com or http://your-ip.com"
echo -e "${NC}"
fi
 
 

Installing Ruby on Rails on Ubuntu 10.04 with speedtrain

31 Jul

[Update 3/7/2011] Check the updated version of the speedtrain script for Ruby 1.9.2 and Rails 3 here:http://obi-akubue.org/?p=922 and https://github.com/obi-a/speedtrain.

I wrote a small user friendly script that installs Ruby on Rails on Ubuntu 10.04. This script installs Ruby,Rubygems, Rails and sqlite. It also creates a sample Rails App.

Usage:

To install Ruby on Rails on Ubuntu 10.04 with this script, using command line.

Step 1: Download the script.

wget http://whisperservers.com/speedtrain

The script is called speedtrain.

Step 2. Make the script executable

chmod +x speedtrain

Step 3. Run the script

./speedtrain

The script will install Ruby,RubyGems, Rails and sqlite. It will then create a folder in your $HOME directory (~/rails_app/) called rails_apps. This is the folder where you store the rails apps you create. The script will also create a sample Rails App. The sample app is located at ~/rails_app/testapp.

To run the sample Rails app. Type…
cd ~/rails_apps/testapp
ruby script/server

Open the browser and type http://localhost:3000/

Source code for the speedtrain shell script.

#!/bin/bash
#:Title   :Speedtrain on Rails
#:Date    :
#:Author  :Obi Akubue
#:Version :0.0
#:Description: This script installs Ruby on Rails on Ubuntu 10.04. (It installs ruby,rubygems,rails,sqlite and creates a test rails app)
 #Notable credits: http://ascarter.net/2010/05/10/rails-development-on-ubuntu-10.04.html (helped me resolve conflicts with rubygems and debian package manager)
 
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m' #light blue
cyan='\e[0;36m'
CYAN='\e[1;36m'
GREEN='\e[1;32m'
NC='\e[0m' # No Color
 
echo  -e "${GREEN} Welcome to Speedtrain on Rails"
echo "Installing Rails..."
echo "This will take a few minutes to complete.."
 
echo -e "${RED} updating system..."
echo -e "${CYAN}"
sudo aptitude update
 
echo -e "${RED} installing ruby..."
echo -e "${GREEN}"
sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev
 
echo -e "${RED} installing rubygems..."
echo -e "${CYAN}"
cd /usr/local/src
sudo wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz
sudo tar xzvf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ruby setup.rb
 
echo -e "${RED} updating rubygems..."
echo -e "${GREEN}"
sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
sudo gem update --system
 
echo -e "${RED} installing rails..."
echo -e "${CYAN}"
sudo gem install rails
 
echo -e "${RED} installing sqlite..."
echo -e "${GREEN}"
sudo apt-get install libsqlite3-dev sqlite3 sqlite3-doc
sudo gem install sqlite3-ruby
 
echo -e "${RED} creating dev directory..."
echo -e "${CYAN}"
mkdir ~/rails_apps/
 
cd ~/rails_apps/
echo -e "${RED} creating dev test app..."
echo -e "${GREEN}"
rails testapp
 
echo -e "${GREEN}"
echo "Rails has been successfully installed"
printf "We created a test Rails App for you at ~/rails_apps/testapp/\n"
printf "To run the test App type\n"
echo -e "${CYAN} cd ~/rails_apps/testapp\n"
echo "ruby script/server"
echo -e "${NC}"
 
 
 
Premium Wordpress Plugin