Linux online installation of git method

Tools/Materials

git

  • CentOS6.5
  • v2.3.0.zip

method/step

  1. 1

    Check if it is installed with git --version command

    How to install git in linux
  2. 2

    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.

    How to install git in linux
  3. 3

    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.

    How to install git in linux
    How to install git in linux
    END

Compile and install git

  1. 1

    Update the system first

    yum  -y update

    After the update is complete, 6.5 has become 6.7

    How to install git in linux
  2. 2

    Install dependent packages

    yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

  3. 3

    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

    How to install git in linux
  4. 4

    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.

    How to install git in linux
  5. 5

    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

    How to install git in linux
    How to install git in linux
  6. 6

    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

    How to install git in linux
  7. 7

    Do not want to restart the system, use the source command to take effect immediately

    source /etc/profile

  8. 8

    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.

    How to install git in linux

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325396214&siteId=291194637