Installing Git, Curl, and Expat from Source

gitrhelsource

I have a RHEL 6.4 VM provisioned by my company's internal KVM.

We are having some trouble using yum (Cannot retrieve repository metadata, which I've confirmed in this case is peculiar to my company's internal cloud), so I have to build Git from source.

Downloading the RPM file and issuing

sudo yum localinstall ....rpm

Gives me the same Cannot retrieve repository metadata error.

Issuing

sudo rpm -ivh ....rpm

Fails with an error: Failed dependencies and then lists all the packages I need to install. I assume I could find the download links for all of them, but I've tried this before and was unable to find the download links for the right versions for the right packages.

The following code actually works, thanks to @slm's answer:

wget ftp://fr2.rpmfind.net/linux/dag/redhat/el6/en/x86_64/extras/RPMS/perl-Git-1.7.9.6-1.el6.rfx.x86_64.rpm
wget http://pkgs.repoforge.org/git/git-1.7.9.6-1.el6.rfx.x86_64.rpm
rpm -ivh perl-Git-1.7.9.6-1.el6.rfx.x86_64.rpm git-1.7.9.6-1.el6.rfx.x86_64.rpm

If I just download the git code, untar it, and build it, like:

wget https://www.kernel.org/pub/software/scm/git/git-1.8.5.tar.gz
tar -xvf git-1.8.5.tar.gz
cd git-1.8.5
./configure
make
make install

I receive the following error when cloning from the http:// protocol:

fatal: Unable to find remote helper for 'http'

Googling told me that I needed curl-devel and expat. I can not use yum, so I went and built those as well:

cd ..
wget http://curl.haxx.se/download/curl-7.34.0.tar.gz
tar -xvf curl-7.34.0.tar.gz
cd curl-7.34.0
./configure
make
make install

cd ..
wget http://downloads.sourceforge.net/expat/expat-2.1.0.tar.gz
tar expat-2.1.0.tar.gz
cd expat-2.1.0
./configure
make
make install

However, upon rebuilding Git, I receive the same error. After Googling more I determined that I needed to pass the following parameters to Git's ./configure:

cd git-1.8.5
./configure --with-curl=<curl_install_path> --with-expat=<expat_install_path> 

However, I couldn't determine where the curl and expat install paths were located.

So what I did instead was build Git, curl, and expat using the ./configure --prefix=/path/to/desired/install/path

mkdir curl
cd curl-7.34.0
./configure --prefix=/home/downloads/curl
...
mkdir expat
cd expat-2.1.0
./configure --prefix=/home/downloads/expat
...
mkdir git
cd git-1.8.5
./configure --prefix=/home/downloads/git --with-curl=/home/downloads/curl --with-expat=/home/downloads/expat
...

and from this I was able to clone with Git from the http protocol. However, this violates the Linux file structure.

Two Questions:

  1. When building Git from source, you need to include the curl and expat install paths to ./configure. Where are these install paths when installing curl and expat without the prefix argument?
  2. I learned that I needed curl and expat's install paths when I got an error and searched for it. Are there any other programs I need to tell Git so I don't get errors in the future?

Best Answer

I think I would suggest not installing these items from source directly but rather harness the power of your package manager to still maintain these packages.

locally installing

You can use a command line tool such as curl or wget to still download the packages necessary to install them either using yum or rpm directly.

$ sudo yum localinstall some.rpm
-or-
$ sudo rpm -ivh some.rpm

I would suggest looking to the repositories RepoForge as well as EPEL for RPMs. For example the git packages are here.

A simple command in the terminal will download it:

$ wget http://pkgs.repoforge.org/git/git-1.7.10.4-1.el6.rfx.x86_64.rpm

Rebuilding a source RPM

On the off chance you have to have the latest versions, you can still make use of RPMs but rather than download the .rpm version of a package, you'll want to get the .src.rpm version. These can be rebuilt using the following command:

$ rpmbuild --rebuild some.src.rpm

Rebuilding a tar.gz using a donor source RPM

You can also take your .tar.gz tarballs and reuse the .spec file that's included in the above .src.rpm. You do this through the following commands.

$ mkdir -p ~/rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}

Then create a ~/.rpmmacros file.

%packager Your Name
%_topdir /home/YOUR HOME DIR/rpm
%_tmppath /home/YOUR HOME DIR/rpm/tmp

Now we're ready to "install" the donor .src.rpm.

$ rpm -ivh some.src.rpm

This will deposit a tarball and a .spec file in your ~/rpm directories. You can then edit this .spec file and replace the tarball with the newer one.

Now to rebuild it:

$ rpmbuild -ba ~/rpm/SPECS/some.spec

This will create a .rpm and a new .src.rpm file once it's complete.

Additional tips

You can use the tool yum-builddep to make sure you have all the required RPMs installed before getting started.

$ sudo yum-builddep some.src.rpm
Related Question