Install the latest version of Git from source on Ubuntu
Git is a rarely updated but important development software. The version in the official system repository is always significantly behind the latest version. If you don't want to install additional daily updates, manually installing the latest version from source is a good solution.
1. Install libraries that Git depends on
1sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev install-info
2. Download the latest Git source package
The source package is on kernel.org. Those who understand know that Linus created it, so it must be kept somewhere prestigious. The address is: https://www.kernel.org/pub/software/scm/git. Find the latest version by date. At the time of writing this article, the latest version is: git-2.37.0.tar.xz
3. Unzip to a specified location. I usually put non-system source packages in /opt (uncompress the files).
1➜ sudo tar -xvf git-2.37.0.tar.xz -C /opt/
2git-2.37.0/
3git-2.37.0/.cirrus.yml
4git-2.37.0/.clang-format
5git-2.37.0/.editorconfig
6git-2.37.0/.gitattributes
7....
4. Compile and Install (configure && make install)
1➜ cd /opt/git-2.37.0
Check the default compilation options (check default location)
1➜ git-2.37.0 ./configure --help
2`configure' configures git 2.37.0 to adapt to many kinds of systems.
3
4Usage: ./configure [OPTION]... [VAR=VALUE]...
5
6To assign environment variables (e.g., CC, CFLAGS...), specify them as
7VAR=VALUE. See below for descriptions of some of the useful variables.
8
9Defaults for the options are specified in brackets.
10
11Configuration:
12-h, --help display this help and exit
13--help=short display options specific to this package
14--help=recursive display the short help of all the included packages
15-V, --version display version information and exit
16-q, --quiet, --silent do not print `checking ...' messages
17--cache-file=FILE cache test results in FILE [disabled]
18-C, --config-cache alias for `--cache-file=config.cache'
19-n, --no-create do not create output files
20--srcdir=DIR find the sources in DIR [configure dir or `..']
21
22Installation directories:
23--prefix=PREFIX install architecture-independent files in PREFIX
24[/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
25[PREFIX]
26
27By default, `make install' will install all the files in
28`/usr/local/bin', `/usr/local/lib' etc. You can specify
29an installation prefix other than `/usr/local' using `--prefix',
30for instance `--prefix=$HOME'.
31
32For better control, use the options below.
Comply with the specification, no special settings are necessary, start compiling
1➜ git-2.37.0 sudo ./configure
2configure: Setting lib to 'lib' (the default)
3configure: Will try -pthread then -lpthread to enable POSIX Threads.
4configure: CHECKS for site configuration
5checking for gcc... gcc
6checking whether the C compiler works... yes
Install
1➜git-2.37.0 sudo make install
2GIT_VERSION = 2.37.0
3* new build flags
4CC fuzz-commit-graph.o
5CC fuzz-pack-headers.o
6......
Check the results. Newly installed version:
1➜ git-2.37.0 /usr/local/bin/git --version
2git version 2.37.0
Original system version:
1➜ git --version
2git version 2.34.1
It's a good idea to back up the old version as git_old to have a fallback. Confirm that /usr/local/bin is in the search path for the PATH environment variable.
1➜ sudo mv /usr/bin/git /usr/bin/git_old
2➜ echo $PATH
3/home/mephisto/.cargo/bin:/home/mephisto/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Done.
1➜ git -v
2git version 2.37.0
Copyright statement:
- All content that is not sourced is original., please do not reprint without authorization (because the typesetting is often disordered after reprinting, the content is uncontrollable, and cannot be continuously updated, etc.);
- For non-profit purposes, to deduce any content of this blog, please give the relevant webpage address of this site in the form of 'source of original text' or 'reference link' (for the convenience of readers).
See Also:
- Ubuntu install WeChat
- Ubuntu connects AirPods headphones
- A Brief Introduction to Scientific Internet Access with Xray