Issue
In my use case, I want to use the latest version of GIT in CentOS7. But I do not have sudo access to install git in the box.
Installed git version is 1.8.3.1
. But I want to use 2.4.11
because the version 1.8.3
gives errors like
unrecognized argument: --author-date-order
I downloaded the latest git and tried to use it. I could run it without the error mentioned above. I used like bin/git
directly.
$git.Linux.x86_64/bin/git --version
git version 2.4.11
But I cannot change the code in all the places with the path. Is there a way to set latest git PATH and use it without installing it?
I would really appreciate any help on this.
Solution
I believe you are out of luck, but maybe not.
When something (your shell, another program, anything) tries to invoke Git, the Operating System searches for a program executable named Git in each of the folders in your PATH variable.
So if you want to prevent Git
from matching the existing version installed by root, then you are out of luck, short of removing some very important folders from your PATH (don't do this!). However, you MAY be able to figure out the order in which the OS searches the PATH variable to find the Git executable, and you can prepend or append YOUR git bin folder. That way assuming the OS searches in a predictable way, it should find YOUR Git before it finds the Git installed system-wide.
Then, you can change your .bashrc to consistently prepend/append your git bin folder as your user logs in.
This is a bit hack-y and could result in undefined behaviour, though so user beware. The proper way would be to ask your sysadmin to update Git or fix the errors to allow you to use it.
EDIT After a quick test on Fedora (which should behave similarly to CentOS given it's a Red Hat distro) it seems to search from the start of the path (left hand side) and stops after the first match.
EDIT 2 It also occurs to me to warn you: this will only work for invocations of Git from within your user environment. If you run something as a different user, or something that doesn't have the same $PATH variable, then that will git the different version installed system-wide. Again, user beware.
Answered By - Geraden Answer Checked By - Senaida (WPSolving Volunteer)