LINUX学习笔记之yum命令

整理日期:2017年10月12日

yum配置本地光盘源

mount -t iso9660 /dev/cdrom /mnt/cdrom
vi /etc/yum.conf
[main]
gpgcheck=1
enabled=1

vim /etc/yum.repos.d/rhel.repo
[Server]
enabled=1
name=Redhat
baseurl=file:///mnt/cdrom/Server
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

====================================================================================================================================================================

http://repoforge.org/use/
#rpm -ivh rpmforge-release-0.5.3-1.el6.rf.i686.rpm --force --nodeps --nosignature
yum install --enablerepo=rpmforge-extras

====================================================================================================================================================================

配置yum
#vi /etc/yum.conf
[main]
exclude=kernel*

[base]
name=Fedora Core $releasever - KaTeX parse error: Expected 'EOF', got '#' at position 17: …asearch - Base #̲baseurl=http://…releasever/$basearch/os/
baseurl=http://ftp.cdpa.nsysu.edu.tw/Linux/Fedora/linux/releases/22/Everything/i386/os/

[updates-released]
name=Fedora Core $releasever - KaTeX parse error: Expected 'EOF', got '#' at position 29: …leased Updates #̲baseurl=http://…releasever/$basearch/
baseurl=http://ftp.cdpa.nsysu.edu.tw/Linux/Fedora/linux/updates/22/i386/

#yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
#yum install -y gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

[解决] yum search/intall, Error: xz compression not available
#yum remove epel-release
#rm -rf /var/cache/yum/x86_64/6Server/epel/
#rpm -ivh epel-release-6-8.noarch.rpm --force --nodeps --nosignature
#rpm -ivh pyliblzma-0.5.3-3.el6.i686.rpm --force --nodeps --nosignature

====================================================================================================================================================================
yum的配置一般有两种方式,一种是直接配置/etc目录下的yum.conf文件,另外一种是在/etc/yum.repos.d目录下增加.repo文件。
一、yum的配置文件
$ cat /etc/yum.conf
[main]
cachedir=/var/cache/yum #yum下载的RPM包的缓存目录
keepcache=0 #缓存是否保存,1保存,0不保存。
debuglevel=2 #调试级别(0-10),默认为2(具体调试级别的应用,我也不了解)。
logfile=/var/log/yum.log #yum的日志文件所在的位置
exactarch=1 #在更新的时候,是否允许更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。
obsoletes=1 #这是一个update的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。
gpgcheck=1 #是否检查GPG(GNU Private Guard),一种密钥方式签名。
plugins=1 #是否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件。
installonly_limit=3 #允许保留多少个内核包。
exclude=selinux* #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离。
#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

