yum命令

用途

yum(Yellowdog Updater Modified),RedHat系Linux操作系统包管理器,基于rpm,从源远程仓库下载rpm包安装,同时解决依赖关系,使用Python语言编写。除了安装,还可以更新,卸载,查询软件包等。

用法

yum [options] [command] [package ...]

常用命令列表

install

安装源仓库包

update

更新软件包,没有指定包,会更新所有已安装的包

update-to

更新到指定的版本

check-update

检查更新列表,看看是否有新版本

upgrade

和update --obsoletes含义一样

upgrade-to

含义和upgrade一样,只不过指定更新到某个版本

remove

erase

卸载包,包括依赖

list

列出可用的包信息

search

根据关键字搜索包

info

显示包信息

clean

清空缓存

makecache

生成缓存

groupinstall

安装组里所有的包

groupupdate

更新组里所有的包

grouplist

列出仓库里所有的组

groupremove

删除组内所有的包

groupinfo

显示组内包所有的信息

localinstall

安装本地包

localupdate

更新本地包

reinstall

重新安装包

downgrade

降级包或者降级到指定的版本

deplist

显示依赖的包和提供者

repolist

列出源仓库列表

check

检查本地rpmdb数据库,速度比较慢

help

显示帮助信息或者某个命令的帮助信息,如果有指定

常用选项

-h, --help

显示帮助信息

-y, --assumeyes

安装过程中,每一步自动选择同意

--assumeno

每次都选择不同意

-c, --config=[config file]

指定配置文件

-q, --quiet

运行时不输出信息

-v, --verbose

跟-q选项相反,输出详细信息

-d, --debuglevel=[number]

设置调试级别

-e, --errorlevel=[number]

设置错误级别

-C, --cacheonly

仅从缓存读

--version

显示程序版本信息

--showduplicates

显示所有版本,默认是只显示最新的包版本

--enablerepo=repoidglob

启用源仓库,可以是名字,标识,通配符

--disablerepo=repoidglob

禁用源仓库

--obsoletes

更新时,启用过时处理逻辑(不知道是什么鬼?删除不必要的文件?)

-x, --exclude=package

排除指定的包

--nogpgcheck

不进行gpg检验

--downloadonly

不更新,只下载

设置yum源

源文件所在目录

/etc/yum.repos.d

163源

国内一般使用网易源,毕竟是大厂,安全和速度有保障

# 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-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/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-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/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-$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

yum配置文件(/etc/yum.conf)

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

实践

1 源仓库搜索指定的包,比如php

[root@vm ~]# yum search php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
gitlab_gitlab-ee/signature | 836 B 00:00
gitlab_gitlab-ee/signature | 1.0 kB 00:00 ...
gitlab_gitlab-ee-source/signature | 836 B 00:00
gitlab_gitlab-ee-source/signature | 951 B 00:00 ...
======================================================== N/S Matched: php =========================================================
cups-php.x86_64 : Common Unix Printing System - php module
graphviz-php.x86_64 : PHP extension for graphviz
php.x86_64 : PHP scripting language for creating dynamic web sites
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP

2 列出可用的包,比如php,未指定显示所有已安装和未安装可用的包列表

[root@vm ~]# yum list php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
php.x86_64 5.3.3-49.el6 base

3 显示包依赖,比如php依赖的包和提供方

[root@vm ~]# yum deplist php
Loaded plugins: fastestmirror
Finding dependencies:
Loading mirror speeds from cached hostfile
package: php.x86_64 5.3.3-49.el6
dependency: libssl.so.10(libssl.so.10)(64bit)
provider: openssl.x86_64 1.0.1e-57.el6
dependency: libc.so.6(GLIBC_2.8)(64bit)
provider: glibc.x86_64 2.12-1.209.el6
provider: glibc.x86_64 2.12-1.209.el6_9.1
provider: glibc.x86_64 2.12-1.209.el6_9.2
dependency: libxml2.so.2(LIBXML2_2.5.2)(64bit)
provider: libxml2.x86_64 2.7.6-21.el6_8.1
dependency: libz.so.1()(64bit)
provider: zlib.x86_64 1.2.3-29.el6
dependency: libkrb5.so.3()(64bit)
provider: krb5-libs.x86_64 1.10.3-65.el6
dependency: libxml2.so.2(LIBXML2_2.6.5)(64bit)
provider: libxml2.x86_64 2.7.6-21.el6_8.1
dependency: libcrypt.so.1()(64bit)
provider: glibc.x86_64 2.12-1.209.el6
provider: glibc.x86_64 2.12-1.209.el6_9.1
provider: glibc.x86_64 2.12-1.209.el6_9.2
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.12-1.209.el6
provider: glibc.x86_64 2.12-1.209.el6_9.1
provider: glibc.x86_64 2.12-1.209.el6_9.2

