How To Setup Rails with rbenv in Ubuntu 14.04

Introduction

Ruby on Rails is open source framework that run with Ruby programming language. It will be modern framework in the future. Why? Because we just generate the code and let the framework finish your job. Easy right?We can add another API by using gemfile installation. It’s included Bootstrap framework or something like SASS or LESS to styling your site more beautiful. So, let’s get started by using install rails in ubuntu 14.04

Install rbenv

First thing we want to do is installing rbenv by using this command below.

First, command update:

$ sudo apt-get update

Then, install rbenv and Ruby dependencies using this command:

$ sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

So, we will install rbenv now:

$ cd
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
$ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
$ echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc
$ exec $SHELL

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bashrc
$ exec $SHELL

$ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

It will installs rbenv into your home directory and you can install another ruby & rails version. So let’s install Ruby language now.

Install Ruby

Before install ruby, you can see what the version of ruby you want to use in your rbenv. You can go to this page to find ruby version that you want to use. Put this code into your command line:

$ rbenv install -v 2.2.3
$ rbenv global 2.2.3

The “global” command is mean you make ruby version 2.2.3 as default of your ruby version. With “rbenv install xxx” you can install another version with that command line.

Verify your ruby has been installed by copy this command:

$ ruby -v

This is if you won’t Rubygems to generate local documentation when you install new gemfile. Copy this:

$ echo “gem: –no-document” > ~/.gemrc

You will also copy this command to install bundler for dependencies your applications:

$ gem install bundler

Everything looks good, let’s install rails right now.

Install Javascript Runtime

This is not java installation, this is javascript runtime. It’s different with java, java is language programming to make some OS application. But, in here we will install node.js as javascript runtime, let’s take a deep:

$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash –
$ sudo apt-get install -y nodejs

Install Rails

Just using this command to install rails or if you want to use specific rails by add “-v” in the end line:

$ gem install rails -v 4.2.4

Ok, so now copy this command line to install shims for all ruby executable known to rbenv, which will enable you to use executables:

$ rbenv rehash

Then, verify your rails installation by using this command:

$ rails -v

Until here, we’re finished install Ruby on Rails, but we still have another optional steps. Let’s take a deep.

Configure git

Well, you must install git as your version control when you want to develop some application as controlling your version by git. Let’s config our git now.

Add this command to your command line:

$ git config –global color.ui true
$ git config –global user.name “YOUR NAME”
$ git config –global user.email “YOUR@EMAIL.com”
$ ssh-keygen -t rsa -C “YOUR@EMAIL.com”

Install Database

In the fact rails using sqlite3 to store database on development. But, you can also install another database for production in this step. You can using MySQL or PostgreSQL as your database.

Setting Up MySQL

Just copy and paste this code into your terminal:

$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev

if you are finished with installing database you choose you can skip this installation.

Setting Up PostgreSQL

We will install the latest version of PostgreSQL which is 9.3 by doing this command:

$ sudo sh -c “echo ‘deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main’ > /etc/apt/sources.list.d/pgdg.list”
$ wget –quiet -O – http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add –
$ sudo apt-get update
$ sudo apt-get install postgresql-common
$ sudo apt-get install postgresql-9.3 libpq-dev

Then, you must setup user for PostgreSQL because they not automatically setup the user. Let’s do this by doing this command:

$ sudo -u postgres createuser chris -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris

Final Steps

Last thing you must to do is create your test application by doing this in your command line:

#### If you want to use SQLite (not recommended)
rails new myapp

#### If you want to use MySQL
rails new myapp -d mysql

#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql

# Move into the application directory
cd myapp

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

You can visit ‘localhost:3000’ to see your rails application runs good. Everything is clear now and enjoy make the application.

Advertisements

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