最简单方式
更简单的操作,其实/etc/yum.repo.d/CentOS-Media.repo中有说明:
sudo mkdir -p /media/cdrom &&
sudo mount /dev/cdrome /media/cdrome &&
sudo yum --disablerepo=* --enablerepo=c5-media search gcc
每次都把其他源禁用,使用c5-media这个源就可以了。
其他方式
公司服务器是RHEL4,所以下了个Centos4的镜像,装上虚拟机发现有两个问题:
1. 安装时崩溃:VirtualBox添加虚拟机时不使用SATA硬盘,改为IDE硬盘,估计那个时候还没有SATA。
2. yum无效,因为RHEL4已经不维护了,所以需要将yum的源改为本地,但是改过之后还是不行,有两点要注意:
第一点,操作步骤:
[winlin@localhost ~]$ cd /etc/yum.repos.d/
[winlin@localhost yum.repos.d]$ sudo mv CentOS-Base.repo CentOS-Base.repo.bk
[winlin@localhost yum.repos.d]$ sudo cp CentOS-Media.repo winlin.cdrom.repo
[winlin@localhost yum.repos.d]$ sudo mv CentOS-Media.repo CentOS-Media.repo.bk
[winlin@localhost yum.repos.d]$ sudo vi winlin.cdrom.repo
将内容改为:
[c4-media]
name=CentOS-$releasever - Media
baseurl=file:///media/mnt/
gpgcheck=1
enabled=1
gpgkey=file:///usr/share/doc/centos-release-4/RPM-GPG-KEY-centos4
然后执行命令:
[winlin@localhost yum.repos.d]$ sudo mkdir -p /media/mnt
[winlin@localhost yum.repos.d]$ sudo mount /dev/cdrom /media/mnt/
最后更新yum:
[winlin@localhost yum.repos.d]$ sudo yum clean all
Cleaning up Everything
0 headers removed
0 packages removed
3 metadata files removed
0 cache files removed
1 cache files removed
[winlin@localhost yum.repos.d]$ sudo yum list
Setting up repositories
c4-media 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 611 kB 00:00
c4-media : ################################################## 1599/1599
第三点,一定要修改repo的 enabled=1
第四点,使用yum list时要用sudo,或者以root登录即可。
这样就可以安装了:
[winlin@localhost yum.repos.d]$ yum search subversion
Searching Packages:
Setting up repositories
Reading repository metadata in from local files
subversion-devel.i386 1.1.4-2.ent c4-media
Matched from:
subversion-devel
Development package for Subversion developers.
The subversion-devel package includes the static libraries and
include files for developers interacting with the subversion
package.
http://subversion.tigris.org/
subversion.i386 1.1.4-2.ent c4-media
Matched from:
subversion
Subversion is a concurrent version control system which enables one
or more users to collaborate in developing and maintaining a
hierarchy of files and directories while keeping a history of all
changes. Subversion only stores the differences between versions,
instead of every complete file. Subversion is intended to be a
compelling replacement for CVS.
http://subversion.tigris.org/