Showing posts with label GIT Installation. Show all posts
Showing posts with label GIT Installation. Show all posts

Thursday, 8 August 2019

HOW TO INSTALL GIT IN LINUX WITHOUT ROOT ACCESS ?

INTRODUCTION

In one of our earlier articles on using the git distributed version control system, we showed you how to install git in Linux. As you may observe from that article, installing git is a fairly straightforward process. But what if you were not a system administrator and did not have sahil privileges on the system you were working on. One alternative could be to build the git package from the source code but that would still require access to a compiler like gcc which you may not have.
In this article, we will share a very simple method to install the git version control system on your machine requiring only access to the rpm package for git.

Step 1: Create a folder named git 
The first step is to create a folder named git where you would like to store git related binaries.
[sahil@linuxnix:~] $ mkdir git

Step 2: Copy the git rpm to the git folder
The next step is to copy the git rpm to the folder named git that we created in the previous step.
[sahil@linuxnix:~] $ mv git-1.8.3.1-12.el7_4.x86_64.rpm git
[sahil@linuxnix:~] $ cd git
[sahil@linuxnix:~/git] $ ls -ltr
total 4516
-rw-r--r-- 1 sahil sahil 4600452 Aug 16 08:59 git-1.8.3.1-12.el7_4.x86_64.rpm

Step 3: Extract the git rpm contents
Now we will extract the contents of the git rpm into the current working directory i.e git.
For extracting the rpm contents we will use a combination of the rpm2cpio and cpio commands.
[sahil@linuxnix:~/git] $ rpm2cpio git-1.8.3.1-12.el7_4.x86_64.rpm | cpio -idmv
./etc/bash_completion.d
./etc/bash_completion.d/git
./usr/libexec/git-core
./usr/libexec/git-core/git-add--interactive
---------------------------------------------------output truncated for brevity
For the time being, don’t worry if you are unable to understand how the rpm2cpio and cpio command combination worked. We will emphasize on that aspect of the redhat package manager in a separate article dedicated to it. For the purpose of this demonstration, just understand that the rpm2cpio and cpio command combination extracts all the files contained in the rpm into the current working directory. Note that the file and directory hierarchy structures are maintained during this rpm extraction process.

Step 4: Verify that the git binary is now available
Now that the rpm package contents have been extracted, let’s take a look at the files and directories available in our git folder now.
[sahil@linuxnix:~/git] $ ls
etc git-1.8.3.1-12.el7_4.x86_64.rpm usr
[sahil@linuxnix:~/git] $
Notice that there is a usr directory here. Under the usr directory, we will have a bin directory under which the git related binaries will reside.
[sahil@linuxnix:~/git/usr/bin] $ pwd
/export/home/sahil/git/usr/bin
[sahil@linuxnix:~/git/usr/bin] $ ls
git git-receive-pack git-shell git-upload-archive git-upload-pack
[sahil@linuxnix:~/git/usr/bin] $
The file git is the git binary that we will use.
[sahil@linuxnix:~/git/usr/bin] $ ls -lht git
-rwxr-xr-x 112 sahil unix 1.5M Aug 11 2017 git
[sahil@linuxnix:~/git/usr/bin] $

Step 5: Verify that git works
To verify that the binary actually works, let’s check the version of the git package using the below command
[sahil@linuxnix:~/git/usr/bin] $ ./git --version
git version 1.8.3.1
[sahil@linuxnix:~/git/usr/bin] $

Step 6: Add the location of the git binary to the PATH variable
Under the current setup, we would have to be within our ~/git/usr/bin directory to be able to use the git binary.
To be able to use it from within anywhere in the file system hierarchy, we need to add this location to the PATH environment variable inside the .bash_profile file in our home directory.
grep PATH .bash_profile
export PATH=$PATH:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/local/sbin:$HOME/git/usr/bin

Step 7: Verify that git is available outside ~/git/usr/bin directory
With the PATH variable now set we should be able to use git commands from anywhere within the file system hierarchy. Let’s give it a try.
[sahil@linuxnix:~] $ cd /tmp
[sahil@linuxnix:/tmp] $ pwd
/tmp
[sahil@linuxnix:/tmp] $ git --version
git version 1.8.3.1
[sahil@linuxnix:/tmp] $
The above output confirms that access to the git binary is now available outside the ~/git/usr/bin directory.

CONCLUSION

In this article, we demonstrated how we install the git version control system on our machine despite not having superuser privileges on it.

WHAT IS GIT AND HOW TO INSTALL IT ON CENTOS

INTRODUCTION

A version control system is a piece of software that records changes to a file or set of files over time so that you can recall specific versions of these files at a later date. The need for version control is not limited to developers in today’s complex and mission-critical infrastructure environments. System administrators too can make efficient use of version control to track changes in their scripts and/or place different configuration files under version control.
GIT is a powerful distributed version control system, perhaps the most powerful and feature-rich version control system available as of this writing.
We’ve already briefly talked about the need for version control for system administrators and in this article, we will talk about how GIT came into existence and how to install it on a centos system.

History of GIT
GIT was created by Linus Torvalds in 2005. It is written in Perl and C. The GIT project was essentially started as a substitute version control system for the Linux Kernel after BitKeeper withdrew its support. This project has since become immensely popular among since the emergence of the devops movement and framework and continues to increase its popularity.

GIT Design goals:
  • Speed
  • Simplicity
  • Strong branch/merge support
  • Distributed
  • Scales well for large projects
We mentioned in our introduction that GIT is a distributed version control system. Given below are the advantages of distributed version control systems over other types:
  • Developers generally push changes to their own repository which are then pulled into the official repository by the project maintainers.
  • Cloning of repositories serves as an easy way to backup projects as each clone is a full backup.
  • Allows branches and applying fixes to different branches.
  • A full local history is available along with other repository statistics.
  • Deployment is very streamlined.

