Tag Archives: ruby

Set up ruby-on-rails

How to install Ruby on Rails in Ubuntu 12.04 LTS

Ubuntu 12.04 LTS (Long Term Support) – Precise Pangolin has already released, and you might have upgraded from 11.10 or installed Ubuntu 12.04 LTS. In this post you will learn how to setup Ruby on Rails on a newly installed Ubuntu 12.04 LTS.

Ruby on Rails is a very popular web development framework, it is based on the principle of  “Convention over Configuration”. Although, application development using Rails is quite easy and fun but setting up rails development environment may be difficult and frustrating, specifically for beginners. I had already written a post about setting up rails on Ubuntu 11.10  but few things has changed and need to be updated for the new version of Rails, Ruby and Ubuntu.

“Hassle Free” Rails Installer for Ubuntu 12.04

Although I’ve explained the installation steps in detail but if already know how these things work then better save time by running the script – that will install Ruby on Rails on Ubuntu 12.04 along with the dependencies and RVM.

Download the Rails Installer Script (From Github)

First change some settings in Gnome Terminal. Go to Edit -> Profile Preferences -> Title and Command and check the “Run Command as login shell”  box.

Login Shell - Terminal

Then make the script executable and execute it (you may have to enter the login password once) –

sudo chmod +x rails-installer.sh

If anything goes wrong then let me know through comments.

Step by Step Instruction for Setting Up Rails on Ubuntu 12.04 LTS

Just follow these simple steps and withing a couple of minutes you would be creating some nice applications (and of course using Rails).

step 1.  Install git and cURL

First of all, update your package repository.

sudo apt-get update

git is a simple, fast and efficient version control system. It is easy to learn, so even if you don’t have any experience with git you can try it in your next rails project (or any other project). you will love it.

sudo apt-get install git

Curl is a simple command line utility for getting file over web protocols, based on libcurl. To install curl simply execute –

sudo apt-get install curl

step 2. Install RVM and Dependencies

RVM is not strictly required but it makes ruby management a lot easier. You can try different implementations of ruby, different versions of ruby and all without any pain. So it’s strongly recommended. but RVM requires the command to be executed as login shell, so open a terminal and go to Edit -> Profile Preferences -> Title and Command and check the box that says “Run Command as a login shell“. (look at the above snapshot)

curl -L get.rvm.io | bash -s stable

Now, you must load the RVM

source ~/.rvm/scripts/rvm

Then install additional dependencies specified by the RVM –

rvm requirements

sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Installing Javascript Runtime
In newer version of Rails, you also need a Javascript runtime. Although you could install it from the package repository but it’s very outdated. So I recommend installing it using the PPA. (and I’ll also update the script)

sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

step 3. Install Ruby

Now, you got RVM running, installing and running multiple versions or just one version of Ruby is very simple. To install Ruby just pass the version number to rvm install command (or some other implementation of ruby if you want; RVM also supports rbx, ree, JRuby, IRonRuby other than the default MRI) –

rvm install 1.9.3

Then select the Ruby version you want to use, (or make it default so that you don’t have to select it again in new session)

rvm use 1.9.3 --default

Now, you can check the version of ruby, you’re running right now-

ruby -v

step 4. Install Rails

RVM installs ruby as well as the gem utility (managing ruby libraries). To install rails, simply install it using the gem. It will automatically install the latest version unless you specify the version explicitly.

gem install rails

Now You’re ready to go.

rails new app_name
cd app_name
rails server

Now, open a browser and go to http://localhost:3000. 🙂

Voila 🙂

You should also check out this Ruby on Rails Interactive Video Course on Treehouse.

Note : When your Rails Application is ready, you may want to deploy it to a real server, I recommend Digital Ocean (@$5/mo, you get 512 MB RAM, 20 GB SSD and 1TB Bandwidth, cool, isn’t it.) for that, also checkout the Digital Ocean review if you want to know more about them. If you need any help then read this article about Deploying Rails Application to VPS.

Update 1 : Added a video as a reference for Rails Installer Script.

Update 2 : checkout my new rails application: Railyo – Rails freelancing jobs for cool developers!

Ruby 2.0 is out!

mruby – Lightweight Ruby

What is mruby ?

mruby is a light weight implementation of the Ruby programming language.

So if you use ruby then mruby might be useful for you – because it can run ruby program in interpreter form or compile and execute in vm form, probably in less amount of time (faster execution) with less amount of resources (that’s what the light weight indicates) as compared to the standard Ruby (MRI).

Ruby is already popular in web application development (Ruby on Rails framework) but the lightweight and efficient version of ruby would probably explore new domains for ruby – e.g mobile platform (Actually, it has started – checkout the bottom notes), embedded devices etc.ruby-logo


Download mruby

There isn’t any official version of mruby available right now but you can checkout the github page for downloading the initial release.

mruby at github

Notes : Now, Ruby is one of the most popular programming languages, within a few months you might be able to write mobile apps for Android and iPhone, in ruby using mobiruby (built on the top of mruby).

Fecon getting award from Stallman

Free Software Awards for 2011

The Advancement of Free Software Award => Matz (Creator of Ruby)

