How to install Git on Ubuntu 24

To install Git on Ubuntu you need one apt command, and on many servers Git is already there. This guide is for Ubuntu 24.04 and 22.04. It covers the newer Git from the git-core PPA, the first setup every new machine needs and an SSH key for GitHub.

Install Git on Ubuntu with apt

Refresh the package list, install Git and check the version:

sudo apt update sudo apt install -y git git --version

Ubuntu 24.04 has Git 2.43.0, Ubuntu 22.04 Git 2.34.1. That is enough for everyday work, and the package gets security fixes with the system.

Get the latest Git from the git-core PPA

Ubuntu doesn’t move to new Git releases within one Ubuntu version. The git-scm.com download page points Ubuntu users to the PPA of the Ubuntu Git Maintainers team, which carries the latest stable Git. If Git from apt is installed, this updates it in place.

sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install -y git git --version

Set your name and email

Git writes a name and an email into every commit. Set them once for your user. Use the email of your GitHub or GitLab account, so the service links the commits to you. The last line makes main the first branch of new repositories.

git config --global user.name "Your Name" git config --global user.email "[email protected]" git config --global init.defaultBranch main git config --list

Put your own name and email in place of Your Name and [email protected]. The settings live in ~/.gitconfig. Run the same commands again to change them.

Connect to GitHub with an SSH key

GitHub doesn’t accept your account password when you push. The simplest way in is an SSH key. Create one with your GitHub email, start the SSH agent and add the key to it. ssh-keygen asks where to save the key (press Enter for the default) and for a passphrase: set one, it protects the key if someone copies the file.

ssh-keygen -t ed25519 -C "[email protected]" eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 cat ~/.ssh/id_ed25519.pub

The last command prints the public key, one line that starts with ssh-ed25519. Copy it and add it on GitHub:

  1. Click your profile picture in the upper-right corner of github.com and choose Settings.
  2. In the Access section of the sidebar, click SSH and GPG keys, then New SSH key.
  3. Type a Title such as the machine’s name, paste the line into Key and click Add SSH key.

Check the connection. The first time, SSH asks whether to trust github.com: type yes.

Look for You've successfully authenticated, but GitHub does not provide shell access. Clone repositories with the SSH address, [email protected]:user/repo.git.

If Git doesn’t work

  • Author identity unknown and Please tell me who you are. when you commit: the name and email aren’t set. Run the two commands for them above.
  • remote: Support for password authentication was removed on August 13, 2021.: GitHub wants an SSH key or a token, not the password. Set up the key, then switch the repository to SSH: git remote set-url origin [email protected]:user/repo.git
  • [email protected]: Permission denied (publickey).: GitHub doesn’t know this key. Check that the .pub line is in SSH and GPG keys on GitHub and that the agent has the key: ssh-add -l
  • add-apt-repository: command not found: install the tool that adds PPAs: sudo apt install -y software-properties-common

If you also work on a Mac

MacWashing, System Junk: Xcode junk, user caches, installers and logs found, 22.83 GB ready to be cleaned

System Junk in MacWashing finds the caches of every app it knows, including those hidden inside app data, plus logs, Xcode junk and leftovers of deleted apps. It shows how much each takes and clears them in one go. Anything debatable stays unchecked until you decide.

Free trial · macOS 14 or later

Questions and answers

How do I install Git on Ubuntu?

Run: sudo apt update && sudo apt install git For the latest version, add the git-core PPA first: sudo add-apt-repository ppa:git-core/ppa

Should I use HTTPS or SSH with GitHub?

Both work. Over HTTPS, GitHub asks for a personal access token instead of the password. An SSH key is set up once and then asks for nothing, so on your own machines it is simpler.

How do I update Git?

With the system: sudo apt update && sudo apt upgrade With the git-core PPA connected, that brings the newest release.