为Linux更换yum源

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

1.Redhat使用CentOS国内源

首先以root用户登录终端,执行以下命令:

1
[root@localhost Desktop]# cd /etc/yum.repos.d/

切换到yum源所在目录.

执行:

1
2
3
[root@localhost yum.repos.d]# ls
CentOS6-Base-163.repo  google.repo  rhel-source.repo
google-chrome.repo     redhat.repo

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

1
[root@localhost yum.repos.d]# mv redhat.repo redhat.repoOLD

//为避免错误,对所有源执行重命名.
*:也可以将其中的文件全部删除,但这样会对操作有风险.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#########################################################################
# 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
<strong>baseurl=http://mirrors.163.com/centos/6/os/$basearch/</strong>
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates - 163.com
<strong>baseurl=http://mirrors.163.com/centos/6/updates/$basearch/</strong>
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
<strong>baseurl=http://mirrors.163.com/centos/6/extras/$basearch/</strong>
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
<strong>baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/</strong>
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
<strong>baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/</strong>
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/文件夹下面:

搜狐:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[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

网易的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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来减少垃圾评论。了解我们如何处理您的评论数据