yum工具

yum使用

yum 命令:

介绍:CentOS中下载软件

格式:yum [option] xx.rpm

用法:

  • list :罗列可安装的rpm包 ,是在配置文件/etc/yum.repos.d/中yum源定义的

       @base :本机已安装
    
    base : 未安装
    
       install :安装
  • yum install -y name : 安装包,-y不加询问,默认为y ,--downloadonly 保存下载的包但不安装

  • search 'vim' :搜索可安装的包

  • remove 'vim':卸载

  • update|upgrade :升级包

  • groupinstall “英文套件名” :安装套件

  • groupremove :卸载套件

  • yum provides "/*/vim":搜索vim命令的源码包

使yum保留下载的rpm包

修改/etc/yum.conf

[main]

cachedir=/dir/ 指定保存目录

keepcache=1 保存已经下载的rpm包

debuglevel=2

还有一种就是使用--download选项,配合--downloaddir 指定保存的路径。

[root@localhost ~]# yum install -y --downloadonly python36.x86_64 --downloaddir .

查看linux中命令的依赖:

[root@localhost ~]# ldd /bin/ls
        linux-vdso.so.1 =>  (0x00007ffc66bfa000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb9a75da000)
        libcap.so.2 => /lib64/libcap.so.2 (0x00007fb9a73d5000)
        libacl.so.1 => /lib64/libacl.so.1 (0x00007fb9a71cc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fb9a6dff000)
        libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb9a6b9d000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fb9a6999000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb9a7801000)
        libattr.so.1 => /lib64/libattr.so.1 (0x00007fb9a6794000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb9a6578000)

搭建yum本地源

1.先挂载ios文件

[root@localhost ~]# mount /dev/cdrom /mnt

2.编辑本地的配置文件

[root@localhost ~]# vim CentOS-Media.repo

[c6-media]

name=CentOS-$releasever - Media #源的名称

baseurl=file:///mnt/ #源的路径

gpgcheck=0 #是否检测

enabled=1 #是否启用

3.清理软件

[root@localhost ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost ~]#

4.建立缓存

[root@localhost ~]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.cqu.edu.cn
base                                                                                                        | 3.6 kB  00:00:00     
extras                                                                                                      | 3.4 kB  00:00:00     
updates                                                                                                     | 3.4 kB  00:00:00     
(1/5): extras/7/x86_64/prestodelta                                                                          |  68 kB  00:00:00     
(2/5): base/7/x86_64/other_db                                                                               | 2.5 MB  00:00:00     
(3/5): extras/7/x86_64/other_db                                                                             | 111 kB  00:00:00     
(4/5): updates/7/x86_64/other_db                                                                            | 381 kB  00:00:00     
updates/7/x86_64/prestodelta   FAILED                                          
http://mirrors.shu.edu.cn/centos/7.5.1804/updates/x86_64/repodata/705037c90b79530cfd21a44ddde821a90ede3e29a4c24768656b1881b61e033c-prestodelta.xml.gz: [Errno 14] curl#7 - "Failed connect to mirrors.shu.edu.cn:80; Connection refused"
正在尝试其它镜像。
(5/5): updates/7/x86_64/prestodelta                                                                         | 409 kB  00:00:00     
元数据缓存已建立
[root@localhost ~]# yum list

yum更换国内源

CentOS系统中yum的源默认是国外的,但国内有墙的关系访问会比较慢,所以可以将yum的源地址换成国内的,如163

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-163.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.163.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.163.org/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.163.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.163.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.163.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.163.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.163.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.163.org/centos/RPM-GPG-KEY-CentOS-7

或者直接下载网上的源文件

[root@localhost ~]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost ~]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo # 需要先安装wget包

yum安装扩展源

[root@localhost ~]# yum install -y epel-release

最后更新于

这有帮助吗?