{"id":5953,"date":"2024-03-13T10:30:49","date_gmt":"2024-03-13T10:30:49","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=5953"},"modified":"2024-03-14T08:16:11","modified_gmt":"2024-03-14T08:16:11","slug":"install-git-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/","title":{"rendered":"How To Install Git on Ubuntu 20.04"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Introduction\" title=\"Introduction\">Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Prerequisites\" title=\"Prerequisites\">Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Installing_Git_with_Default_Packages\" title=\"Installing Git with Default Packages\">Installing Git with Default Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Installing_Git_from_Source\" title=\"Installing Git from Source\">Installing Git from Source<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Verify_the_Version_of_Git_Currently_Installed_on_the_Server\" title=\"Verify the Version of Git Currently Installed on the Server\">Verify the Version of Git Currently Installed on the Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Unpack_the_Compressed_Tarball_File\" title=\"Unpack the Compressed Tarball File\">Unpack the Compressed Tarball File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Setting_Up_Git\" title=\"Setting Up Git\">Setting Up Git<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/natsav.com\/blog\/install-git-on-ubuntu-20-04\/#Conclusion\" title=\"Conclusion\u00a0\">Conclusion\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span><b>Introduction<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Version control systems like Git are essential to modern software development best practices. Versioning allows you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Many software projects\u2019 files are maintained in Git repositories, and platforms like GitHub, GitLab, and Bitbucket help to facilitate software development project sharing and collaboration.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">In this guide, we will go through how to install and configure Git on an <a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\">Ubuntu 20.04 server<\/a>. We will cover how to install the software two different ways: via the built-in package manager, and via source. Each of these approaches come with their own benefits depending on your specific needs.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><b>Prerequisites<\/b><b><br \/>\n<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You will need an Ubuntu 20.04 server with a non-root superuser account.<br \/>\n<\/span><span style=\"font-weight: 400;\">To set this up, you can follow our Initial Server Setup Guide for Ubuntu 20.04.<br \/>\n<\/span><span style=\"font-weight: 400;\">With your server and user set up, you are ready to begin.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Installing_Git_with_Default_Packages\"><\/span><strong>Installing Git with Default Packages<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The option of installing with default packages is best if you want to get up and running quickly with Git, if you prefer a widely-used stable version, or if you are not looking for the newest available functionalities. If you are looking for the most recent release, you should jump to the section on installing from source.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Git is likely already installed in your Ubuntu 20.04 server. You can confirm this is the case on your server with the following command:<\/span><\/p>\n<p style=\"text-align: justify;\">git &#8211;version<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If you receive output similar to the following, then Git is already installed.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">git version 2.25.1<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If this is the case for you, then you can move onto setting up Git, or you can read the next section on how to install from source if you need a more up-to-date version.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">First, use the apt package management tools to update your local package index.<\/span><\/p>\n<p style=\"text-align: justify;\">#sudo apt update<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">With the update complete, you can install Git:<\/span><\/p>\n<p style=\"text-align: justify;\">#sudo apt install git<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You can confirm that you have installed Git correctly by running the following command and checking that you receive relevant output.<\/span><\/p>\n<p style=\"text-align: justify;\">#git &#8211;version<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">git version 2.25.1<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">With Git successfully installed, you can now move on to the Setting Up Git section of this tutorial to complete your setup.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Installing_Git_from_Source\"><\/span><strong>Installing Git from Source<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If you\u2019re looking for a more flexible method of installing Git, you may want to compile the software from source, which we will go over in this section. This takes longer and will not be maintained through your package manager, but it will allow you to download the latest release and will give you greater control over the options you include if you wish to make customizations.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Verify_the_Version_of_Git_Currently_Installed_on_the_Server\"><\/span><strong>Verify the Version of Git Currently Installed on the Server<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">#git &#8211;version<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If Git is installed, you\u2019ll receive output similar to the following:<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">git version 2.25.1<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Before you begin, you need to install the software that Git depends on. This is all available in the default repositories, so we can update our local package index and then install the relevant packages.<\/span><\/p>\n<p style=\"text-align: justify;\">#sudo apt update<\/p>\n<p style=\"text-align: justify;\">#sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">After you have installed the necessary dependencies, create a temporary directory and move into it. This is where we will download our Git tarball.<\/span><\/p>\n<p style=\"text-align: justify;\">#mkdir tmp<\/p>\n<p style=\"text-align: justify;\">#cd \/tmp<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">From the Git project website, we can navigate to the tarball list available at https:\/\/mirrors.edge.kernel.org\/pub\/software\/scm\/git\/ and download the version you would like. At the time of writing, the most recent version is 2.26.2, so we will download that for demonstration purposes. We\u2019ll use curl and output the file we download to git.tar.gz.<\/span><\/p>\n<p style=\"text-align: justify;\">#curl -o git.tar.gz https:\/\/mirrors.edge.kernel.org\/pub\/software\/scm\/git\/git-2.26.2.tar.gz<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Unpack_the_Compressed_Tarball_File\"><\/span><strong>Unpack the Compressed Tarball File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">#tar -zxf git.tar.gz<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Next, move into the new Git directory:<\/span><\/p>\n<p style=\"text-align: justify;\">#cd git-*<\/p>\n<p style=\"text-align: justify;\"><strong>Now, you can Make the Package and Install it by Typing these two Commands<\/strong><\/p>\n<p style=\"text-align: justify;\">#make prefix=\/usr\/local all<\/p>\n<p style=\"text-align: justify;\">#sudo make prefix=\/usr\/local install<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Now, replace the shell process so that the version of Git we just installed will be used:<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">With this complete, you can be sure that your install was successful by checking the version.<\/span><\/p>\n<p style=\"text-align: justify;\">#git &#8211;version<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">git version 2.26.2<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">With Git successfully installed, you can now complete your setup.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Setting_Up_Git\"><\/span><strong>Setting Up Git<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">After you are satisfied with your Git version, you should configure Git so that the generated commit messages you make will contain your correct information and support you as you build your software project.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Configuration can be achieved by using the git config command. Specifically, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:<\/span><\/p>\n<p style=\"text-align: justify;\">#git config &#8211;global user.name &#8220;Your Name&#8221;<\/p>\n<p style=\"text-align: justify;\">#git config &#8211;global user.email &#8220;youremail@domain.com&#8221;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">We can display all of the configuration items that have been set by typing:<\/span><\/p>\n<p style=\"text-align: justify;\">#git config &#8211;list<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">user.name=Your Name<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">user.email=youremail@domain.com<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a text editor of your choice like this (we\u2019ll use nano):<\/span><\/p>\n<p style=\"text-align: justify;\">#nano ~\/.gitconfig<\/p>\n<p style=\"text-align: justify;\">#~\/.gitconfig contents<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">name = Your Name<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">email = youremail@domain.com<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Press CTRL and X, then Y then ENTER to exit the text editor.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">There are many other options that you can set, but these are the two essential ones needed. If you skip this step, you\u2019ll likely see warnings when you commit to Git. This makes more work for you because you will then have to revise the commits you have done with the corrected information.<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><b>Conclusion\u00a0<\/b><b><br \/>\n<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You should now have Git installed and ready to use on your system.<\/span><\/p>\n<p style=\"text-align: justify;\">The advanced hosting product offers the most competitive pricing while ensuring reliable and fast server performance,cloud server india, <a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\"><strong>best cloud hosting in india<\/strong><\/a>, cheap cloud hosting india,cloud server cost in india,cloud server price in india,cloud server providers in india,cloud hosting price in india.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Version control systems like Git are essential to modern software development best practices. Versioning allows you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories. Many software projects\u2019 files are maintained in Git repositories, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5688,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[255],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/01\/Ubuntu-e1704458894723.jpg?fit=520%2C347&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5953"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=5953"}],"version-history":[{"count":8,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5953\/revisions"}],"predecessor-version":[{"id":5970,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5953\/revisions\/5970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5688"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=5953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=5953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=5953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}