How to install Git on Ubuntu
Git installs on Ubuntu through the terminal using a single command, and takes less than a minute. Open your terminal (press Ctrl+Alt+T), type sudo apt update and press Enter, then type sudo apt install git and press Enter again. When prompted, type your password and press Enter. Ubuntu will read and install Git automatically.
After installation finishes, verify it worked by typing git --version and pressing Enter. You should see a version number like "git version 2.34.1" or higher. If you see that, Git is ready to use.
The reason Ubuntu uses this "apt" method is that it keeps Git updated automatically when you update your system. This beats downloading from a website because you get security fixes without thinking about it.
Key Takeaways
- Git installs in Ubuntu through the terminal with two commands: sudo apt update followed by sudo apt install git.
- You must type your password when prompted — this is normal and expected on Ubuntu.
- After installation, type git --version to confirm Git is working and see which version you have.
- Before you can use Git to save your first project, you need to tell Git your name and email address with two configuration commands.
Opening the terminal and running the update command
The terminal is where you type commands directly to Ubuntu. Press Ctrl+Alt+T to open it. A black or white window will appear with a blinking cursor and a line that ends with a dollar sign ($) or hash mark (#).
Type exactly this: sudo apt update. The word "sudo" means "do this as an administrator." Press Enter. Ubuntu will ask for your password — the one you use to log in. Type it (you will not see the letters appear, which is normal) and press Enter again.
Ubuntu will read a list of available software updates. This takes a few seconds to a minute depending on your internet speed. When it finishes, you will see the cursor and dollar sign again, ready for the next command.
Installing Git with the apt install command
Now type: sudo apt install git and press Enter. Ubuntu will show you a list of files it is about to read and ask "Do you want to continue? [Y/n]". Type the letter Y (capital or lowercase both work) and press Enter.
Ubuntu downloads Git and installs it. This usually takes 10 to 30 seconds. When it finishes, you will see the cursor again. Git is now on your computer and ready to use.
If you see an error message that says "E: Could not open lock file" or "Permission denied," it usually means another program is updating Ubuntu at the same time. Wait a minute and try the command again.
Verifying Git installed correctly
Type git --version and press Enter. Git will print a line showing which version you have, like "git version 2.34.1" or "git version 2.43.0". Any version number means Git installed successfully.
If you see "command not found" instead, the installation did not complete. Go back and run sudo apt install git again, making sure you pressed Enter after each command and typed Y when asked to continue.
Configuring Git with your name and email
Before you use Git to track your first project, you need to tell Git who you are. This information gets attached to every change you save, so other people (or you, months later) know who made each change.
Type this command, replacing "Your Name" with your actual name: git config --global user.name "Your Name". Press Enter. Then type this command, replacing the email address: git config --global user.email "your.email@example.com". Press Enter again.
These commands do not print anything back — they just store your information. That is normal. You only need to run these two commands once on your computer, ever. After this, every project you create with Git will know who you are.
Troubleshooting common installation problems
If sudo apt update fails and says "Unable to locate package," your Ubuntu system may not have access to the standard software repositories. This is rare on a fresh Ubuntu installation. Restart your computer and try again.
If you get "sudo: command not found," you are not in a real terminal — you may be in a restricted shell or a different tool. Close the window and press Ctrl+Alt+T again to open the actual Ubuntu terminal.
If the installation seems to hang (nothing happens for more than two minutes), your internet connection may have dropped. Press Ctrl+C to stop the command, check your internet, and run sudo apt install git again.
What to do after Git is installed
Git is now ready, but it does not do anything by itself — you use it by typing commands in the terminal. The next step is to create a folder for a project, move into that folder, and run git init to tell Git to start tracking changes in that folder.
You can also clone an existing project from a website like GitHub by typing git clone followed by a project address. This downloads a complete copy of someone else's project to your computer, including its entire history of changes.
Most people learn Git by doing one of these two things: starting their own project or copying an existing one. Both use the same Git commands underneath, so either path teaches you what you need to know.
Frequently Asked Questions
Do I need to use sudo for every Git command?
No. You only use sudo for the installation command. Once Git is installed, you type regular Git commands like git init or git clone without sudo. The sudo was only needed to install software system-wide.
Can I install Git on Ubuntu without using the terminal?
The terminal is the standard way on Ubuntu. Some graphical software managers exist, but they are slower and less reliable. Learning the terminal command takes two minutes and works the same way every time.
What if I already have Git installed but want to update it?
Run sudo apt update followed by sudo apt upgrade. Ubuntu will check if a newer version of Git exists and install it if one is available. You do not need to uninstall the old version first.
Is it safe to type my password in the terminal?
Yes. When you type your password after sudo, Ubuntu hides what you type (you will not see letters appear). This is a security feature. Type carefully and press Enter when done.
Can I use Git on Ubuntu if I do not have administrator access?
If you cannot use sudo, you cannot install Git system-wide. You would need to ask your system administrator to install it for you, or use a different computer where you have full access.