Tools/Materials
git
-
CentOS6.5
-
v2.3.0.zip
method/step
-
Check if it is installed with git --version command
-
In the CentOS5 version, since there is no git in the yum source, a series of dependency packages need to be pre-installed. There is already a git version in the yum source of CentOS6, which can be installed directly using the yum source.
-
yum -y install git
However, the git version installed in the yum source is 1.7.1, and the minimum Git version required by Github, etc. cannot be lower than 1.7.2. Therefore, we generally do not use the above method, but download the git source code to compile and install.
END
Compile and install git
-
Update the system first
yum -y update
After the update is complete, 6.5 has become 6.7
-
Install dependent packages
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
-
Download the git source code and unzip it
$ wget https://github.com/git/git/archive/v2.3.0.zip
$ unzip v2.3.0.zip
$ cd git-2.3.0
-
Compile and install:
Install it in the "/usr/local/git" directory.
make prefix=/usr/local/git all
make prefix=/usr/local/git install
Because the server time is not correct, an error is reported during the compilation process as shown in the figure below. Use ntpdate to automatically correct the system time. The error "Writing perl.mak for Git make[2]: *** [perl.mak] Error 1" is reported, please restart the apache service, service httpd restart.
-
After the compilation is completed, use git --version to check the git version, but it is still 1.7.1, because it uses git under "/usr/bin" by default.
You can check the path where git is located with the following command:
$ whereis git
git: /usr/bin/git /usr/local/git /usr/share/man/man1/git.1.gz
-
We need to put the compiled and installed git path into the environment variable, and let it replace the git under "/usr/bin". For this we can modify the "/etc/profile" file (or /etc/bashrc file).
vim /etc/profile
Then in the last line of the file, add the following content, then save and exit.
export PATH=/usr/local/git/bin:$PATH
-
Do not want to restart the system, use the source command to take effect immediately
source /etc/profile
-
Then use git --version again to check the git version and find that the output is 2.3.0, indicating that the installation was successful.
-