How to install Git on Linux (Ubuntu)
By Flavio Copes
Learn how to install Git on Linux Ubuntu with sudo apt install git, verify it with git --version, and set up your name, email, and editor with git config.
To install Git on Ubuntu, run sudo apt update followed by sudo apt install git. Two commands, and you’re done.
Let’s go through the process step by step, including the configuration you need before your first commit.
Install Git with apt
Open your terminal. First, update your package list:
sudo apt update
You may need to enter your password. This is a standard security measure.
Then install Git:
sudo apt install git
Ubuntu will download and install Git for you, along with its dependencies.
To verify the installation, type:
git --version
You should see something like:
git version 2.43.0
The exact number depends on your Ubuntu version. Ubuntu ships the Git version that was current when that release was frozen, so it’s often a bit behind the latest.
Configure your identity
Git records your name and email in every commit you make. Set them once, globally:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Replace “Your Name” and “youremail@example.com” with your actual details.
This step is not optional. If you skip it and try to commit, Git stops you with an error that says Please tell me who you are, and it prints those same two git config commands. Run them, then commit again.
If you use VS Code, you can set it as your default Git editor:
git config --global core.editor "code --wait"
This will open VS Code for commit messages and other Git operations that require text input. The --wait flag matters: it tells VS Code to keep Git waiting until you close the file, otherwise Git thinks you’re done immediately.
You can check everything you configured with:
git config --global --list
Start using Git
With Git installed, you can start version controlling your projects. Navigate to your project folder and run:
git init
This creates a new repository in that folder, stored in a hidden .git directory.
While Git may seem complex initially, it becomes an invaluable tool with practice. It’s widely used in software development for its version control capabilities.
Want to actually learn Git? Want to stop feeling frustrated with it? I created the Git Masterclass to solve this problem!