INSTALL GIT

GIT runs on Linux, OS X, Windows, and many other operating systems.
Now we will show you how to install GIT via yum. For RedHat and Centos systems, the git package along with its dependencies is available in the base repository. To install git via yum we execute the following command:
[root@linuxnix ~]# yum install git -y
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 8.2 kB 00:00:00
extras | 3.4 kB 00:00:00
puppetlabs-pc1 | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* epel: mirror1.ku.ac.th
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-6.el7_2.1 will be updated
--> Processing Dependency: git = 1.8.3.1-6.el7_2.1 for package: perl-Git-1.8.3.1-6.el7_2.1.noarch
---> Package git.x86_64 0:1.8.3.1-12.el7_4 will be an update
--> Running transaction check
---> Package perl-Git.noarch 0:1.8.3.1-6.el7_2.1 will be updated
---> Package perl-Git.noarch 0:1.8.3.1-12.el7_4 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Updating:
git x86_64 1.8.3.1-12.el7_4 updates 4.4 M
Updating for dependencies:
perl-Git noarch 1.8.3.1-12.el7_4 updates 53 k

Transaction Summary
====================================================================================================================================
Upgrade 1 Package (+1 Dependent package)

Total download size: 4.4 M
Downloading packages:
updates/7/x86_64/prestodelta | 605 kB 00:00:02
Delta RPMs reduced 53 k of updates to 26 k (50% saved)
(1/2): perl-Git-1.8.3.1-6.el7_2.1_1.8.3.1-12.el7_4.noarch.drpm | 26 kB 00:00:02
(2/2): git-1.8.3.1-12.el7_4.x86_64.rpm | 4.4 MB 00:00:42
------------------------------------------------------------------------------------------------------------------------------------
Total 105 kB/s | 4.4 MB 00:00:43
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : perl-Git-1.8.3.1-12.el7_4.noarch 1/4
Updating : git-1.8.3.1-12.el7_4.x86_64 2/4
Cleanup : perl-Git-1.8.3.1-6.el7_2.1.noarch 3/4
Cleanup : git-1.8.3.1-6.el7_2.1.x86_64 4/4
Verifying : git-1.8.3.1-12.el7_4.x86_64 1/4
Verifying : perl-Git-1.8.3.1-12.el7_4.noarch 2/4
Verifying : perl-Git-1.8.3.1-6.el7_2.1.noarch 3/4
Verifying : git-1.8.3.1-6.el7_2.1.x86_64 4/4

Updated:
git.x86_64 0:1.8.3.1-12.el7_4

Dependency Updated:
perl-Git.noarch 0:1.8.3.1-12.el7_4

Complete!
[root@linuxnix ~]#

Install GIT from source:
We’ll now show you how to install it from source. Before you begin, you’ll need to install the software that git depends on.  We’ll now install these dependencies with the following commands:
sudo yum groupinstall "Development Tools"
sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
The development tools package group consists of tools like gcc which are essential in compiling and building binaries from source code.
I’ve downloaded git using the git repository  on github.
[root@linuxnix ~]# ls -l git-master.zip
-rw-r--r--. 1 root root 8615986 Dec 30 03:51 git-master.zip
[root@linuxnix ~]#
Let’s unzip it.
[root@linuxnix ~]# unzip git-master.zip
Now that the file has been extracted, let’s take a look inside the directory.
[root@linuxnix git-master]# pwd
/root/git-master
[root@linuxnix git-master]# ls | wc -l
395
Once we are in the source folder, we can begin the source build process.  We can perform pre-build checks like software dependencies and hardware configurations with the configure script that is generated by make configure.
This script will also use a –prefix to declare /usr/local as the appropriate destination for the new binary and will create a Makefile to be used in the following step. We’ll generate the Makefile with the following commands:
make configure
./configure --prefix=/usr/local
Makefiles are scriptable configuration files that are processed by the make utility. Our Makefile will tell make how to compile a program and link it to our CentOS installation so that we can execute the program properly.  With a Makefile in place, we can now execute make install to compile the source code into a working program and install it on our server. We’ll now execute the make install command as follows to install the required packages on the system.
make install
Once the install completes, we can verify that we now have git installed by checking it’s version.
[root@linuxnix ~]# which git
/usr/local/bin/git
[root@linuxnix ~]#
[root@linuxnix ~]# git --version
git version 2.16.0-rc0
[root@linuxnix ~]#

CONCLUSION

In this article, we showed you how to install git via the yum package manager and also from source. We also explained the need for version control systems and the different advantages they provide.

Thursday, 27 December 2018

GIT: Installation of the Git command line tooling

6.1. Ubuntu, Debian and derived systems

On Ubuntu and similar systems you can install the Git command line tool via the following command:
sudo apt-get install git

6.2. Fedora, Red Hat and derived systems

On Fedora, Red Hat and similar systems you can install the Git command line tool via the following command:
dnf install git

6.3. Other Linux systems

To install Git on other Linux distributions please check the documentation of your distribution. The following listing contains the commands for the most popular ones.
# Arch Linux
sudo pacman -S git

# Gentoo
sudo emerge -av git

# SUSE
sudo zypper install git

6.4. Windows

A Windows version of Git can be found on the Git download page. This website provides native installers for each operating system. The homepage of the Windows Git project is git for window.

6.5. Mac OS

The easiest way to install Git on a Mac is via the Git download page and to download and run the installer for Mac OS X.
Git is also installed by default with the Apple Developer Tools on Mac OS X.