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

[code lang=”bash”]

yum install ruby

yum install ruby-devel ruby-irb ruby-rdoc ruby-ri[/code]

 

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.

[code lang=”bash”]yum install rubygems[/code]

 

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.

[code lang=”bash”]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[/code]

 

Update Rubygems

[code lang=”bash”]gem update

gem update –system[/code]

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

[code lang=”bash”]yum install gcc gcc-c++ make -y[/code]

 

Install Rails

[code lang=”bash”]gem install rails -V[/code]

-V for details of the process

verify with

[code lang=”bash”]rails –version[/code]

 

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:

[code lang=”bash”]gem list[/code]

 

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

[code lang=”bash”]yum install sqlite-devel[/code]

After you have sqlite installed, install the gem with:

[code lang=”bash”]gem install sqlite3-ruby[/code]

 

Testing

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

[code lang=”bash”]irb

#irb(main):001:0> require ‘rubygems’

=> true

#irb(main):002:0> require ‘sqlite3’

=> true[/code]

 

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.

[code lang=”bash”]cd ~/

rails new project

cd project

rake db:create[/code]

 

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

[code lang=”bash”]gem install therubyracer[/code]

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

[code lang=”bash”]bundle install

rails server[/code]

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.

*

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