How do I use RPM to install GCC from my CentOS distribution media?

I have a few package installation related questions concerning RPM, YUM and CentOS and getting GCC installed:

  1. I've mounted my distribution media on my CentOS 5.2 machine but I can't seem to work out how to point RPM at the media and use that instead of looking to the internet. All the examples I've googled for appear to assume downloading the RPM's from the internet.

  2. What does the -ivh switch combo do (I'm guessing -i is for install)? I did man rpm but the switch count and combinations blew my mind.

  3. Should I be using YUM instead of RPM?


Solution 1:

I'd recommend using yum localinstall rather than using the rpm command directly; that way you'll have the gcc package in your yum database so that it can keep track of updates. The command would just be:

yum localinstall /mnt/cdrom/CentOS/gcc-(whatever).rpm

Solution 2:

You want to use something like rpm -ivh /mnt/cdrom/CentOS/gcc-(whatever).rpm. The command line options there are:

  • -i -- install (you can use -U to install or upgrade, many just always use that)
  • -v -- verbose output
  • -h -- show hashmarks, a simplistic progress bar

Yum will figure out which package you mean if you type yum install gcc. That'll use your chosen repository, or the CD if you've got the correct repository installed (which you probably do). In general, yum is easier to use if you're not doing anything strange.

Solution 3:

There is probably already a repo defined in yum for the centos media that you can use that just needs to be enabled. The documentation included in the file shows you how you could disable all your remote repos, enable just the local media repo and install your software package from cd.

$ cat /etc/yum.repos.d/CentOS-Media.repo 
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
#  CentOS-5.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c5-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c5-media [command]

[c5-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Solution 4:

1 step rpm -ivh vsftpd.x86_64 0:2.2.2-7.rpm

2 step rpm -ivh createrepo-0.9.8-4.rpm

3 step copy every thing from DVD or .iso to /var/ftp/pub (cp -av /var/ftp/pub)

4 step createrepo -v /var/ftp/pub/

5 step vi /etc/yum.repos.d/base.repo

6 step

[base] name=Server Software baseurl=ftp://192.168.0.254/pub/ enabled=1 gpgcheck=0

7 step yum install gcc -y