How To Install Git on Ubuntu 16.04
- You need to run a server with any Ubuntu 16.04 LTS release.
- You should log in to SSH using the root user.
The first thing that should be done is to run general OS and package updates. On Ubuntu you can do that by executing the following command:
Then, after the general updates on the server have been run, you can start with the installation of Git.
apt-get install git
If you are asked to confirm the download of the installation; Just press Y to confirm. It is simple as that.
Confirm Git the installation
Once you are done with the main installation, you need to check and make sure that the executable file is set up and accessible. You can do this by running Git with the version command.
#git --version git version 2.17.0
How To Install Git from Source
Another way to install Git, which is more flexible, is to compile the software from source. This method takes more time and it won`t be maintained through the package manager, but you will get the chance to download the latest version and you will have the control over the options that can be included if you want to customize it.
Update and install the local package index
sudo apt-get update sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
When all the necessary dependencies are done and installed, you will be able to get the git version you want and you can do that by visiting the git project`s mirror on GitHub.
If you wish to get the latest stable version, all you have to do is to go and change the branch to the latest non-“rc” tag via the button along the left side of the project header:
Then, on the right side of the page, right-click the Download ZIP button and you need to copy the link address.
Now go back to the Ubuntu 16.04 server where you need to type wget and then to paste the copied address. Have in mind that the URL which you copied can differ from this example:
wget https://github.com/git/git/archive/v2.17.0.zip -O git.zip
The next step s to unzip the downloaded file and move it in the result directory by typing:
unzip git.zip cd git
At this point, by typing the following commands, you can create the package and install it:
make prefix=/usr/local all sudo make prefix=/usr/local install
Since you already installed git, you may want to upgrade it to its latest version, and that is quite simple – all you need to do is clone the repository (be sure that you have changed it to your home directory) and next build and install. Navigate to the branch in order to find the URL which you need to use for the clone operation or also you can tag the things you want on the project`s GitHub page and simply copy the clone URL on the right:
git clone URL
Once again, don`t forget to change to your home directory and use the already copied URL:
cd ~ git clone https://github.com/git/git.git
By taking these steps you will create new directory within the existing one and there you will be able to rebuild the packages and of course to reinstall the latest version. This is how your older version will be overwritten with the new version:
cd git make prefix=/usr/local all sudo make prefix=/usr/local install
Configure root user
Configure Git’s settings (for the root user)
Now you should set up your user for git in order to prevent some commit errors later. We’ll set up the user gituser with the e-mail address gituser@your_domain.com.
git config --global user.name "gituser" git config --global user.email "gituser@your_domain.com"
Verify the Config changes
At this point the configuration changes should be verified and that can be done by viewing the .gitconfigfile. This can be done in various ways and here you can see the methods.
You can use cat with the following command in order to view the config file:
You can also use the git config command in order to view the same details:
git config --list
And that’s it, now you have Git installed on your Ubuntu 16.04 server and you have also configured it on your root user. You can get rolling with your code changes from here, or you can repeat the steps for other system user accounts.