I recently explained how to install Git on Ubuntu 20.04. The two ways I’ve shown you are based on pre-compiled packages for Ubuntu. But sometimes it’s better to do it another way. That’s why, in this post, you’ll learn how to install Git from the source code in Ubuntu 20.04.
Git is a free and open-source distributed version control system. It is perhaps the most popular within the branch as millions of developers use it to control software versions. Ease of use, community support, and efficient version control are the main features of Git. In addition, it is open-source and free, which makes it ideal for all projects.
Why should I install a program from the source code?
The answer to this question can be summed up as efficiency. When we install a program from the source code, only what is necessary to work according to our system and hardware is installed. This makes it faster and more efficient.
On the other hand, there is a security issue. When a package comes already done and we install it, at the end we won’t know who compiled it and under what parameters it was done. This is not the end of the world because we know that in Linux, the repositories are quite taken care of by the developers of the distributions, but, indeed, it is not compiled specifically for us.
Therefore, if you are thinking of using it in a company or a personal project, compiling it can assure you even more efficiency and security.
Finally, learning to compile packages is a great help for working with Linux and can also be used in other areas.
Installing Git from the source code
First, you have to install all the packages needed to compile code in Ubuntu 20.04
To do this, open a terminal and run the following command:
:~$ sudo apt install build-essential Reading package lists… Done Building dependency tree Reading state information… Done The following packages were automatically installed and are no longer required: git-man libcurl3-gnutls liberror-perl Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev Suggested packages: binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib glibc-doc git bzr libstdc++-9-doc make-doc The following NEW packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev 0 upgraded, 40 newly installed, 0 to remove and 22 not upgraded. Need to get 39.8 MB of archives. After this operation, 174 MB of additional disk space will be used. Do you want to continue? [Y/n]
Then, install the packages that will allow you to build the application once it is compiled for our system:
:~$ sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
Also included in the above command is the unzip package that will help decompress the Git source code file.
Then, you proceed to download the Git source code from the /tmp/ folder
:~$ cd/tmp
:~$ wget -c https://github.com/git/git/archive/v2.26.2.zip -O git.zip
When the download is finished, proceed to decompress the file.
:~$ unzip git.zip
This will create a folder called git-2.26.2 and you’ll need to access it.
:~$ cd git-2.26.2
And then start compiling from there:
:~$ sudo make prefix=/usr/local all
And then, the installation:
:~$ sudo make prefix=/usr/local install
This process will take a little while according to your computer.
Now we have to prove that everything works properly. To do this, display the version of Git using that same command:
:~$ git --version
git version 2.26.2
This indicates that the git command is being recognized by the system. So, it’s ready to be used.
Conclusion
Perhaps compiling the source code of an application yourself is not the most direct way to install it, but it is the most efficient and secure. So it’s always good to do so when there are not too many complications.
So, share this post, join our Telegram channel and if you can, buy us a coffee. 🙂