How to Install Git on Amazon Linux 2 Instance

How to Install Git on Amazon Linux 2 Instance

How to Install Git on Amazon Linux 2 Instance

Dear Reader, I hope you are doing well today. In my today’s post, I am here to help you install Git on Amazon Linux 2(AL2) EC2 Instance.

You can also check out my other post to install Nginx, Apache, Java, Docker, Ansible, PHP 8.1, PHP 8.2 etc. on Amazon Linux 2.

After the installation, we will do some basic configurations like setting up name/email etc. Finally, we’ll set up our first git repository on the Amazon Linux 2 EC2 Instance.

So are you ready?

Alright !!!

Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.

Let’s get to know a little bit about Amazon Linux 2 and Git.

Background

Amazon Linux 2: 

  • Amazon Linux 2 is a Linux operating system from Amazon Web Services (AWS).
  • You can install software on Amazon Linux 2 using the yum package manager.
  • Usually, you can find stable versions of the software on the Amazon Linux 2 core repository. And you can install using the yum install package-name command.
  • looking for newly released software? Look for it in amazon-Linux-extras repository.
  • When writing this post, Nginx is available in amazon-linux-extras repository and we will install it from there only on Amazon Linux 2.

About Git: 

Git is a very popular open-source distributed version control system-

  • It is a widely used version control system in the world.
  • It makes collaboration on a project easier.
  • Git is very fast and you can use it in applications of any grade without performance issues.
  • It has a very active community so you will get support as and when needed

Having Git on Amazon Linux 2

If you hit the command yum search git in an Amazon Linux 2 system, you will get a response like below-

How to Install Git on Amazon Linux 2 Instance 1

If you look closely, you will notice git.x86_64 : Fast Version Control System as shown in the above screenshot. That means it is available in the Amazon Linux 2 core repository. And, you can install it by using sudo yum install git -y command.

You can also verify it by running yum info git command as shown below-

How to Install Git on Amazon Linux 2 Instance 2

Now you know the one-liner command to install Git on Amazon Linux 2 EC2 instance. However, for the sake of the completeness of this tutorial, I will give step by step guide below on how to install it on the system and set it up.

Prerequisite

Steps to Install Git on Amazon Linux 2 Instance

These are the steps to install Git on an Amazon Linux 2 EC2 instance. I have broken it into small steps to keep it very simple.

  1. Create an Amazon Linux 2 EC2 Instance
  2. Connect to your EC2 Instance
  3. Run System Update
  4. Install Git using sudo yum install git
  5. Verify Git Installation
  6. Configure Basic Details
  7. Setup a Simple Git Repo

Step 1: Create an Amazon Linux 2 EC2 Instance

Before you install Git on your Amazon Linux EC2 instance, you need one up and running. If you already have one, you can go to step 2 directly.

If not, read my previous tutorial on How to Launch an EC2 Instance with Amazon Linux 2 AMI and create an Amazon Linux 2 EC2 instance.

Step 2: Connect to Your EC2 Instance

Once your instance is up and running, select your instance and click connect as shown below.

How to Install Nginx on Amazon Linux 2 Instance 2

Select the EC2 Instance Connect tab, make sure the user name is ec2-user and then click Connect.

A new browser window opens and you should be inside your EC2 instance as seen below within no time.

How to Install Nginx on Amazon Linux 2 Instance 4

Very good. Let’s proceed to install Git on our Amazon Linux 2 EC2 instance.

Step 3: Run System Update

Just after we connected to our instance, in the terminal we got a response like a package update available, run sudo yum update.

To be honest, before installing any software on your instance, you should always run a system update to ensure all the packages/software are latest.

Run the below command to update all the packages

sudo yum update

Once you are done with the update, move on to the next step.

Step 4: Install Git using sudo yum install git -y

As I told you earlier, Git is available on Amazon Linux 2 core repository. So you can install it using yum

sudo yum install git -y

Command Breakdown-

Here is a breakdown of the command:

  • sudo – This tells the system to run the command as root.
  • yum – This is the package manager for CentOS and other RPM-based Linux distributions.
  • install – This is the command to install a package.
  • git – This is the name of the package that contains the Git software.
  • -y – This option tells yum to automatically answer yes to any prompts.

As soon as you hit enter, git and its dependencies get installed as seen below-

How to Install Git on Amazon Linux 2 Instance 3

Step 5: Verify Git Installation

You can run git –version to verify the git installation.

git --version

Once you type git –version and hit enter, it shows you the version of git that you just installed.

How to Install Git on Amazon Linux 2 Instance 4

Amazing !!!

You have successfully installed Git on Amazon Linux 2 EC2 Instance.

In case you would like to know the location Git was installed, you can fire the below command-

which git

Step 6: Basic Git Configuration

Configuring your Git username/email is very important for traceability on who is doing what changes. After setting up the name/email, every change/commit you do will have this name and email. Use the below set of commands to set a name and email –

$ git config --global user.name "Preeti Jha"
$ git config --global user.email "pj@cloudkatha.com"

Note: Make sure to replace my name/email with your own.

Step 7: Setup a Simple Git Repo

Create a folder, navigate inside the folder and fire git init to initialize a git repository.

mkdir cloudkatha
cd cloudkatha
git init
How to Install Git on Amazon Linux 2 Instance 5

Some Important Git Commands-

Here are some important Git commands:

  • git init: Initialize a new Git repository.
  • git add: Add files to the staging area.
  • git commit: Commit changes to the repository.
  • git status: Show the status of the working directory and the staging area.
  • git log: Show the commit history of the repository.
  • git checkout: Switch branches or checkout a specific commit.
  • git merge: Merge changes from one branch into another branch.
  • git push: Push changes to a remote repository.
  • git pull: Fetch changes from a remote repository and merge them into the current branch.

These are just a few of the most important Git commands. There are many other commands available, and you can find more information in the Git documentation.

Conclusion

In this how-to guide, you learn how to install Git on Amazon Linux 2 Instance.

We roughly did these things in this tutorial-

  • I learned a bit about Amazon Linux 2 and Git
  • Created an Amazon Linux 2 EC2 and connected to it.
  • Install Git on our EC2
  • Configured Git and Initialized the First Git repository.

Were you able to install Git on Amazon Linux 2 Instance using this tutorial? Let me know in the comment section.

Enjoyed the content?

Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.

Don’t forget to motivate us-

Suggested Read:

Leave a Reply

Your email address will not be published. Required fields are marked *