为Linux更换yum源

*:此方法与大部分Linux桌面系统兼容,不兼容方面请在评论中指明。

1.Redhat使用CentOS国内源

首先以root用户登录终端,执行以下命令:
[root@localhost Desktop]# cd /etc/yum.repos.d/
切换到yum源所在目录.

执行:
[root@localhost yum.repos.d]# ls
CentOS6-Base-163.repo google.repo rhel-source.repo
google-chrome.repo redhat.repo

//执行ls命令,即可查看所有内容
对于这些原本存在的文件,为了避免出现错误,我们可以对其进行重命名:

[root@localhost yum.repos.d]# mv redhat.repo redhat.repoOLD
//为避免错误,对所有源执行重命名.
*:也可以将其中的文件全部删除,但这样会对操作有风险.

下面就可以进行新创建的源文件了:
使用命令: vim 163.repo
然后将下面的内容粘贴到里面,请确认粗体部分的链接可以访问!!!(如:http://mirrors.163.com/centos/6/os/)

#########################################################################
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#########################################################################
然后执行命令: yum clean
yum makecache

就可以用了,配置完成后可以使用 : yum install mysql* 测试.

2.Fedora使用国内源

虽然Fedora自身提供了软件源,但速度还是不如人意,最近我就对Fedora的软件源进行了改造,将其原本的国外的源换成了网易和搜狐的源。

其方法基本与上面相同,下面这两个repo的文件是:Fedora 17 /32 的,可以直接放到/etc/yum.repos.d/文件夹下面:

搜狐:
[releases-mirror.sohu.com]
name=fedora-sohu-releases
baseurl=http://mirrors.sohu.com/fedora/releases/17/Fedora/i386/os/
enabled=1
gpgcheck=0

[everything-mirror.sohu.com]
name=fedora-sohu-Everything
baseurl=http://mirrors.sohu.com/fedora/releases/17/Everything/i386/os/
enabled=1
gpgcheck=0

[updates-mirror.sohu.com]
name=Fedora-sohu-updates
baseurl=http://mirrors.sohu.com/fedora/updates/17/i386/
enabled=1
gpgcheck=0

网易的:
[Fedora-mirrors.163.com]
name=Fedora 17 – i386
baseurl=http://mirrors.163.com/fedora/updates/17/i386/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY
[Everything-mirrors.163.com]
name=Everything 17 – i386
baseurl=http://mirrors.163.com/fedora/updates/17/i386/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY
[updates-mirrors.163.com]
name=Fedora updates
baseurl=http://mirrors.163.com/fedora/updates/17/i386/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY

然后执行命令: yum clean
yum makecache
就可以使用了,配置了两个国内源速度刷刷的啊。。。

《为Linux更换yum源》上有3条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据