4 显示包信息,比如php

[root@vm ~]# yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
gitlab_gitlab-ee/signature | 836 B 00:00
gitlab_gitlab-ee/signature | 1.0 kB 00:00 ...
gitlab_gitlab-ee-source/signature | 836 B 00:00
gitlab_gitlab-ee-source/signature | 951 B 00:00 ...
Available Packages
Name : php
Arch : x86_64
Version : 5.3.3
Release : 49.el6
Size : 1.1 M
Repo : base
Summary : PHP scripting language for creating dynamic web sites
URL : http://www.php.net/
License : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
: easy for developers to write dynamically generated webpages. PHP also
: offers built-in database integration for several commercial and
: non-commercial database management systems, so writing a
: database-enabled webpage with PHP is fairly simple. The most common
: use of PHP coding is probably as a replacement for CGI scripts.
:
: The php package contains the module which adds support for the PHP
: language to Apache HTTP Server.

5 删除包,比如已经安装的lynx包

[root@vm ~]# yum -v remove lynx
Loading "fastestmirror" plugin
Config time: 0.006
Yum Version: 3.2.29
rpmdb time: 0.000
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package lynx.x86_64 0:2.8.6-27.el6 will be erased
Checking deps for lynx.x86_64 0:2.8.6-27.el6 - e
--> Finished Dependency Resolution
Dependency Process ending
Depsolve time: 0.183 Dependencies Resolved ===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Removing:
lynx x86_64 2.8.6-27.el6 installed 4.7 M Transaction Summary
===================================================================================================================================
Remove 1 Package(s) Installed size: 4.7 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Member: lynx.x86_64 0:2.8.6-27.el6 - e
Removing Package lynx-2.8.6-27.el6.x86_64
rpm_check_debug time: 0.029
Running Transaction Test
Member: lynx.x86_64 0:2.8.6-27.el6 - e
Removing Package lynx-2.8.6-27.el6.x86_64
Transaction Test Succeeded
Transaction Test time: 1.374
Member: lynx.x86_64 0:2.8.6-27.el6 - e
Removing Package lynx-2.8.6-27.el6.x86_64
Running Transaction
Erasing : lynx-2.8.6-27.el6.x86_64 1/1
Verifying : lynx-2.8.6-27.el6.x86_64 1/1
VerifyTransaction time: 0.125
Transaction time: 1.338 Removed:
lynx.x86_64 0:2.8.6-27.el6 Complete!

6 安装包,比如lynx包

# 仅下载,不安装
[root@vm ~]# yum --downloadonly install lynx
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lynx.x86_64 0:2.8.6-27.el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
lynx x86_64 2.8.6-27.el6 base 1.3 M Transaction Summary
===================================================================================================================================
Install 1 Package(s) Total download size: 1.3 M
Installed size: 4.7 M
Is this ok [y/N]: y
Downloading Packages:
lynx-2.8.6-27.el6.x86_64.rpm | 1.3 MB 00:00
exiting because --downloadonly specified # 直接安装
[root@vm ~]# yum install lynx
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lynx.x86_64 0:2.8.6-27.el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
lynx x86_64 2.8.6-27.el6 base 1.3 M Transaction Summary
===================================================================================================================================
Install 1 Package(s) Total size: 1.3 M
Installed size: 4.7 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lynx-2.8.6-27.el6.x86_64 1/1
Verifying : lynx-2.8.6-27.el6.x86_64 1/1 Installed:
lynx.x86_64 0:2.8.6-27.el6 Complete!

7 清空所有缓存

