Tuesday 3 November 2015

Version Control using git in CentOS7


Version control systems allow you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch off from the base code to create alternative versions of files and directories.
One of the most popular version control systems is git. Many projects maintain their files in a Git repository, and sites like GitHub and Bitbucket have made sharing and contributing to code with Git easier than ever.
In this guide, we will demonstrate how to install Git on a CentOS 7 server.

1) Install git.

[shabbir@compute1 ~]$ sudo yum install git


2) Configure your name and email.

[shabbir@compute1 ~]$ git config --global user.name "shabbir rangwala"
[shabbir@compute1 ~]$ git config --global user.email "shabbir.ahr@gmail.com"

[shabbir@compute1 ~]$ git config --list
user.name=shabbir rangwala
user.email=shabbir.ahr@gmail.com


3) Create your workspace. Create a dir. 'git' in the home directory and subfolders for each of our individual projects. 

[shabbir@compute1 ~]$ mkdir -p ~/git/perl
[shabbir@compute1 ~]$ cd ~/git/perl


4) Copy all project files to the dir. Here we create a test file to use in our repository.

[shabbir@compute1 perl]$ touch test_file.pl


5)  Tell git that you want to use your current directory as a git environment.

[shabbir@compute1 perl]$ git init
Initialized empty Git repository in /home/shabbir/git/perl/.git/


6) Add all files and directories to your newly created repository.

[shabbir@compute1 perl]$ git add .


7) Every time you add or make changes to files, you need to write a commit message. Commit messages explain what your change did.

[shabbir@compute1 perl]$ git commit -m "Initial Commit" -a

the -a signifies that we want our commit message to be applied to all added or modified files. This is okay for the first commit, but generally you should specify the individual files or directories that we want to commit.

To commit an individual file.
[shabbir@compute1 perl]$ git commit -m "Initial Commit" test_file.pl

To add additional files or directories, you just add a space separated list to the end of that command.

8) Create an account on github.com and create a repository 'perl'


9) Configure the remote repository. The name is 'origin' and the URL is 'https://github.com/RShabbir53/perl.git'.

[shabbir@compute1 perl]$ git remote add origin https://github.com/RShabbir53/perl.git

[shabbir@compute1 perl]$ git remote -v
origin    https://github.com/RShabbir53/perl.git (fetch)
origin    https://github.com/RShabbir53/perl.git (push)



10) Push code to the remote server. "git push" tells git that we want to push our changes, "origin" is the name of our newly-configured remote server and "master" is the name of the first branch.
In the future, when you have commits that you want to push to the server, you can simply type "git push".

[shabbir@compute1 perl]$ git push -u origin master


11) In the future, when you have commits that you want to push to the server, you can simply type "git push".

Sunday 1 November 2015

Install Ruby on Rails in CentOS7



1) Install prerequisites.

[shabbir@compute1~]$ sudo yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel


2) Install rbenv

[shabbir@compute1~]$ git clone git://github.com/sstephenson/rbenv.git .rbenv

[shabbir@compute1~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

[shabbir@compute1~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
  
[shabbir@compute1~]$ exec $SHELL
  
[shabbir@compute1~]$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
  
[shabbir@compute1~]$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
  
[shabbir@compute1~]$ exec $SHELL

Reboot the machine.
[shabbir@compute1~]$ systemctl reboot



3) Install Ruby

[shabbir@compute1 ~]$ rbenv install -v 2.2.3

[shabbir@compute1 ~]$ rbenv global 2.2.3


Verify that Ruby was installed properly.
[shabbir@compute1 ~]$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]


[shabbir@compute1 ~]$ echo "gem: --no-document" > ~/.gemrc

[shabbir@compute1 ~]$ gem install bundler



4) Install Rails 

[shabbir@compute1 ~]$ gem install rails -v 4.2.4

[shabbir@compute1 ~]$ rbenv rehash 

Verify that Rails was installed properly.
[shabbir@compute1 ~]$ rails -v
Rails 4.2.4

 
 
5) Install JavaScript Runtime

Install EPEL Repository.
[shabbir@compute1 ~]$ sudo yum -y install epel-release


[shabbir@compute1 ~]$ sudo yum install nodejs



6) Install Database

[shabbir@compute1 ~]$ sudo yum groupinstall mariadb


[shabbir@compute1 ~]$ sudo yum install mariadb-devel

[shabbir@compute1 ~]$ sudo systemctl enable mariadb

[shabbir@compute1 ~]$ sudo systemctl start mariadb 

[shabbir@compute1 ~]$ gem install mysql

[shabbir@compute1 ~]$ rbenv rehash



7) Create 'Hello World' Application

7.1) Create Demo Project
[shabbir@compute1 ~]$ rails new demo


7.2) Start the Web Server.
[shabbir@compute1 ~]$ cd demo 

[shabbir@compute1 demo]$ rails server

7.3) Open a browser and type the following URL. http://localhost:3000
 





NOTE: To stop the web server, hit Ctrl+C in the terminal window where it's running.


7.4) Create a new controller called "welcome" with an action called "index".

[shabbir@compute1 demo]$ generate controller welcome index
      create  app/controllers/welcome_controller.rb
       route  get 'welcome/index'
      invoke  erb
      create    app/views/welcome
      create    app/views/welcome/index.html.erb
      invoke  test_unit
      create    test/controllers/welcome_controller_test.rb
      invoke  helper
      create    app/helpers/welcome_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/welcome.coffee
      invoke    scss
      create      app/assets/stylesheets/welcome.scss



The controller, is located at app/controllers/welcome_controller.rb and the view, located at app/views/welcome/index.html.erb.


7.5) Edit the View.

[shabbir@compute1 demo]$ vi app/views/welcome/index.html.erb

<h1>Hello, World!</h1>



7.6) Now that we have made the controller and view, we need to tell Rails when we want "Hello, World!" to show up. In our case, we want it to show up when we navigate to the root URL of our site, http://localhost:3000. At the moment, "Welcome aboard" is occupying that spot.

Edit the application's routing file.
[shabbir@compute1 demo]$ vi config/routes.rb

Uncomment the following line
  root 'welcome#index'


7.7) Ensure that the Web server is running. Open a browser and type the following URL. http://localhost:3000