Friday 20 May 2016

Rails on Ubuntu 16.04

Initialization



Update your system.


sudo apt get update


Install all ruby and rails related dependencies.


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


Installing ruby



There are various ways you can install ruby. We are going to install ruby with rvm. Rvm lets us manage various versions of ruby. It also provides container for various gem bundles for different applications. This is very convenient for multiple applications development.


Install rvm related dependencies.


sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev


Get latest stable rvm version.


curl -L https://get.rvm.io | bash -s stable


You may encounter an error regarding signature verification. Just follow the instructions on screen and try above command again.


Execute rvm file to load on terminal.


source ~/.rvm/scripts/rvm


Check rvm version.


rvm -v


Install ruby version.


rvm install 2.3.1


This was the latest ruby version while writing this blog. This might take some time, have a coffee or a tea if that’s your thing. :)


Check the ruby version.


ruby -v


Make installed ruby version default.


rvm use 2.3.1 --default


Configuring git



Git is a great version management for your applications. Head towards GitHub and register your account if you haven’t already.


Make color code for git information true.


git config --global color.ui true


Enter your GitHub name and email.


git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"


This is important because every Git commit uses this information, and its immutably baked into the commits you start creating.


Generate ssh key. (more information)


ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"


Just keep pressing enter and ssh key will be generated.


Display the content of generated key file with following command.


cat ~/.ssh/id_rsa.pub


Copy the content and paste it in your GitHub ssh setting.


Enter following command to verify connection.




Installing Rails



Rails requires JavaScript run-time so we will install Node.js. This lets us use CoffeScript and asset pipeline.


curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -


sudo apt-get install -y nodejs


Remember the container I talked about earlier, we will create one for rails installation.


rvm gemset create rails-4.2.6


At the time of writing this blog latest stable version of rails was 4.2.6, so we created gemset related to that.


List gemsets.


rvm gemset list


Use created gemset.


rvm gemset use rails-4.2.6


This will select rails-4.2.6 gemset. You can verify with list command.


gem install rails -v 4.2.6


This will install rails and its dependent gems. Dude that’s going to take some time play some game in your phone, also let me know if really good.


All done ! Check the version just to make sure.


rails -v


Setup MySQL



Rails by default uses SQLite database, but we will install MySQL as its more robust.


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


While installation you will be asked in enter password for MySQL root user, keep it secure one.


Creating first app



rails new myapp -d mysql

This will create rails app skeleton.


Move into application directory.


cd myapp


Change the config/database.yml to set username and password for MySQL setting.


nano config/database.yml


Create database and run application.


rake db:create


rails s


Navigate to http://localhost:3000 to check you application.


Congratulation now your Ubuntu is rocking with rails.

Conclusion


  We have come to an end of installation guide. There are many other packages and awesome gems to be installed but that depends on application requirements. Anyways this is just a beginning. Happy coding !!!



Saturday 23 April 2016

Ubuntu 16.04 LTS along with Windows

Background:


            I had Windows 10 (upgraded from 7) with Ubuntu 14.04 32-bit. I wanted to upgrade to 16.04 so started researching about it. While digging into my system I found out that I have 4 GB ram and yet I installed 32-bit version. So I decided to remove 14.04 and install 16.04 with 64-bit architecture.

Getting started:


            Download the ISO from Ubuntu site and burn it to disk or make a bootable USB flash drive. Make sure that you have proper architecture, 32-bit if you have less than 3 GB else go for 64-bit.

Partitions:


Let talk about hard disk partitions a little because it’s important for advance but rather easy installation. Each hard disk can have 4 primary partitions and that is where OS can be installed.  Now that doesn’t mean you can only install 4 OS in one hard disk. This is where extended and logical partition comes into picture.

            You can create 3 primary partitions and 1 extended partition. This extended partition can have multiple logical partitions. So you can either create 4 primary partitions or create 3 primary partitions and 1 extended partition (which is primary partition in a way) with multiple logical partitions.

            Open ‘Computer Management’ application from start menu and click on ‘Disk Management’. Here you should be able to see various hard disks and its partitions.



            So basically in windows file system each partition is represented as drive letters (c: d: e:  etc.,). In Linux, file system its bit different, it has sda which represents hard disk and sda1, sda2, sda3 etc. as partition representation.

