Ruby on Rails Centos 6.x beginners installation guide!

Ruby on Rails Centos Installation Guide!

For my ruby on rails centos server, I installed a fresh Centos 6.3 minimal.

Ruby on Rails Centos

Installation

 

Install Ruby

1
2
3
yum install ruby
 
yum install ruby-devel ruby-irb ruby-rdoc ruby-ri
yum install ruby

yum install ruby-devel ruby-irb ruby-rdoc ruby-ri

 

Option 1: Install Rubygems using yum

this is the easy way. install from source if you have problems or you need the more recent rubygems version.

1
yum install rubygems
yum install rubygems

 

Option 2: Install Rubygems from sources

access the latest available gems by visiting: http://rubygems.org/pages/download.

remember to ‘yum remove rubygems’ if you’ve installed rubygems earlier using yum.

1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir ~/src
 
cd ~/src
 
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
 
tar xzvf rubygems-1.8.24.tgz
 
rm rubygems-1.8.24.tgz -f
 
cd rubygems-1.8.24
 
ruby setup.rb
mkdir ~/src

cd ~/src

wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz

tar xzvf rubygems-1.8.24.tgz

rm rubygems-1.8.24.tgz -f

cd rubygems-1.8.24

ruby setup.rb

 

Update Rubygems

1
2
3
gem update
 
gem update --system
gem update

gem update --system

make sure you have gcc and make installed. it’s used by gem and needed to install gems like sqlite3-ruby

1
yum install gcc gcc-c++ make -y
yum install gcc gcc-c++ make -y

 

Install Rails

1
gem install rails -V
gem install rails -V

-V for details of the process

verify with

1
rails --version
rails --version

 

ERROR: Error installing rails:
activesupport requires Ruby version >= 1.X.X.

If you get this error while installing rails you need to

yum remove ruby

and then install it from source (check if newer versino exist):

cd /opt
yum groupinstall “development tools”
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz
tar -zxvf  ruby-2.1.0.tar.gz
cd ruby-2.1.0.tar.gz
./configure
make
make install

# and then some cleaning…
cd ..
rm ruby-2.1.0.tar.gz

You can also use easier methods like rbenv or RVM.

It will install rubygems too for you.

then try to install rails again.

 

That’s it!

you have ruby on rails (rails) installed!

you have gem package manager installed. you can view installed packages with:

1
gem list
gem list

 

What’s now?

 

Sqlite

You will probably need an sql. Rails version 2.0+ uses sqlite3 as its default database – you can, of course, use others

1
yum install sqlite-devel
yum install sqlite-devel

After you have sqlite installed, install the gem with:

1
gem install sqlite3-ruby
gem install sqlite3-ruby

 

Testing

to test you have installed everything as needed do the following test using irb:

1
2
3
4
5
6
7
8
9
irb
 
#irb(main):001:0> require 'rubygems'
 
=> true
 
#irb(main):002:0> require 'sqlite3'
 
=> true
irb

#irb(main):001:0> require 'rubygems'

=> true

#irb(main):002:0> require 'sqlite3'

=> true

 

Creating your First Project

Using an SQLite3 database for data storage is a zero configuration database that just works. ‘db::rake’ will create the database.

1
2
3
4
5
6
7
cd ~/
 
rails new project
 
cd project
 
rake db:create
cd ~/

rails new project

cd project

rake db:create

 

Javascript runtime

rails default project template uses CoffeeScript. Compiling CoffeeScript to JavaScript requires a JavaScript runtime. without it running the server will return an execjs error.

 

Install TheRubyRacer

1
gem install therubyracer
gem install therubyracer

Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it.

therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby.

also, from rails 3 you can use node.js for compiling the coffeescript.

edit the ‘Gemfile‘ file inside your new project directory and uncomment (delete the #) from the line 

# gem ‘therubyracer’ ….

to

gem ‘therubyracer’ ….

save.. and your project should now work.

 

Start Server

1
2
3
bundle install
 
rails server
bundle install

rails server

Installing Ruby on Rails on Centos 6.3 is Easy!

if everything correct, This will fire up WEBrick web-server (Rails can also use several other web servers like apache or nginx). To see your application in action, open a browser window and navigate to http://localhost:3000. You should see Rails default page.

 

 

Read more…

read the full ruby on rails guide: Getting Started with Rails. you have everything installed and ready for this guide 🙂

 

read more on web-servers in iTekBlog:

1 thought on “Ruby on Rails Centos 6.x beginners installation guide!

  1. jj

    This is a no go.
    On most unix distros this way of installing ruby will completely make your ruby installation outdated and not useful at all for any serious development.

    If you only plan to play a bit with some ruby code it might be ok, but if you already know that you are going to dive into rails or some other cool ruby stuff then you need to install ruby with RVM (Ruby Version Manager)
    Official page & install instructions here: https://rvm.io/rvm/install/
    A nice and light tutorial here http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
    The second one also better explains why using apt-get or yum will make your ruby outdated and kind of broken (you will not be able to use some gems, get latest rails, and so on…)

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.