清理本地yum缓存并更新重新缓存
======================
yum clean
yum clean all
rm -rf /var/cache/yum/*
yum makecache
yum update
cd /etc/yum*d
yum缓存清理使用yum clean 命令,yum clean 的参数有headers, packages, metadata,
dbcache, plugins, expire-cache, rpmdb, all
最快捷还是
yum clean all
cat yum.conf
======================
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
metadata_expire=1800
timeout=120
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
vi rhel-debuginfo.repo
[base]
name=CentOS-5 - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch&
repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
#released updates
[update]
name=CentOS-5 - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates
baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons
baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras
baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
#additional packages that extend functionality of existing
packages
[centosplus]
name=CentOS-5 - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=centosplus
baseurl=http://ftp.sjtu.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=contrib
baseurl=http://ftp.sjtu.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5
vi dag.repo
[dag]
name=Dag RPM Repository for RHEL5
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el5/en/$basearch/dag/
enabled=1
gpgcheck=1
gpgkey=http://ftp.riken.jp/Linux/dag/packages/RPM-GPG-KEY.dag.txt
vi rpmforge.repo
# Name: RPMforge RPM Repository for Red Hat Enterprise 5 -
dag
# URL: http://rpmforge.net/
[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
#baseurl = http://apt.sw.be/redhat/el5/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
vi mirrors-rpmforge
http://apt.sw.be/redhat/el5/en/$ARCH/dag
http://archive.cs.uu.nl/mirror/dag.wieers/redhat/el5/en/$ARCH/dag
http://ftp2.lcpe.uni-sofia.bg/freshrpms/pub/dag/redhat/el5/en/$ARCH/dag
#http://ftp.heanet.ie/pub/freshrpms/pub/dag/redhat/el5/en/$ARCH/dag
http://ftp-stud.fht-esslingen.de/dag/redhat/el5/en/$ARCH/dag
http://mirror.cpsc.ucalgary.ca/mirror/dag/redhat/el5/en/$ARCH/dag
http://mirrors.ircam.fr/pub/dag/redhat/el5/en/$ARCH/dag
http://rh-mirror.linux.iastate.edu/pub/dag/redhat/el5/en/$ARCH/dag
http://rpmfind.net/linux/dag/redhat/el5/en/$ARCH/dag
http://wftp.tu-chemnitz.de/pub/linux/dag/redhat/el5/en/$ARCH/dag
http://www.mirrorservice.org/sites/apt.sw.be/redhat/el5/en/$ARCH/dag
测试:
rpm -e --nodeps perl-DBD-MySQL
rpm -e --nodeps perl-DBI
然后执行:
yum list
yum list all
yum install -y vim
yum install -y perl-DBD-MySQL
切换国内的yum源:
=============
centos7默认的源的网址mirrorlist.centos.org,属于国外的网站,可能出现连不上或者网速很慢,
使用国内一些大的源,既可以提高速度,同时避免一些常见软件版本无法找到。国内主要sohu、网易。
1. 切换到系统yum源的目录: cd/etc/yum.repos.d
2.备份系统默认yum源:mvCentOS-Base.repo CentOS-Base.repo.bk
3.下载
163网易的yum源:
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
sohu的yum源:
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
4.更改网易的源为默认的系统yum源,即:
mv CentOS6-Base-163.repo CentOS-Base.repo
5.运行yum makecache 生成缓存,
即
yum makecache
yum update
此时可能会出现HTTP ERORR 404-Not Found Trying
othermirror,原因可能是yum查找软件包
使用的过时的缓存(此时可能需要去cd/etc/yum.repos.d目录,找到过时的缓存,把它去掉),
等同于 yum cleanheaders yum cleanpackage
yum clean
yum clean all
yum update
yum makecache
清空更新之后,再次安装软件,问题消失,
这之后,重新运行 yum
make cache
生成缓存,yum makecache
主要目的是将服
务器上的软件包信息在本地缓存,以提高搜索安装软件的速度。
6、常用命令
=====================
1.安装软件
yum install 软件名称
2.卸载软件
yum remove 软件名称
3.更新软件
yum update 软件名称
4.列出所有可安装的软件包
yum list
5.列出所有可更新的软件包
yum list updates
6.列出所有已安装的软件包
yum list installed
7.列出所有可更新的软件包信息
yum info updates
8.列出所有已安裝的软件包信息
yum info installed
--其它命令
check Check for problems in the rpmdb
check-update 检查是否有软件包更新
clean 删除缓存的数据
deplist 列出软件包的依赖关系
distribution-synchronization Synchronize installed packages to the
latest available versions
downgrade downgrade a package
erase 从系统中移除一个或多个软件包
groupinfo 显示组的详细信息
groupinstall 向系统中安装一组软件包
grouplist 列出可安装的组
groupremove 从系统中移除一组软件包
help 显示用法信息
history Display, or use, the transaction history
info 显示关于软件包或组的详细信息
install 向系统中安装一个或多个软件包
list 列出一个或一组软件包
load-transaction load a saved transaction from filename
makecache 创建元数据缓存
provides 查找提供指定内容的软件包
reinstall 覆盖安装一个包
repolist 显示已配置的仓库
resolvedep 判断哪个包提供了指定的依赖
search 在软件包详细信息中搜索指定字符串
shell 运行交互式的 yum 外壳
update 更新系统中的一个或多个软件包
update-minimal Works like update, but goes to the 'newest' package
match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade 更新软件包同时考虑软件包取代关系
version yum版本信息
7、测试:
===============
yum install xterm
[root@VM_64_101_centos ~]# yum install xterm
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package xterm.x86_64 0:295-3.el7 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package:
xterm-295-3.el7.x86_64
--> Processing Dependency: libXaw.so.7()(64bit) for package:
xterm-295-3.el7.x86_64
--> Running transaction check
---> Package libXaw.x86_64 0:1.0.12-5.el7 will be
installed
---> Package libXpm.x86_64 0:3.5.11-3.el7 will be
installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================
Package Arch
==============================================================================================
Installing:
xterm x86_64
Installing for dependencies:
libXaw x86_64
libXpm x86_64
Transaction Summary
==============================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 700 k
Installed size: 1.8 M
Is this ok [y/d/N]: Exiting on user command
Your transaction was saved, rerun it with:
yum load-transaction
/tmp/yum_save_tx.2017-06-06.11-43.2o1ly_.yumtx
[root@VM_64_101_centos ~]# yum install xterm
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package xterm.x86_64 0:295-3.el7 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package:
xterm-295-3.el7.x86_64
--> Processing Dependency: libXaw.so.7()(64bit) for package:
xterm-295-3.el7.x86_64
--> Running transaction check
---> Package libXaw.x86_64 0:1.0.12-5.el7 will be
installed
---> Package libXpm.x86_64 0:3.5.11-3.el7 will be
installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================
Package Arch
==============================================================================================
Installing:
xterm x86_64
Installing for dependencies:
libXaw x86_64
libXpm x86_64
Transaction Summary
==============================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 700 k
Installed size: 1.8 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): libXpm-3.5.11-3.el7.x86_64.rpm
(2/3): libXaw-1.0.12-5.el7.x86_64.rpm
(3/3): xterm-295-3.el7.x86_64.rpm
----------------------------------------------------------------------------------------------
Total
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libXpm-3.5.11-3.el7.x86_64
Installing : libXaw-1.0.12-5.el7.x86_64
Installing : xterm-295-3.el7.x86_64
Verifying : libXaw-1.0.12-5.el7.x86_64
Verifying : libXpm-3.5.11-3.el7.x86_64
Verifying : xterm-295-3.el7.x86_64
Installed:
xterm.x86_64 0:295-3.el7
Dependency Installed:
libXaw.x86_64 0:1.0.12-5.el7
Complete!
