Everything Beginners Should Know About Installing Software Using GIT

How to work with Git software repositories

Open-source Git is the most used version control system in the world. The mature project was developed by Linus Torvalds, the creator of the Linux operating system, and it is used by an enormous collection of software projects—both commercial and open-source—that depend on Git for version control.

This guide shows how to get a project from Git, how to install the software on your system and how to change the code, which requires knowledge of programming.

Illustration of a person working on computer
VVadyab / Getty Images

How to Find Programs Using Git

Visit the explore webpage at GitHub to see the featured and trending repositories as well as links to guides and training. Look at the various categories for applications you want to download and have a go at using, changing, compiling and installing. Use the search field at the top of your screen where you can find a specific program or any category of software available on the site. 

An Example of Cloning a Git Repository

In Git terminology, downloading a repository is "cloning" it. That's because you're making an exact copy of the Git repository on your computer. The procedure is simple, but you must have Git installed on your system.

If you're working on a Linux system, like Ubuntu, you're in luck. Git is available in your distribution's package repositories. Install it the way you normally would any other application. Nearly every distribution calls the package 'git.'

Git is free and open source, so it won't cost you a penny on any platform. Windows users can find the latest version on the Git Windows download page. Mac users can find it on the Git for Mac download page.

This guide will use the small command line program called cowsay, which displays a message as a speech bubble from an ASCII cow.

To start, type cowsay in the GitHub search field. You will notice that there are a number of versions available you can choose. The example in this guide is going to work one from the developer "Schacon." It's a fairly simple version written in Perl, so it should be relatively easy to work with and modify.

GitHub page cowsay

To clone this particular cowsay repository, enter the following command into a terminal window.

 git clone https://github.com/schacon/cowsay.git

The git command runs Git. Then, it's told to clone a repository, and the link to the Cowsay repository on GitHub is provided. You can find the Git clone link on GitHub under Clone or download, just above the table displaying the contents of a repository.

Git clone repository

How to Compile and Install the Code

Install the application first just to make sure it runs. How you do this depends on the project you have downloaded. For example, C projects will probably require you to run a makefile with the make command, whereas the cowsay project in this example requires you to run a shell script.

So how do you know what to do?

You just cloned the repository into whichever directory you were in when you ran the 'clone' command. Everything from the repository will be in a new directory named after that repository. In this case, it's cowsay. Chanage directories into the cowsay folder, and list out its contents.

cd cowsay
ls

You should see either a file called README or a file called INSTALL or something that stands out as a help guide.

Git repository directory listing

In the case of this cowsay example, there is both a README and an INSTALL file. The README file shows how to use the software, and the INSTALL file gives the instructions to install cowsay. In this case, the instruction is to run the following command:

sh install.sh

During the installation, you are asked whether you are happy for it to install cowsay to the default folder supplied. You can either press Return to continue or enter a new path. Should you want the default path, you'll probably need to rerun the command with 'sudo.'

Cowsay install from Git

How to Run Cowsay

All you have to do to run cowsay is type the following command:

cowsay hello world

The words hello world appear in the speech bubble from a cow's mouth.

Cowsay hello world

Changing Cowsay

Now that you have cowsay installed, you can amend the file using your favorite editor. This example uses the nano editor as follows:

nano cowsay
Cowsay configuration file

You can supply switches to the cowsay command to change the eyes of the cow.

For example cowsay -g shows dollar signs as the eyes.

You can amend the file to create a cyclops option so that when you type cowsay -c the cow has a single eye.

The first line you need to change is line 46 which looks as follows:

getopts('bde:f:ghlLnNpstT:wW:y', \ %opts);

These are all the available switches that you can use with cowsay. To add the -c as an option, change the line as follows:

getopts('bde:f:ghlLnNpstT:wW:yc', \ %opts);

Between lines 51 and 58 you see the following lines:

$borg = $opts{'b'};
$dead = $opts{'d'};
$greedy = $opts{'g'};
$paranoid = $opts{'p'};
$stoned = $opts{'s'};
$tired = $opts{'t'};
$wired = $opts{'w'};
$young = $opts{'y'};

As you can see, there is a variable for each of the options that explains what the switch will do. For example $greedy = $opts['g]';

Add one line for the -c switch amendment as follows:

$borg = $opts{'b'};
$dead = $opts{'d'};
$greedy = $opts{'g'};
$paranoid = $opts{'p'};
$stoned = $opts{'s'};
$tired = $opts{'t'};
$wired = $opts{'w'};
$young = $opts{'y'};
$cyclops = $opts{'c'};

On line 144, there is a subroutine called construct_face which is used to construct the cows face.

The code looks like this:

sub construct_face {
  if ($borg) { $eyes = "=="; }
  if ($dead) { $eyes = "xx"; $tongue = "U "; }
  if ($greedy) { $eyes = "\ $\ $"; }
  if ($paranoid) { $eyes = "@@"; }
  if ($stoned) { $eyes = "**"; $tongue = "U "; }
  if ($tired) { $eyes = "--"; }
  if ($wired) { $eyes = "OO"; }
  if ($young) { $eyes = ".."; }
}

For each of the variables specified earlier, there is a different pair of letters that is placed in the variable $eyes.

Add one for the $cyclops variable :

sub construct_face {
  if ($borg) { $eyes = "=="; }
  if ($dead) { $eyes = "xx"; $tongue = "U "; }
  if ($greedy) { $eyes = "\ $\ $"; }
  if ($paranoid) { $eyes = "@@"; }
  if ($stoned) { $eyes = "**"; $tongue = "U "; }
  if ($tired) { $eyes = "--"; }
  if ($wired) { $eyes = "OO"; }
  if ($young) { $eyes = ".."; }
  if ($cyclops) { $eyes = "()"; }
}

Saved the file and run the following command to reinstall cowsay.

sh install.sh

Now, when you run cowsay -c hello world, the cow has only one eye.

Cowsay modified cow