Friday, May 11, 2012

Installing Ruby on Rails on Ubuntu

So finally, after having waited in my to-do list for reasonably long time, Ruby and Rails is installed on my Ubuntu 12.04 (the proven, practical and precise OS). Yes, I did a fresh install of Ubuntu 12 after the upgrade from Ubuntu 11 rendered the OS respond slow (Ubuntu team, are you reading this?). But, I am more excited about Ruby on Rails. If you haven't heard of it yet, you need to catch up. Visit its homepage here.

This post is going to talk about installing Ruby on Rails (I will call it Rails henceforth going by the common term) which can be a real pain at times. And sadly, there are not many good documentation out there on it.

During my writing of this blog, the current versions I used are Ruby 1.9.3 and Rails 3.2.3. This post shows how to install Ruby, Rails and finally the Bundler using RVM (Ruby Version Manager). However, there is a simple way to install the entire package called the Railsready script that installs all the required packages at one go, and is quite simple. I wanted to get into the nitty-gritties! ;)

You need to do some checks first:
  1. You need to make sure you have sudo access to the system.
  2. We will not be using apt-get for the installations. Its outdated and can be quite problematic when installing Rails. Instead, we will use aptitude.
Step 1: Check if aptitude is installed in your system
Type the following command in the terminal.
$ sudo aptitude
in the terminal, and it should open the a visual interface. If you get errors, you have to install aptitude by executing the following commans.
$ sudo apt-get update
$ sudo apt-get upgrade
4 sudo apt-get install aptitude

Step 2: Update the libraries
You should update the libraries to make sure you have all the latest ones. This can save you from quite some trouble due to missing libraries during installation.
$ sudo aptitude update
$ sudo aptitude upgrade
Upgrade will take quite some time. Grab a coffee!

Step 3: Install Git and Curl
Since we will be using RVM (Ruby Version Manager), we need to install Git and Curl, if we do not already have them. Git is the source control repository (as you might know by the GitHub fame) nd Curl is a command line tool to get data from a URL.
$ sudo aptitude install build-essential git-core curl

Step 4: Install Ruby Version Manager
Ruby Version Manager (RVM) is very helpful to manage different versions of Ruby on a system. Using RVM is highly recommended (by me!).

To geth the RVM files to our system, we execute the following command at the bash shell.
$ bash < <(curl -s
Instead of the above command, you can also type:
$ curl -L  | bash -s stable

Step 5: Make RVM load with terminal
To make RVM load itself everytime we open the terminal, we need to edit the bash config file.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Now, close and open the terminal again. Or you can get the same effect by this command:
. ~/.bashrc
To check RVM is installed and to read the notes, you can execute:
$ rvm notes

Step 6: Install packages required for Ruby
After RVM is installed, its time to install Ruby. But you need to make sure we have all the packages that are required by Ruby (it's better to install all these packages now and avoid a headache later on!).

To check what the requirements are, you can execute:
$ rvm requirements
There should be quite some packages enlisted. Some of them, if they are already installed, like git and curl, will not be installed again.

To install the packages, execute:
$ sudo aptitude install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison

Step 7: Install Ruby (1.9.3 in this case)
With all preparations done now, we can go ahead to install Ruby. I used version 1.9.3.
$ rvm install 1.9.3
This should install Ruby just fine. If you have multiple versions of Ruby on your machine, you can make use this version by:
$ rvm use 1.9.3
, or even better, make this version as default:
$ rvm --default use 1.9.3
Check which version of Ruby you are using by,
$ rvm -v

Step 8: Install Rails
Time to install Rails now. This is the main application framework, one that changed the world to an extent! ;)

To install rails, we will use gems, the standard package manager for Ruby. You do not need to use sudo for installing gems.
$ gem install rails -v 3.2.3
Check the version of rails that was just installed.
$ rails -v
Congratulations, your installation is done. You can try out now creating a new Rails project.

Step 9: Create a new Rails project
Lets create a new Rails project. My site is called "hellosite".
$ rails new hellosite
This should start the bundler, that is responsible for managing application's dependencies. In case, the bundler doesn't start, you can go to the directory of the project (in our case "hellosite") and run the bundler.
$ cd hellosite

$bundle install
Go to the project's directory and you should see the project created with all different folders e.g. models and controllers and views....we will talk about them in some other post! ;)

Step 10: Start the Rails server
$ rails server
This command will start the default Rails server called WEBrick.

In case, you get an error like "ExecJS::RuntimeUnavailable", you need to get some packages installed:
$ gem 'execjs'

$ gem 'therubyracer'
Then go to the project directory and run the bundler again.
$ bundle install
and then start the Rails server using,
$rails server
The WEBrick server runs on port 3000 by default. Once the server is started, you can open your favorite browser, type "http://localhost:3000" and your site should open. There you go, you first Rails project is online! ;)

Eh, btw, the server is still running. To stop the server, press Ctrl+C! ;)

I will follow with more posts on this. But an important disclaimer before I close, trying out these commands on your machine should be done at your risk and do not hold me responsible if anything goes wrong. I had these two handly references that made my task easy, and these references have more comprehensive info. You can also refer to Ryan Bigg's installation guide or get the pdf from Mircea Goia's post for more.

Monday, March 5, 2012

Install Windows 8 Consumer Preview on Oracle VirtualBox

With Microsoft releasing Windows 8 Consumer Preview at MWC in Barcelona a few days back, I could not wait to give it a try. And as you might have expected, my best bet is to get it installed on Oracle VM VirtualBox. So, lets get started.

If you do not have the VirtualBox installed, you can get it from here. I have Oracle VM VirtualBox version 4.1.8 on my machine. Next, I have downloaded the consumer preview of Windows 8 from here, and you should choose the one that suits your machine. I got the 32 bit one. Now, we are ready to go.

Creating a new virtual machine
The first step is to create a new virtual machine for Windows 8. Click on the obvious New button and the wizard starts.

Follow the wizard, where you need to specify a name for the virtual machine and allocate the memory size (minimum 1 GB suggested). Then it asks for creating the virtual hard disk. Choose "create new hard disk". In the following screen choose the file extension as VHD.

You can either choose the memory to be dynamically allocated or keep it fixed size and then choose the recommended disk space. Keeping the default option of 20 GB is fine, if you have that much to spare. The wizard should then create the virtual machine.

Note: After the machine is created, you have to go to Settings > System > Processor and check the option "Enable PAE/NX". Skipping this step might result in error "Your PC needs to be repaired" when installing the OS.

Installing Windows 8 Consumer Preview

Now, we can start with the installation of Windows 8 using the .iso file we downloaded form the link above. Start the Windows 8 virtual machine and it displays the First Run wizard.Specify the path of the .iso as installation media and let the installation begin. The rest of the installation is pretty straight forward, if you have installed Windows before.

The product key for the installation can be found at the same link mentioned above from where the .iso file was downloaded (DNJXJ-7XBW8-2378T-X22TX-BKG7J).

Because it is just a preview, you have limited options to play around with. When the installation asks for it, don't forget to create a Microsoft account. You will need it to access multiple features later on. When the installation is done, you are greeted by the new start screen.

Lot of things have changed, and I have to get into a habit with this OS. But there are two obvious things that I can already share: Windows 8 clearly looks like an OS targeted primarily for tablets and touchscreens, and the preview is not clean and the finishing touch are missing (well, that's why it's a preview).

Now off to play around with it, and wait for another post I would write if this preview really falls worth of it. So, before signing off, a quick tip: you can click the Windows logo button to get the start screen back at any point of time!