二、*.repo文件详解
什么是repo文件?
repo文件是Fedora中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,repo文件中的设置内容将被yum读取和应用!
我们以一份系统自带的repo文件做为实例来探讨(#号后面是我加的注释):
[fedora] #方括号里面的是软件源的名称,将被yum取得并识别

name=Fedora $releasever - KaTeX parse error: Expected 'EOF', got '#' at position 12: basearch #̲这里也定义了软件 仓库的名称,…releasever变量定义了发行版本,通常是8,9,10等数字,KaTeX parse error: Expected 'EOF', got '#' at position 127: …hod=priority #̲failovermethod …releasever/Everything/KaTeX parse error: Expected 'EOF', got '#' at position 14: basearch/os/ #̲上面的一行baseurl第一个…releasever&arch=KaTeX parse error: Expected 'EOF', got '#' at position 10: basearch #̲上面的这一行是指定一个镜像服务…releasever和$basearch替换成自己对应的版本和架构,例如10和i386,在浏览器中打开,我们就能看到一长串镜可用的镜像服务器地址列表。
选择自己访问速度较快的镜像服务器地址复制并粘贴到repo文件中,我们就能获得较快的更新速度了,格式如下baseurl所示:
baseurl=
ftp://ftp.sfc.wide.ad.jp/pub/Linux/Fedora/releases/10/Everything/i386/os
http://ftp.chg.ru/pub/Linux/fedora/linux/releases/10/Everything/i386/os
http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/os
http://mirror.nus.edu.sg/fedora/releases/10/Everything/i386/os
http://mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/os
http://ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/os
http://ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/os

enabled=1 #这个选项表示这个repo中定义的源是启用的,0为禁用
gpgcheck=1 #这个选项表示这个repo中下载的rpm将进行gpg的校验,已确定rpm包的来源是有效和安全的
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定义用于校验的gpg密钥

##以下的软件仓库基本上用不到,选项含义同上
[fedora-debuginfo]
name=Fedora $releasever - KaTeX parse error: Expected 'EOF', got '#' at position 42: …ethod=priority #̲baseurl=http://…releasever/Everything/ b a s e a r c h / d e b u g / m i r r o r l i s t = h t t p : / / m i r r o r s . f e d o r a p r o j e c t . o r g / m i r r o r l i s t ? r e p o = f e d o r a − d e b u g − basearch/debug/ mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug- basearch/debug/mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedoradebugreleasever&arch= b a s e a r c h e n a b l e d = 0 g p g c h e c k = 1 g p g k e y = f i l e : / / / e t c / p k i / r p m − g p g / R P M − G P G − K E Y − f e d o r a − basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora- basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYfedorabasearch

[fedora-source]
name=Fedora KaTeX parse error: Expected 'EOF', got '#' at position 45: …ethod=priority #̲baseurl=http://…releasever/Everything/source/SRPMS/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

关于yum的选项:
check-update 检查可提供的包升级
clean 删除缓存数据
deplist 列出包依赖相关
erase 移除一个或多个包从你的系统
groupinfo 显示关于包组的细节
groupinstall 从组里安装软件包到你的系统
grouplist 列出当前的组
groupremove 在一个组中移除包从您的系统
help 显示帮助用法信息
info 显示关于包或一组包的细节信息
install 安装一个或多个软件包在你的系统
list 列出一个包或某组的包
localinstall 安装本地 RPM
makecache 生成原数据缓存
provides Find what package provides the given value
reinstall 重新安装一个包
repolist 显示软件仓库的配置
resolvedep 决定哪个包提供了给定的依赖
search 查找包细节居给定的字符串
shell 运行交互式的yum shell
update 更新一个或多个包在你的系统
upgrade Update packages taking obsoletes into account
Options:
-h, --help show this help message and exit
-t, --tolerant be tolerant of errors
-C 从缓冲中运行,而不是升级缓存
-c [config file] config file location
-R [minutes] 最大化的命令等待时间
-d [debug level] 调试输出级别
–showduplicates 显示复制, 在repo,list/search命令下
-e [error level] 错误输出级别
-q, --quiet 安静的操作
-v, --verbose verbose operation
-y 回答所有的问题为是
–version 显示 YUM版本信息并退出
–installroot=[path] 设置为root安装
–enablerepo=[repo] 激活一个或多个仓库(支持通配符)
–disablerepo=[repo] 禁掉一个或多个仓库(支持通配符)
-x [package], --exclude=[package] 在名称或glob不包含包。
–disableexcludes=[repo] disable exclude from main, for a repo or for everything
–obsoletes enable obsoletes processing during updates
–noplugins 禁掉yum插件
–nogpgcheck 禁掉GPG验证检查
–disableplugin=[plugin] 用名称禁掉插件
–enableplugin=[plugin] enable plugins by name
–skip-broken 忽略包的依赖问题
–color=COLOR control whether color is used

====================================================================================================================================================================
当大家想只给centos系统更新补丁的时候,往往会把其他一些无用的组件给更新下来,现在就给大家说下怎么只更新补丁而又不更新其他组件.
1.安装yum插件即可:
yum install yum-security
2.使用:
检查安全更新
yum –security check-update
3.只安装安全更新
yum update -security
4.检查特定软件有无安全更新
yum list-security software_name
5.列出更新的详细信息
yum info-security software_name

====================================================================================================================================================================
如何使用yum来下载RPM包而不进行安装

方法一:yum

yum命令本身就可以用来下载一个RPM包,标准的yum命令提供了–downloadonly(只下载)的选项来达到这个目的。

$ sudo yum install --downloadonly
默认情况下,一个下载的RPM包会保存在下面的目录中:

/var/cache/yum/x86_64/[centos/fedora-version]/[repository]/packages
以上的[repository]表示下载包的来源仓库的名称(例如:base、fedora、updates)

如果你想要将一个包下载到一个指定的目录(如/tmp):

$ sudo yum install --downloadonly --downloaddir=/tmp
注意,如果下载的包包含了任何没有满足的依赖关系,yum将会把所有的依赖关系包下载,但是都不会被安装。

另外一个重要的事情是,在CentOS/RHEL 6或更早期的版本中,你需要安装一个单独yum插件(名称为 yum-plugin-downloadonly)才能使用–downloadonly命令选项:

$ sudo yum install yum-plugin-downloadonly
如果没有该插件,你会在使用yum时得到以下错误:

Command line error: no such option: --downloadonly

方法二: Yumdownloader

另外一个下载RPM包的方法就是通过一个专门的包下载工具–yumdownloader。 这个工具是yum工具包(包含了用来进行yum包管理的帮助工具套件)的子集。

$ sudo yum install yum-utils
下载一个RPM包:

$ sudo yumdownloader
下载的包会被保存在当前目录中。你需要使用root权限,因为yumdownloader会在下载过程中更新包索引文件。与yum命令不同的是,任何依赖包不会被下载。

http://ask.xmodulo.com/yum-download-rpm-package.html

====================================================================================================================================================================
** Found 1 pre-existing rpmdb problem(s), ‘yum check’ output follows:
kernel-2.6.32-220.13.1.el6.x86_64 has missing requires of kernel-firmware >= ('0 ', ‘2.6.32’, ‘220.13.1.el6’)

解决方法:修改文件vi /etc/yum.conf 将exclude=kernel*前加注释即可解决,此参数的意思是排除安装或更新kernel开头的软件,而我们安装gcc需要依赖kernel相关的软件glibc-headers-2.12-1.80.el6_3.5.x86_64 。

在安装完毕后浏览中文网页或查看中文文档时总是宣誓乱码,因此需要安装中文语言包,如果不能 从安装盘进行安装,可以通过yum进行安装,安装办法为:

yum groupinstall -support
eg:yum groupinstall chinese-support
在上面的命令中, 是下列之一: assamese, bengali, chinese, gujarati, hindi, japanese, kannada, korean, malayalam, marathi, oriya, punjabi, sinhala, tamil, thai, 或 telegu。

locale -a查看系统支持的语言

vi /etc/sysconfig/i18n

改成LANG=”zh_CN.UTF-8″

source /etc/sysconfig/i18n 即可生效

====================================================================================================================================================================

yum依赖错误处理:清理重复的rpm包
发表于2014/02/06由feng
使用fedora/redhat/centos系列的linux发行版,有时会因为某些非正常原因(异常断电居多)造成yum/rpm错误,表现是在运行yum时出现依赖包错误,仔细查看其相关包,会发现这些包是矛盾的版本号依赖。这种情况下,通常就是本机rpm数据库里记录了某个rpm包多个版本(可能事实上只装了一个版本),通过rpm -q {包名} 会查出来多个版本,例如

[root@fscfedora feng]# rpm -q audit
audit-2.3.2-1.fc20.x86_64
audit-2.3.3-1.fc20.x86_64

我们需要删除其中一个包,通常删除旧版本的包,命令: rpm -e {带版本号的完整包名}。

但这时通过yum或rpm -e移除该包时,有时仍旧出现依赖错误。

这是可以通过rpm 的 --noscript参数,硬性移除该包(指定完整的版本号),例如

[root@fscfedora feng]# rpm -e --noscripts audit-2.3.2-1.fc20.x86_64

然后再检查该包,会发现少了已删除的那个。然后继续yum吧,如果还有类似情况,同法处理之。

tips,我们还可以运行 yum check 检查是否有类似的错误包。


参考脚本:

[root@fscfedora feng]# rpm -q audit
audit-2.3.2-1.fc20.x86_64
audit-2.3.3-1.fc20.x86_64
[root@fscfedora feng]# rpm -e --noscripts audit-2.3.2-1.fc20.x86_64
[root@fscfedora feng]# rpm -q audit
audit-2.3.3-1.fc20.x86_64
[root@fscfedora feng]#

典型错误示例:

–> 解决依赖关系完成
错误:软件包:glibc-devel-2.18-11.fc20.x86_64 (@anaconda)
需要:glibc-headers = 2.18-11.fc20
正在删除: glibc-headers-2.18-11.fc20.x86_64 (@anaconda)
glibc-headers = 2.18-11.fc20
更新,由: glibc-headers-2.18-12.fc20.x86_64 (updates)
glibc-headers = 2.18-12.fc20
您可以尝试添加 --skip-broken 选项来解决该问题
** 发现 19 个已存在的 RPM 数据库问题, ‘yum check’ 输出如下:
1:NetworkManager-0.9.9.0-24.git20131003.fc20.x86_64 有缺少的需求 NetworkManager-glib(x86-64) = (‘1’, ‘0.9.9.0’, ‘24.git20131003.fc20’)
1:NetworkManager-0.9.9.0-28.git20131003.fc20.x86_64 是 1:NetworkManager-0.9.9.0-24.git20131003.fc20.x86_64 的副本
audit-2.3.2-1.fc20.x86_64 有缺少的需求 audit-libs = (‘0’, ‘2.3.2’, ‘1.fc20’)

打算在centos7上安装一个远程控制软件,发现teamviewer只有centos的32位版本,试着安装了一下,各种报错,尝试多次无果。于是试着用向日葵远程控制软件,也报错,貌似也是只支持32位。
按照网上乱七八糟的教程,发现都是报错,后来终于找到解决方法,如下
查看是否有32位库
yum list |grep xulrunner
安装32位库
yum install xulrunner.i686
报错

。。。此处太长,忽略
…you can also use --setopt=protected_multilib=false to remove #这行是系统推荐做法
this checking, however this is almost never the correct thing to
do as something else is very likely to go wrong (often causing
much more problems).

Protected multilib versions: expat-2.1.0-10.el7_3.i686 != expat-2.1.0-8.el7.x86_64
Error: Protected multilib versions: libuuid-2.23.2-33.el7_3.2.i686 != libuuid-2.23.2-33.el7.x86_64

既然有提示,那么就按照它的提示来呗
yum install –setopt=protected_multilib=false xulrunner.i686
在这里我把setopt放到命令的最后面,发现还是报一样的错误,然后放到上面的这个位置
然后就能安装成功了

【解决】缺少libstdc++.so.6库的原因及解决办法
原创 2014年10月15日 11:29:44 3025932
问题原因:
系统是64bit,该库是32bit的,在64bit系统上安装32bit库

解决办法:

  1. 查看哪个安装包包含该库:yum provides libstdc++.so.6
    libstdc+±4.4.7-4.el6.i686
  2. 安装 libstdc+±4.4.7-4.el6.i686
    yum install libstdc+±4.4.7-4.el6.i686
    报错:
    –> Finished Dependency Resolution
    Error: Protected multilib versions: libstdc+±4.4.7-4.el6.i686 != libstdc+±4.4.7-3.el6.x86_64
    You could try using --skip-broken to work around the problem
    You could try running: rpm -Va --nofiles --nodigest
    2.1 解决办法:
    yum update libstdc+±4.4.7-3.el6.x86_64
    然后再执行步骤2的命令

顺便告诉大家,需要直播设备的朋友可以进我的店铺地址:https://shop66907778.taobao.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值