A Beginners Guide To Installing Software Using GIT

Was this page helpful?

This guide is deliberately going to be fairly simple and the point of the guide is to show how you get software from the GIT repositories, how you can compile and install it and how to amend the code to make it your own.

Why Would You Want To Use GIT?

Most distributions have repositories teeming with software so why on earth would you want to download and install it from GIT.

In a video and written review of Solus earlier this week, I noted that the main problem with Solus is that there isn't much software in the repositories and whilst most mainstream distributions have everything covered there may come a time when you would like to install a more up to date package than your package manager provides.

You may also be a budding young software developer (or old in my case) who wants to download, edit and compile programs.

How To Find Programs Using GIT

Visit https://github.com/explore and then use the see all link to browse all the available repositories. You can now search by the various categories to look for applications you want to download and have a go at changing, compiling and installing.

If you already know the name of the program you want to change then you can use the search bar at the top of the page.

Cloning A Git Repository

To actually download an application you do something called cloning. The procedure is actually very simple and I am going to demonstrate with the use of the small command line program called cowsay which is used to display a message as a speech bubble from an ASCII cow.

If you search for cowsay via the git search tool you will notice that there are a number of versions available.

 

I decided to go for the first one which takes you to this page: https://github.com/schacon/cowsay. This version uses a perl version of cowsay.

You will need to have git installed on your system. You can get this from your distribution's repositories.

To clone the cowsay repository the following command is required:

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

The git command runs git, the clone command clones the repository onto you computer and the last part is the address to the project you wish to clone which should appear in your address bar.

Working Out How To Compile And Install The Code

Before hacking away at the code it is worth installing 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 make file whereas the cowsay project you have just downloaded simply requires you to run a shell script.

So how do you know what to do?

In the folder where you ran the git command, there should now be a folder with the package you cloned. For example, in my case I downloaded cowsay and there is now a /home/gary/cowsay folder.

If you navigate to the cowsay folder using the cd command and then do a directory listing you should hopefully see either a file called README or a file called INSTALL or something that stands out as a help guide.

In the case of cowsay, there was both a README and an INSTALL file. The README file shows how to use the software whereas the INSTALL file tells me what I need to do to install cowsay.

All I have to do to install cowsay is 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.

It might be that the script fails due to lack of permissions in which case you can use the sudo command to elevate your privileges or run the su command to switch to an account with more privileges.

How To Run Cowsay

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

cowsay hello world

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

Changing Cowsay

I am going to show you how to simply amend cowsay to make it do something different to what it did before.

In the cowsay folder is a file called cowsay. You can edit cowsay in your favorite editor. I used the nano editor as follows:

nano cowsay

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.

My change is simply going to create a cyclops option so that when you type cowsay -c the cow has a single eye.

The first line that I 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. I was the -c to be an option so I changed the line as follows:

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

Between lines 51 and 58 you will 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]';

I needed to add one for the -c switch 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 = ".."; }
}

As you can see for each of the variables specified earlier there is a different pair of letters which is placed in the variable $eyes.

I needed to add one for the $cyclops variable which I did as follows:

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 = "()"; }
}

That is all I had to change. I saved the file and ran the following command to reinstall cowsay.

sh install.sh

Running cowsay -c hello world now looks like the image above.

Updating The Manual

This is all well and good but if anybody else decided to run cowsay on my system they might read the manual entry only to find that there is no cyclops switch.

In the cowsay folder, there is a file called cowsay.1. I edited this file and changed line 27 to show that you can use c as a switch as well.

Summary

This guide is very simplistic. It shows how to get a project from git, how to work out how to install the software and a little bit about changing the code.

You, of course, need to know a little bit about programming in order to amend program code but hopefully, this guide has at least put you on the right course.