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-184.108.40.206-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-220.127.116.11-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-18.104.22.168-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-22.214.171.124-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 126.96.36.199 [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 188.8.131.52 [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)
- How does /tmp directory get emptied automatically over time ? - January 22, 2019
- Oracle VirtualBox installation troubleshooting in Linux explained - October 23, 2018
- How to install Oracle virtual box on Centos 7? - October 22, 2018
- Understanding swapiness parameter in Linux - September 20, 2018
- Resolving YUM: Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast - September 19, 2018