Install packages in CentOS from DVD without connection to internet

I have a CentOS 6.4 system with no connection to internet. I have the installer DVD though. How can I install a package, say gcc, using this DVD alone?


Let us assume the ISO is already burnt into a DVD, or the ISO is present as a file on your file system. First, we need to mount it. The preferred mount point to mount it is /media/CentOS, because yum is configured to look for repositories from this location by default while installing packages from DVD. The steps below describe how to mount the ISO (whether present as a file or burnt into DVD) and install packages from the ISO.

  1. If you have the ISO burnt into a DVD, insert the DVD into the CentOS system. If the ISO is not burnt into a DVD, but present as a separate file on the file system, then skip the next two steps and go directly to step 4 in this list.
  2. Check if the DVD has been mounted automatically. To do this execute the following command:

    mount | grep CentOS
    

    If this command returns an output, it means the DVD has been mounted. For example, the following example output shows that the DVD has been mounted to /media/CentOS_6.4_Final automatically.

    /dev/sr0 on /media/CentOS_6.4_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)
    
  3. If the CD has been mounted automatically, then ignore this step. Otherwise, mount it manually.

    mkdir /media/CentOS
    mount -t iso9660 /dev/sr0 /media/CentOS
    
  4. If the ISO is present on the file system, mount it to /media/CentOS using the mount command with -o loop option.

    mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso /media/CentOS/
    
  5. Execute: cat /etc/yum.repos.d/CentOS-Media.repo and read the information provided as comments in this file. See the repo name within square brackets. It is c6-media by default. Also, see the locations specified for baseurl property. These URLs point to local directories /media/CentOS, /media/cdrom and /media/cdrecorder/ by default.

  6. If the DVD is mounted to a mount point specified in the baseurl property, then ignore this step. Otherwise, create a symbolic link at a location specified in the baseurl property with the mount point as its target. An example follows.

    ln -s /media/CentOS_6.4_Final /media/CentOS
    
  7. In the shell, execute the yum command while disabling all repos except the repo specified in /etc/yum.repos.d/CentOS-Media.repo:

    yum --disablerepo=\* --enablerepo=c6-media install gcc