728x90 AdSpace

  • Latest News

    Thursday, July 25, 2013

    How to install ruby on rails 3

    How to install Ruby on Rails 3.2 with MySQL on Debian/Ubuntu
    This is the way I managed to install Ruby on rails 3.2 with MySQL on Debian/Ubuntu.

    Other articles you may be interested in:
    ROR with SQLite3 for Ubuntu 11 .10 (the easiest way to install and use ror)
    ROR with SQLite3 for Fedora 15

    Pay attention: if you had already installed Ruby on rails with SQLite3 and you just want to add mysql database you can skip some steps, but make sure to install the required libraries.

    1. INSTALL THE NEEDED LIBRARIES

    Type the following command in the console:

    sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev

    2. DOWNLOAD AND INSTALL RUBY 1.9.3

    Download the last version Ruby 1.9.3 in the "Compiling Ruby" section of the web page
    Unzip the archive
    Install running:
    $ ./configure
    $ make
    take a coffee
    $ sudo make install

    Check the successful installation running ruby -v: it should answer with "ruby 1.9.3p..."

    3. DOWNLOAD RUBY GEM: THE STANDARD RUBY PACKAGE MANAGER

    Download ruby gem version 1.8.25 (rubygems-1.8.25.tgz)
    Unzip the archive somewhere
    Put the console in the unzipped folder
    Install running: $ sudo ruby setup.rb
    Check the successful installation running gem -v: it should reply "1.8.25"

    4. INSTALL RAILS

    Install Rails running on the console: $ sudo gem install rails
    (it takes a while, don't worry)
    Check if everything is ok using the commands "rails -v" (you should get "rails 3.2.XX") or "gem list"

    5. INSTALL MYSQL

    Install running on the console: $ sudo apt-get install mysql-client-5.5 mysql-server-5.5
    During the installer it asks for a mysql root-user password (type for ex. admin)
    Try to start and stop the mysql server using the commands:

    $ sudo service mysql stop
    $ sudo service mysql start

    6. INSTALL MYSQL GEM

    In order to install the mysql gem you could use:
    $ sudo gem install mysql2
    $ sudo gem install therubyracer

    7. CREATE A NEW RAILS PROJECT

    $ rails new yourappname -d=mysql
    When you see run bundle install wait some seconds.
    Put the console in myapp folder

    It could be useful also to run:
    $ sudo bundle install

    because maybe the project requires other gems (in my case it installed a new version of rake gem)

    8. DATABASE SETTINGS ON THE NEW RAILS APPLICATION

    Open the file myapp/config/database.yml and put your
    mysql root-user password
    for the test and development database
    You must leave a blank character after the 'password' keybord. So you should get something like this:

    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: myapp_development
    pool: 5
    username: root
    password: your-password
    socket: /var/run/mysqld/mysqld.sock

    9. CREATE THE BLANK DATABASE

    Start the mysql database using: sudo service mysql start
    Put the console in myapp folder and run: $ rake db:create
    Check the step 12 if you get an error here.

    in order to create the databases myapp_test and myapp_development.
    If creates the db is correctly creates, it replies with anything...

    It could be useful to check if the db is created or not: do like this:

    $ mysql -u root -p // open mysql console
    $ Enter password: type-your-password
    mysql> show databases;

    and you should find the myapp_test and myapp_development db.
    mysql> \q // close mysql console

    10. RUN YOUR RAILS APP

    Put the console in myapp folder and run $ rails server
    Open the browser
    http://localhost:3000
    and you should see the Ruby on Rails: welcome page;-)

    I suggest you to continue the ROR learning on the official documentation, in particular on the getting started page.

    11. SOME USEFUL MYSQL COMMANDS

    $ mysql -u root -p // open mysql console
    mysql> show databases; //show all the databases
    mysql> use database-name; //select a database
    mysql> show tables; //show the tables of the selected db
    mysql> describe table-name; //show the attributes of the selected table
    If you need to change the mysql root password type this command:
    $ mysqladmin -u root -p password enter-your-new-password
    Enter password: enter-your-old-password

    12. !! COMMON ISSUES THAT MIGHT OCCUR !!

    Running rake db:create or rake db:migrate you could get the error: Could not find a JavaScript runtime.
    put in the first line of your Rakefile: gem 'therubyracer'
    run sudo bundle install
    Running rake db:create or rake db:migrate you could get the error: uninitialized constant Rake::DSL. The solution is to put in the first line of your Rakefile: require 'rake/dsl_definition'

    In the browser at localhost:3000 you could get the error: "no such file to load -- openssl". The solution is to go through the installation directory of ruby: ruby-1.9.2-p180/ext/openssl and run:

    ruby extconf.rb

    make
    sudo make install

     

     

    Also read:
    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Item Reviewed: How to install ruby on rails 3 Rating: 5 Reviewed By: Mark John Dee
    Scroll to Top