---
title: "How to Install Git on Ubuntu 22.04 and 24.04"
description: "Git is available in Ubuntu's default package repositories on both 22.04 LTS and 24.04, so installation is fast. The more involved part is configuring SSH key authentication for GitHub or GitLab, which is what this guide covers in full. You'll also find a section on managing multiple Git identities on a single server, which comes up frequently in shared development environments and VPS deployments."
url: https://www.inmotionhosting.com/blog/how-to-install-git-on-ubuntu/
date: 2026-03-24
modified: 2026-03-24
author: "Sam Page"
categories: ["Tips and Advice"]
type: post
lang: en
---

# How to Install Git on Ubuntu 22.04 and 24.04

![How to Install Git on Ubuntu 22.04 and 24.04](https://www.inmotionhosting.com/blog/wp-content/uploads/2026/03/How-to-Install-Git-on-Ubuntu-22.04-and-24.04-1024x538.png)

Git is available in Ubuntu’s default package repositories on both 22.04 LTS and 24.04, so installation is fast. The more involved part is configuring SSH key authentication for GitHub or GitLab, which is what this guide covers in full. You’ll also find a section on managing multiple Git identities on a single server, which comes…

## **Prerequisites**

- A Linux VPS or cloud server running Ubuntu 22.04 LTS or Ubuntu 24.04
- SSH access with sudo privileges
- A GitHub or GitLab account (for the SSH key configuration steps)

Both Ubuntu 22.04 LTS and 24.04 ship with OpenSSH client pre-installed. No additional tools are required before beginning.

Not set up on a VPS yet? [InMotion Hosting’s Cloud VPS](https://www.inmotionhosting.com/cloud-vps) includes Ubuntu 22.04 LTS as a supported OS. The [Managed VPS](https://www.inmotionhosting.com/vps-hosting) supports Ubuntu across all plan tiers.

## **Step 1: Update Package Lists**

Before installing any package, sync your apt package index to ensure you’re pulling the latest available version.

sudo apt update

```
sudo apt update
```

## **Step 2: Install Git**

sudo apt install git -y

```
sudo apt install git -y
```

The -y flag confirms the installation automatically. On Ubuntu 22.04, this installs Git 2.34.x. On 24.04, you’ll get Git 2.43.x. To verify the installed version:

git --version

```
git --version
```

Expected output will look similar to: git version 2.43.0

## **Step 3: Configure Your Git Identity**

Git requires a name and email address attached to every commit. Set these globally for the server user you’ll be working with.

git config --global user.name "Your Name"

git config --global user.email "you@yourdomain.com"

```
git config --global user.name "Your Name"

git config --global user.email "you@yourdomain.com"
```

Verify the configuration:

git config --list

```
git config --list
```

## **Step 4: Set Up SSH Key Authentication**

Cloning and pushing to remote repositories over HTTPS requires a password or token on every operation. SSH keys authenticate once and never prompt again. This is the standard approach for server-to-repository authentication.

### **4a. Generate the SSH key pair**

ssh-keygen -t ed25519 -C "you@yourdomain.com"

```
ssh-keygen -t ed25519 -C "you@yourdomain.com"
```

The -t ed25519 flag specifies the Ed25519 algorithm, which is the modern recommended key type. When prompted for a file location, press Enter to accept the default (~/.ssh/id_ed25519). Optionally set a passphrase.

If your remote service requires RSA (older GitLab instances, for example), use:

ssh-keygen -t rsa -b 4096 -C "you@yourdomain.com"

```
ssh-keygen -t rsa -b 4096 -C "you@yourdomain.com"
```

### **4b. Display your public key**

cat ~/.ssh/id_ed25519.pub

```
cat ~/.ssh/id_ed25519.pub
```

Copy the entire output, including the ssh-ed25519 prefix and the comment at the end.

### **4c. Add the key to GitHub or GitLab**

On GitHub: Settings > SSH and GPG keys > New SSH key. Paste your public key and give it a descriptive title (for example, ‘InMotion VPS production’).

On GitLab: User Settings > SSH Keys. Paste the key, give it a title, and set an expiration date if your security policy requires one.

### **4d. Test the connection**

ssh -T git@github.com

```
ssh -T git@github.com
```

Expected output: Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

ssh -T git@gitlab.com

```
ssh -T git@gitlab.com
```

Expected output: Welcome to GitLab, @username!

## **Step 5: Clone a Repository**

With SSH authentication configured, cloning uses the SSH URL rather than HTTPS.

git clone git@github.com:yourusername/your-repo.git

The repository will clone into a directory named after the repo. Navigate into it and confirm the remote configuration:

cd your-repo && git remote -v

```
cd your-repo && git remote -v
```

## **Managing Multiple Git Identities on One Server**

Development VPS environments frequently need to authenticate as different users for different repositories. A developer account for personal projects, a CI deploy key for a client’s repository, a separate identity for work. The SSH config file handles this cleanly.

### **Create a per-host SSH config**

nano ~/.ssh/config

```
nano ~/.ssh/config
```

Add a block for each host identity:

Host github-personal  HostName github.com  User git  IdentityFile ~/.ssh/id_ed25519Host github-client  HostName github.com  User git  IdentityFile ~/.ssh/id_ed25519_client

```
Host github-personal  HostName github.com  User git  IdentityFile ~/.ssh/id_ed25519Host github-client  HostName github.com  User git  IdentityFile ~/.ssh/id_ed25519_client
```

Generate the second key pair with a different filename:

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_client -C "deploy@clientdomain.com"

```
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_client -C "deploy@clientdomain.com"
```

Add id_ed25519_client.pub to the client’s GitHub or GitLab account under their deploy keys.

### **Use the alias when cloning**

git clone git@github-client:clientorg/their-repo.git

```
git clone git@github-client:clientorg/their-repo.git
```

SSH resolves github-client to github.com and uses the specified key file. This approach works without any conflict between identities, even on the same physical server.

## **Setting a Default Branch Name**

Git’s default branch name changed from ‘master’ to ‘main’ in newer configurations, but repositories created on older setups may still use ‘master’. To align your server’s Git behavior with your team’s convention, set the default branch name globally:

git config --global init.defaultBranch main

```
git config --global init.defaultBranch main
```

## **Optional: Install a Newer Version via PPA**

Ubuntu’s default repositories may not include the absolute latest Git release. If you need a newer version for specific features, the Git Maintainers PPA provides current builds for Ubuntu LTS releases:

sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt install git

```
sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt install git
```

This is optional for most use cases. The version in Ubuntu’s default repos is stable and sufficient for the vast majority of workflows.

Related guide: [How to Setup a VPS Server](https://www.inmotionhosting.com/blog/how-to-setup-vps-server/) covers the full VPS setup workflow from provisioning through deployment.

| **Run Git on production-ready infrastructure. InMotion’s Cloud VPS includes Ubuntu 22.04 LTS with root SSH access, high-availability architecture, and no-nonsense pricing. See plans at inmotionhosting.com/cloud-vps.** |
| --- |
