How to install Git on Ubuntu
Git installs on Ubuntu through the terminal using the apt package manager, which takes about two minutes. You run a single command to download and install it, then verify the installation worked by checking the version number. Most Ubuntu systems come with the tools needed already, so you will not need to install dependencies separately.
This guide covers Ubuntu 20.04 and later. If you are running an older version, the steps are the same, but you may see different output in the terminal.
Key Takeaways
- Open the terminal and run sudo apt update followed by sudo apt install git to download and install Git.
- Verify the installation by typing git --version to see which version installed on your system.
- Configure your name and email address with git config commands before making your first commit.
- If you see a "command not found" error, the installation did not complete — run the install command again and check for error messages.
Opening the terminal and updating your package list
Start by opening the terminal. Press Ctrl + Alt + T on your keyboard, or click the Activities menu in the top left, type "terminal", and press Enter. A black window with a command prompt will open.
Before installing Git, update your package list so Ubuntu knows where to find the latest version. Type this command and press Enter:
sudo apt update
The system will ask for your password. Type it (you will not see the characters appear) and press Enter. This command refreshes the list of available software but does not install anything yet. It usually takes 10 to 30 seconds.
Installing Git with apt
Once the update finishes, install Git by typing this command and pressing Enter:
sudo apt install git
The terminal will show a list of files it is about to download and ask you to confirm. Type y and press Enter. The installation will run automatically. You will see lines of text scrolling past — this is normal. Wait until you see the command prompt return (a line ending with a dollar sign or hash mark).
The whole process usually takes one to three minutes depending on your internet speed. If the terminal appears to hang, do not close it — let it finish.
Verifying Git installed correctly
After the installation finishes, check that Git is working by typing this command and pressing Enter:
git --version
The terminal will print something like "git version 2.34.1" or a higher number. If you see this, Git is installed and ready to use. If you see "command not found" instead, the installation did not complete — scroll back through the terminal output to look for error messages in red text, then run the install command again.
If you see a permission error or a message about sudo, make sure you typed sudo at the start of the install command. The sudo prefix tells Ubuntu to run the command with administrator rights, which is required to install software.
Configuring your Git identity
Before you use Git to make commits, tell it who you are. Git records your name and email address with every change you save. Type these two commands, replacing the name and email with your own:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Press Enter after each command. These settings are stored on your computer and apply to every Git project you work on. You only need to set them once. If you want to use a different name or email for a specific project, you can run the same commands without the --global flag while inside that project's folder.
To verify your settings were saved, type this command and press Enter:
git config --global --list
You will see your name and email in the output, along with other Git settings.
Troubleshooting common installation problems
If you see "E: Unable to locate package git", your package list did not update properly. Run sudo apt update again and wait for it to finish completely before running the install command.
If the terminal says "Permission denied" or asks for a password repeatedly, make sure you typed sudo at the start of each command. The first time you use sudo, it will ask for your password. If you type it wrong, it will ask again — you get three tries before it stops.
If Git installed but the terminal still says "command not found" when you type git --version, close the terminal window completely and open a new one. Sometimes the terminal needs to restart to recognize newly installed programs.
What to do after installation
Once Git is installed and configured, you can start using it. Create a new folder for a project, open the terminal inside that folder, and type git init to start a new repository. Or, if you want to work with code that already exists, use git clone followed by the web address of the repository.
Git is now part of your system and will stay installed even after you restart your computer. If you ever need to update it to a newer version, run sudo apt update followed by sudo apt install git again — Ubuntu will upgrade it automatically.
Frequently Asked Questions
Do I need to use sudo to run Git commands after installation?
No. You only use sudo during installation. Once Git is installed, you run regular Git commands like git clone and git commit without sudo. Using sudo with Git commands can cause permission problems with your files.
Can I install Git without using the terminal?
The terminal is the standard way to install Git on Ubuntu. There is no graphical installer. However, once Git is installed, you can use graphical tools like GNOME Evolution or VS Code to work with repositories if you prefer not to type commands.
What if I want to uninstall Git later?
Type sudo apt remove git and press Enter. Confirm by typing y. This removes Git but leaves your project files untouched. Your repositories will still exist — you just will not be able to run Git commands on them until you reinstall.
Is there a newer version of Git available than what apt installs?
The version in Ubuntu's package repository is usually recent but may lag behind the absolute latest release by a few months. For most work, the apt version is sufficient. If you need the newest version, you can add the official Git repository to your system, but this is not necessary for learning or everyday use.
Can I install Git on other Linux systems the same way?
The steps are nearly identical on Debian and Linux Mint. On Fedora or Red Hat systems, use sudo dnf install git instead of apt. On Arch Linux, use sudo pacman -S git. The terminal commands differ, but the concept is the same.