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-188.8.131.52-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-184.108.40.206-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-220.127.116.11-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-18.104.22.168-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 22.214.171.124 [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 126.96.36.199 [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.
Latest posts by Sahil Suri (see all)
- Setting up chrooted ssh jails in Linux - October 8, 2019
- How To exclude copying of specific directories in Linux using cp/scp/rsync - October 7, 2019
- Docker container ports explained - September 27, 2019
- Docker Volumes explained - September 25, 2019
- Docker networking commands explained - September 24, 2019