1、下载最新版Git
a)查看最新版
https://mirrors.edge.kernel.org/pub/software/scm/git/
或者
https://github.com/git/git/releases
b)下载最新版
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.19.1.tar.gz
或在本地下载完成后上传到CentOS虚拟机(建议迅雷下载,wget有点慢)
2、解压
[root@localhost download]# pwd
/usr/local/src/download
[root@localhost download]# ll
total 49276
-rw-r--r--. 1 root root 35676 Oct 4 13:34 container-selinux-2.68-1.el7.noarch.rpm
-rw-r--r--. 1 root root 42712724 Oct 4 13:26 docker-ce-18.06.1.ce-3.el7.x86_64.rpm
-rw-r--r--. 1 root root 7708143 Dec 1 10:02 git-2.19.1.tar.gz
[root@localhost src]# tar -zxvf /usr/local/src/download/git-2.19.1.tar.gz -C /usr/local/src/
[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# ll
total 16
drwxr-xr-x. 3 root root 19 Oct 27 22:23 config
drwxr-xr-x. 2 root root 123 Dec 1 10:03 download
drwxrwxr-x. 25 root root 12288 Sep 28 04:46 git-2.19.1
drwxr-xr-x. 2 root root 6 Nov 30 21:52 workspace
3、编译
a)卸载旧版本
[root@localhost git-2.19.1]# yum remove git
b)make configure出错
[root@localhost git-2.19.1]# make configure
GIT_VERSION = 2.19.1
GEN configure
/bin/sh: autoconf: command not found
make: *** [configure] Error 127
解决
[root@localhost git-2.19.1]# yum install autoconf automake libtool
[root@localhost git-2.19.1]# make configure
GEN configure
c)yum install libcurl-devel
[root@localhost git-2.19.1]# yum install libcurl-devel
d)./configure
[root@localhost git-2.19.1]# ./configure --prefix=/usr/local/git --with-iconv --with-curl --with-expat=/usr/local/lib
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
configure: Setting EXPATDIR to /usr/local/lib
configure: CHECKS for programs
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking for inline... inline
checking if linker supports -R... no
checking if linker supports -Wl,-rpath,... yes
checking for gar... no
checking for ar... ar
checking for gtar... gtar
checking for gnudiff... no
checking for gdiff... no
checking for diff... diff
checking for asciidoc... no
Using 'grep -a' for sane_grep
configure: CHECKS for libraries
checking for SHA1_Init in -lcrypto... no
checking for SHA1_Init in -lssl... no
checking for curl_global_init in -lcurl... yes
checking for curl-config... curl-config
checking for XML_ParserCreate in -lexpat... no
checking for iconv in -lc... yes
checking for deflateBound in -lz... no
checking for socket in -lc... yes
checking for inet_ntop... yes
checking for inet_pton... yes
checking for hstrerror... yes
checking for basename in -lc... yes
checking for gettext in -lc... yes
checking libintl.h usability... yes
checking libintl.h presence... yes
checking for libintl.h... yes
configure: CHECKS for header files
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking for inttypes.h... (cached) yes
checking for old iconv()... no
configure: CHECKS for typedefs, structures, and compiler characteristics
checking for socklen_t... yes
checking for struct itimerval... yes
checking for struct stat.st_mtimespec.tv_nsec... no
checking for struct stat.st_mtim.tv_nsec... yes
checking for struct dirent.d_type... yes
checking for struct passwd.pw_gecos... yes
checking for struct sockaddr_storage... yes
checking for struct addrinfo... yes
checking for getaddrinfo... yes
checking for library containing getaddrinfo... none required
checking whether the platform regex supports REG_STARTEND... yes
checking whether system succeeds to read fopen'ed directory... yes
checking whether snprintf() and/or vsnprintf() return bogus value... no
checking whether the platform uses typical file type bits... yes
configure: CHECKS for library functions
checking libgen.h usability... yes
checking libgen.h presence... yes
checking for libgen.h... yes
checking paths.h usability... yes
checking paths.h presence... yes
checking for paths.h... yes
checking libcharset.h usability... no
checking libcharset.h presence... no
checking for libcharset.h... no
checking for strings.h... (cached) yes
checking for locale_charset in -liconv... no
checking for locale_charset in -lcharset... no
checking for clock_gettime... yes
checking for library containing clock_gettime... none required
checking for CLOCK_MONOTONIC... yes
checking for setitimer... yes
checking for library containing setitimer... none required
checking for strcasestr... yes
checking for library containing strcasestr... none required
checking for memmem... yes
checking for library containing memmem... none required
checking for strlcpy... no
checking for uintmax_t... yes
checking for strtoumax... yes
checking for library containing strtoumax... none required
checking for setenv... yes
checking for library containing setenv... none required
checking for unsetenv... yes
checking for library containing unsetenv... none required
checking for mkdtemp... yes
checking for library containing mkdtemp... none required
checking for initgroups... yes
checking for library containing initgroups... none required
checking for getdelim... yes
checking for library containing getdelim... none required
checking for BSD sysctl... no
checking for POSIX Threads with ''... no
checking for POSIX Threads with '-mt'... no
checking for POSIX Threads with '-pthread'... yes
configure: creating ./config.status
config.status: creating config.mak.autogen
config.status: executing config.mak.autogen commands
4、make && make install
[root@localhost git-2.19.1]# make && make install
* new build flags
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:20:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
make: *** [credential-store.o] Error 1
解决
[root@localhost git-2.19.1]# yum install zlib zlib-devel
[root@localhost git-2.19.1]# make && make install
5、配置环境变量
[root@localhost git-2.19.1]#echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
[root@localhost git-2.19.1]#source /etc/bashrc
6、检查版本
[root@localhost git-2.19.1]# git --version
git version 2.19.1
7、github帐号添加SSH keys
[root@localhost git-2.19.1]# ssh-keygen -t rsa -C"你的Git账号"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #回车
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): #回车或输入密码
Enter same passphrase again: #在输一次
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:dbLagqimFQMLcl0oH+wH14TKyQ+k2L5BotlbrZPMNFM cashzhang27@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| . ..+. |
| ..*.o . |
|+o.O.* o . |
|=++ O E . + |
|o*o * S . |
|o +o=.o. o |
| .O.=. o . |
| .+.* . |
|.o. . |
+----[SHA256]-----+
[root@localhost git-2.19.1]# cat ~/.ssh/id_rsa.pub
# 再把公钥粘到GitHub或Gitee上就ok了