This guide walks you through installing Git, the version control system, on Ubuntu 20.04 LTS. You’ll learn the quickest method using the default repositories, how to verify the installation, and how to configure your identity so your commits are properly attributed. No prior experience with Git is required.
What You’ll Need
- A machine running Ubuntu 20.04 LTS with an active internet connection.
- Access to a user account with
sudoprivileges to install packages. - A terminal window (Ctrl+Alt+T).
Step-by-Step
- Open a terminal. Press
Ctrl+Alt+Ton your keyboard, or search for “Terminal” in the applications menu. - Update your package list. Run
sudo apt update. This refreshes the list of available packages from the Ubuntu repositories. You’ll be prompted for your password; enter it and press Enter. - Install Git. Run
sudo apt install git. The system will show you how much disk space the installation will use and ask for confirmation. TypeYand press Enter to proceed. - Verify the installation. After the installation finishes, check the version with
git --version. You should see output similar togit version 2.25.1. The exact version number may vary depending on the latest updates in the Ubuntu 20.04 repositories. - Set your Git username. Git needs to know who is making commits. Run the following, replacing “Your Name” with your actual name (keep the quotes):
git config --global user.name "Your Name" - Set your Git email. Run the following, replacing “you@example.com” with the email address you want associated with your commits:
git config --global user.email "you@example.com" - Confirm your configuration. Run
git config --listto see all your Git settings. You should see theuser.nameanduser.emailentries you just set, along with other defaults. - Start using Git. You can now use Git in any directory. For example, to initialize a new repository, navigate to your project folder with
cd /path/to/your/projectand rungit init.
Common Mistakes
- Forgetting to run
sudo. Theapt installcommand requires administrative privileges. Running it withoutsudowill result in a “Permission denied” error. - Not updating first. Skipping
sudo apt updatecan lead to installing an outdated version of Git or, in rare cases, a “package not found” error if the package index is stale. - Setting global config in the wrong directory. The
--globalflag sets the configuration for your current user across all projects. If you omit it, the config is only applied to the current repository, which can cause confusion later. - Using an incorrect email address. Git associates commits with the email you set. A typo here can misattribute your work. Double-check the address before proceeding.
Tips
- Use a meaningful email. If you plan to push code to GitHub, GitLab, or another hosting service, use the same email address you registered with there. This ensures your commits are linked to your account.
- Check the version periodically. Ubuntu 20.04 LTS ships with Git 2.25.x. If you need a newer version with the latest features, you can add the official Git PPA (Personal Package Archive) with
sudo add-apt-repository ppa:git-core/ppa, then runsudo apt update && sudo apt upgrade git. This is optional but useful for developers who want the newest tools. - Explore Git help. Run
git helporgit help <command>(for example,git help commit) to see built-in documentation. - Set a default text editor. Git uses an editor for commit messages. If you prefer nano or vim, set it with
git config --global core.editor "nano"(or “vim”).
Troubleshooting
- “E: Unable to locate package git” – This usually means your package list is out of date. Run
sudo apt updatefirst, then try the install again. If it persists, check your internet connection and that your/etc/apt/sources.listfile contains valid Ubuntu repositories. - “Permission denied” when running
apt install– You are not usingsudo. Prependsudoto the command. If you still get permission errors, your user may not be in thesudogroup. Contact your system administrator. - Git is installed but
git --versionshows nothing – The installation may have failed partway. Runsudo apt install --fix-broken gitto repair any broken dependencies, then check again. - Changes to global config don’t seem to apply – If you are inside a repository that has its own local config (in
.git/config), those local settings override the global ones. Check withgit config --list --show-originto see where each setting is coming from.
Frequently Asked Questions
Do I need to install Git if I only want to download code from GitHub?
Yes. Git is the tool that GitHub uses for version control. To clone (download) a repository, you need Git installed on your system.
What is the difference between git and github?
Git is a version control system that runs locally on your machine. GitHub is a web-based hosting service for Git repositories. You can use Git without GitHub, but GitHub requires Git to interact with it.
How do I uninstall Git?
Run sudo apt remove git to uninstall the software. If you also want to remove configuration files, use sudo apt purge git. Your existing repositories and their .git folders will remain untouched.
Can I install Git using Snap or Flatpak?
Yes, but the apt method is the most straightforward and well-integrated with Ubuntu. Snap (sudo snap install git) and Flatpak are available, but they may have slightly different file paths and permissions. The apt version is recommended for most users.
Why do I need to set user.name and user.email?
Every commit in Git records the author’s name and email. Without these, Git will either prompt you for them or use a default like “root” and “root@hostname”, which is rarely what you want. Setting them globally once saves you from entering them for every repository.
What if I already have an older version of Git installed?
Running sudo apt install git will upgrade it to the latest version available in the Ubuntu 20.04 repositories. You can check your current version with git --version before and after.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- How to Add Another Account on Telegram
- Ubuntu Printer Detected But Won’t Print: Fix
- Autoplay Not Working on Windows 11? Fix It
- Edit Messages on iPhone & View Edit History
- How to Clean Rust Off Chrome Dinette Legs
- Prepare Your PC for a Major Windows Upgrade