As you can see top three entries without any file system are Ubuntu OS and the forth entry is reserved by laptop manufacturer for OS restore. Rest 4 are NTFS partitions from which one has Windows OS installed (c:), one has boot for Linux (e:) which was created by Ubuntu (more on this later), one has my data (g:) and last one (d:) is reserved by laptop manufacturer for drivers etc.

            You can install Ubuntu in as small as 15 to 20 GB but I have used approx. 46 GB. You need to free up space from either primary or extended partition via disk management utility or various third party tools available online.

Installation:


            Use the disk or bootable USB flash drive that you created earlier and restart the system. Change boot order so that the disk or USB flash drive is accessed prior to hard disk.

Once media is accessed you will see various options as below:

·         Try Ubuntu without installation
·         Install Ubuntu
·         OEM install (for manufacturers)
·         Check disk for defeats

Select Install Ubuntu and let the installation load which might take a little time. You will be greeted at Welcome screen where you should choose language. After continuing you should see Preparing to install Ubuntu screen with following options:

·         Download updated while installing Ubuntu
·         Install third-party software for graphics and Wi-Fi hardware, Flash, MP3 and other media

First options is not selectable because you are installing directly from media, if you chosen
‘Try Ubuntu’ first and installed from there then you should be able to select this option. You should select second option as it’s recommended.

            When you click continue you might get pop up ‘Force UEFI installation?’ UEFI is a new bios firmware that is used with newer OS and hardware. If you have Windows 8 or later you should continue with UEFI method. As mentioned before I had Windows 7 and upgraded to Windows 10 so I did not continue with UEFI method, instead I clicked go back.

            You should see Installation type screen with following options:

·         Install Ubuntu alongside them
·         Erase disk and install Ubuntu
·         Something else

I got first option because I already Ubuntu prior to writing this blog. Select the ‘Something else as we want to custom install Ubuntu.



            Above image is of ‘Gparted’ application from my installed Ubuntu which we will use here as a reference to custom install Ubuntu. Remember the e: drive I mentioned that is where Ubuntu updated boot record. You should see a screen which look little similar to shared image but with some options below.

Swap


‘Swap’ is used for paging. It is used when you RAM memory runs out. You should keep its size as 1.5 to 2 times of RAM memory. Select ‘Unallocated’ and click on ‘+’ button.

·         Size : As I have 4 GB RAM I have kept 6000 MB
·         Type of the new partition : Primary
·         Location for the new partition : Beginning of this space
·         Use as : Swap area

Root (/)

           
This is where Ubuntu OS is installed along with installation of software and updates. Keep this partition size at least 10 to 15 GB.  Again select ‘Unallocated’ and click ‘+’.

·         Size : As you desire. I have allocated 20000 MB
·         Type of the new partition : Primary
·         Location for the new partition : Beginning of this space
·         Use as : Ext4
·         Format : true
·         Mount point : /

Home


            Home is where user data is stored this is similar to user documents in Windows OS. You know the drill select ‘Unallocated’ and click ‘+’ (You are becoming pro now J).

·         Size : Remaining space
·         Type of the new partition : Logical
·         Location for the new partition : Beginning of this space
·         Use as : Ext4
·         Format : true
·         Mount point : /home

            That’s it tuff part is over. Click “Install now” and Ubuntu will start installing. While it is being installed in background you are presented with few basic settings like location, keyboard layout and login credentials.

            After installation is competed you might get a pop up to set boot record for Ubuntu click ok. You might also get pop up regarding UEFI, select the option you selected earlier. Restart PC and remove bootable media. You should see menu with different OS options.

OOPS !!!


            If you do not see Windows OS option in boot menu don’t panic. Boot into Ubuntu, open terminal and enter following command:

            sudo update-grub

            Restart PC and you should see Windows OS option in menu.

Conclusion


            We have reached to the end of Ubuntu 16.04 LTS Installation. If you have any queries or feedback let me know in comment section below.