[root@vm ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras gitlab_gitlab-ee gitlab_gitlab-ee-source updates
Cleaning up Everything
Cleaning up list of fastest mirrors

参考资料

【1】man yum

【2】linux yum命令详解

http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html

N天学习一个linux命令之yum的更多相关文章

  1. N天学习一个Linux命令之帮助命令:man

    前言 工作中每天都在使用常用的命令和非常用的命令,忘记了用法或者参数,都会bing一下,然后如此循环.一直没有真正的系统的深入的去了解命令的用法,我决定打破它.以前看到有人,每天学习一个linux命令 ...

  2. N天学习一个Linux命令之free

    用途 查看系统内存(物理/虚拟/缓存/共享)使用情况 用法 free [-b | -k | -m | -g | -h] [-o] [-s delay ] [-c count ] [-a] [-t] [ ...

  3. N天学习一个linux命令之ping

    用途 检测主机是否可到达,也就是说,目标主机是否可以联网,还可以用于检测网速.通过发送ICMP ECHO_REQUEST数据包检测. 用法 ping [options] destination 常用选 ...

  4. N天学习一个linux命令之kill

    用途 用于终止进程 用法 kill [-s signal|-p] [--] pid... kill -l [signal] 说明 1.默认发送信号15(请求终止进程,程序可以捕获,操作系统会杀死没有对 ...

  5. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  6. N天学习一个linux命令之scp

    用途 通过ssh通道,不同主机之间复制文件 用法 scp [options] [user@host:]file1 [user2@host2:]file2 常用参数 -1使用 ssh 1协议 -2使用s ...

  7. 每天学习一个Linux命令-目录

    在工作中总会零零散散使用到各种Linux命令,从今天开始详细的学习一下linux常用命令,坚持每天一个命令,学习的主要参考资料为: 1.竹子-博客(https://www.cnblogs.com/pe ...

  8. N天学习一个linux命令之umask

    前言 umask不是linux命令,而是shell内置的指令,俗称用户权限掩码,用于对用户创建的文件和目录设置默认权限.默认的权限掩码是0022,也就是说新创建的文件权限是0644,新创建的目录权限是 ...

  9. N天学习一个linux命令之ip

    用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...

随机推荐

  1. 洛谷P1478 陶陶摘苹果(升级版)

    题目数据范围小,开两个数组手写冒泡应该也能过,不过和之前在牛客上的一题类似用结构体数组就好了,主要是注意用结构体数组的排序 题目 题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果 ...

  2. vue-video-player视频播放插件

    安装依赖 npm install vue-video-player -S 引入配置 //main.js import 'video.js/dist/video-js.css' import 'vue- ...

  3. PHP电影小爬虫(2)

    学习了别人的爬虫后自己改的一个,算是又回顾了一下php的使用 我们来利用simple_html_dom的采集数据实例,这是一个PHP的库,上手很容易.simple_html_dom 可以很好的帮助我们 ...

  4. ACM_巧克力

    Chocolate,Chocolate Time Limit: 2000/1000ms (Java/Others) Problem Description: 都说发神喜欢吃巧克力,有一次发神徒弟买了一 ...

  5. ios cocos2d-x 多点触摸

    需要在 AppController.mm文件中添加一句多点触摸支持: [_view setMultipleTouchEnabled:true];

  6. 单例模式在多线程环境下的lazy模式为什么要加两个if(instance==null)

    刚才在看阿寻的博客”C#设计模式学习笔记-单例模式“时,发现了评论里有几个人在问单例模式在多线程环境下为什么lazy模式要加两个if进行判断,评论中的一个哥们剑过不留痕,给他们写了一个demo来告诉他 ...

  7. 【转】Centos7 ftp 配置及报错处理

    原文链接: https://www.cnblogs.com/GaZeon/p/5393853.html Centos7网络配置,vsftpd安装及530报错解决 今天在虚拟机安装CentOS7,准备全 ...

  8. PD(Power Delivery)充电协议

    关于PD的历史进程,可以在我转载的另一篇文章中了解 http://www.cnblogs.com/Hello-words/p/7851627.html PD 1.0 用的是 BFSK在 VBUS上进行 ...

  9. SQL基本操作——约束

    我们将主要探讨以下几种约束: 1.NOT NULL 2.UNIQUE 3.PRIMARY KEY 4.FOREIGN KEY 5.CHECK 6.DEFAULT SQL NOTNULL约束:NOT N ...

  10. dubbo之主机绑定

    主机绑定 查找顺序 缺省主机 IP 查找顺序: 通过 LocalHost.getLocalHost() 获取本机地址. 如果是 127.* 等 loopback 地址,则扫描各网卡,获取网卡 IP. ...