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- git
[sahil@linuxnix:~] $ cd git
[sahil@linuxnix:~/git] $ ls -ltr
total 4516
-rw-r--r-- 1 sahil sahil 4600452 Aug 16 08:59 git-


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- | cpio -idmv
---------------------------------------------------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- 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
[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
[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
[sahil@linuxnix:/tmp] $ git --version
git version
[sahil@linuxnix:/tmp] $

The above output confirms that access to the git binary is now available outside the ~/git/usr/bin directory.



In this article, we demonstrated how we install the git version control system on our machine despite not having superuser privileges on it. We hope that you’ve found the steps outlined in this article to be useful and we look forward towards your suggestions feedback.

The following two tabs change content below.

Sahil Suri

He started his career in IT in 2011 as a system administrator. He has since worked with HP-UX, Solaris and Linux operating systems along with exposure to high availability and virtualization solutions. He has a keen interest in shell, Python and Perl scripting and is learning the ropes on AWS cloud, DevOps tools, and methodologies. He enjoys sharing the knowledge he's gained over the years with the rest of the community.