How to Install Git on Ubuntu 22.04 and 24.04
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 includes Ubuntu 22.04 LTS as a supported OS. The Managed VPS 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.
Step 2: Install Git
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:
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.email “[email protected]”
Verify the configuration:
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
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:
4b. Display your public key
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
Expected output: Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.
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 [email protected]:yourusername/your-repo.git
The repository will clone into a directory named after the repo. Navigate into it and confirm the remote configuration:
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
Add a block for each host identity:
Generate the second key pair with a different filename:
Add id_ed25519_client.pub to the client’s GitHub or GitLab account under their deploy keys.
Use the alias when cloning
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:
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:
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 covers the full VPS setup workflow from provisioning through deployment.