The advancement of Free Software Award is given(once in a year) to someone who made a great contribution to the progress and development of Free Software. This year, the award has been given to Yukihiro Matsumoto (Matz), the creator of Ruby programming language.

Matz getting Free Software Award
Matz and Stallman

Matz got the award for the advancement of Free Software (by Richard Stallman (aka RMS, St. iGNUcius), founder of FSF) for his contribution to various GNU projects, Ruby (one of the coolest programming language (an scripting language like python), recently it has become much popular in web development due to Ruby on Rails framework) and other free softwares projects.

Know More about

The award for Project of social benefits => Luis for GNU Health

The award for project of social benefits is give to a project or team or the ideas of the free software movements which intentionally or significantly benefits human society in other aspects of life.

Fecon getting award from Stallman
Felcon and Stallman

This year, the award goes to GNU Health, a free software projects that works with health professionals around the world to improve the underprivileged. The president of GNU Solidario (the organization behind the GNU Health project) => Luis Falcon got the award by Richard Stallman for his great contribution to the society (through the free software project).

source : official announcement of 2011 Free Software Awards


gedit plugins for Ruby on Rails

gedit is the default and one of the most popular text/code editor in GNOME based distro such as Ubuntu, Debian, Fedora, Linux Mint etc. It has a lot of cool plugins to add some extra features, some are installed by default while some are available there in package repository, to activate just go to the preferences section and enable it; You don’t even need to restart the gedit application.

gedit is a simple, efficient, easy to use and powerful text editor, it has lot of advanced features that makes it really good for programming (if you’re more hungry for features, then you should try Emacs, although Emacs is little hard to learn but the extra productivity you will gain is incomparable, good for long run). But these features are not enough for a rails developers, so there is a PPA dedicated for rails developers (although it’s for Ubuntu but works well with any debian based distro).

Gedit with GMate Plugin : on Ubuntu 12.04

GMate – The missing Gedit Plugins for Rails Developers

GMate is a set of cool plugins that will add some nice features to gedit text editor – in order to increase the fun with Rails Development (e.g by default gedit can’t highlight the ruby code in .erb.html files but gmate will do it for you!). Since gmate is a PPA for Ubuntu 11.10/12.04/older_versions so it will not work only on Ubuntu but also on other Debian derivatives. If you’re using Fedora or Archlinux then it won’t work, you may have to install it individually, see top 10 gedit plugins for the list of cool plugins.

Install GMate in Ubuntu

sudo apt-add-repository ppa:ubuntu-on-rails/ppa
sudo apt-get update
sudo apt-get install gedit-gmate

You can enable/disable the plugins from Edit -> Preferences -> Plugins.

Recommended Reading(s)

Gedit Shortcuts – Gedit Cheat Sheet for beginner developers, it also contains Gmate shortcuts!

Learning Rails ?

Check out this interactive video course on Ruby on Rails at Treehouse.

ruby program using nano

Ruby Programming with Ubuntu 11.10

Ruby is one of the most popular scripting language. Ruby is an object oriented programming language, it’s open source, dynamic and cross-platform; it is well known for human friendly code. it has gained a lot of popularity (in past few years) in web world, probably due to the web application development framework – Ruby On Rails, that allow developers to build cool web applications very quickly. The same is true with Ubuntu (latest version 11.10 – Oneiric Ocelot) as it is now the most popular Linux distribution for desktop users.

Although this post isn’t going to teach Ruby but it will surely help you in getting started with Ruby, on Ubuntu 11.10 of course. Since Ruby is an interpreted language i.e source code itself is executed – line by line – by Interpreter. So first of all we need to install Ruby Interpreter.  The latest version of Ruby is 1.9.3 p0 (released on Oct 30, 2011), although 1.8.7 is also very popular as a number of applications are based on it.

If you want to quickly get started with Ruby then first install ruby 1.8.* or 1.9.* from command line or Ubuntu Software Center. Open a terminal (Ctrl+Alt+t) and execute –

sudo apt-get install ruby1.9.1

Then create a file ‘fun.rb’ and write a simple ruby program to test.

Creating a new file from terminal –

touch fun.rb

Then use a simple command line editor such as nano(or vim) or a gui gedit to put the code.

ruby program using nano

nano fun.rb
# This is a comment in Ruby!
puts "Enter something (Your Name or any number)"
some_thing = gets
puts "You said  #{some_thing}"

Then save the file (Ctrl+X => y => Enter, if you are using nano). Then you can execute the above ruby program (that simply get some input from the user and print it).


ruby fun.rb

Output :

Enter something (Your Name or any number)
just for Fun!
You said  just for Fun!

Recommended Link(s) for Learning Ruby/Ruby on Rails –

If you want to work with multiple versions of Ruby or wanna go ahead with Ruby and its libraries (called as RubyGems)or frameworks such as Ruby on Rails then you are recommended to use RVM (Ruby Version Manager) instead of installing ruby from Ubuntu Package Repository. I’ve already explained about RVM, Rails etc in detail (along with their dependencies) – install ‘Ruby on Rails’ in Ubuntu.

checkout some free Ruby tutorials!