1.查看系统版本
[root@localhost /]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.4 (Santiago)
Kernel \r on an \m
2.通过wget在http://mirrors.163.com/centos/6/os/x86_64/Packages/装yum源,但是由于是最小化安装,没有wget这个命令(系统提示-bash: wget: command not found)。需要下载一个wget-1.12-1.4.el6.x86_64.rpm包,然后通过rpm命令安装wget程序。
3.安装wget,如果已经存在则忽略此步骤,到http://rpm.pbone.net/index.php3 搜索wget-1.12-1.4.el6.x86_64.rpm,使用rpm -ivh wget-1.12-1.4.el6.x86_64.rpm 安装,当然需要把wget-1.12-1.4.el6.x86_64.rpm放置到RedHat64的目录下,到此目录下去执行rpm -ivh wget-1.12-1.4.el6.x86_64.rpm
4.通过wget下载yum软件包,注意以下的软件包不一定能够成功的下载,原因就是版本的不断变化,网上很多文章没法直接使用就是因为软件包的版本问题,如果下载不到的话可以直接到http://mirrors.163.com/centos/6/os/x86_64/Packages/ 然后通过ctrl+f快捷键查找到匹配到最前面的几个字样的rpm包,比如yum-3等选择下载下述4个软件包
[root@localhost src]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
--2017-09-28 15:05:14-- http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
正在解析主机 mirrors.163.com... 123.58.190.235, 123.58.190.209, 123.58.190.236, ...
正在连接 mirrors.163.com|123.58.190.235|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:37052 (36K) [application/x-redhat-package-manager]
正在保存至: “python-iniparse-0.3.1-2.1.el6.noarch.rpm”
100%[======================================================================================================>] 37,052 --.-K/s in 0.01s
2017-09-28 15:05:14 (2.67 MB/s) - 已保存 “python-iniparse-0.3.1-2.1.el6.noarch.rpm” [37052/37052])
[root@localhost src]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
[root@localhost src]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
[root@localhost src]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
如果在这个过程中提示Couldn’t resolve host ‘mirrors.163.com 字样,有可能是DNS没有设置好,
通过:
cd ~
cd /etc
vi resolv.conf
添加一个nameserver 8.8.8.8
5.安装yum,按照以下顺序格式安装,注意最后yum-3.2.29-81.el6.centos.noarch.rpm 和 yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm需要同时安装,他们互相依赖
[root@localhost src]# rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
[root@localhost src]# rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
[root@localhost src]# rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
如果在这个过程中提示如下字样:
rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
warning: yum-3.2.29-81.el6.centos.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
python-urlgrabber >= 3.9.1-10 is needed by yum-3.2.29-81.el6.centos.noarch
查看系统的python信息 rpm -qa|grep python,
发现python-urlgrabber-3.9.1-9.el6.noarch 版本低于3.9.1-10
卸载:python-urlgrabber-3.9.1-9.el6.noarch
rpm -e python-urlgrabber-3.9.1-9.el6.noarch
下载高版本
[root@localhost src]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
安装
[root@localhost src]# rpm -ivh python-urlgrabber-3.9.1-11.el6.noarch.rpm
查看安装成功没
[root@localhost src]# rpm -qa|grep python
notify-python-0.1.1-10.el6.x86_64
python-iniparse-0.3.1-2.1.el6.noarch
python-simplejson-2.0.9-3.1.el6.x86_64
python-rhsm-1.1.8-1.el6.x86_64
python-ethtool-0.6-3.el6.x86_64
python-urlgrabber-3.9.1-11.el6.noarch------------------------
python-2.6.6-36.el6.x86_64
rpm-python-4.8.0-32.el6.x86_64
python-dmidecode-3.10.13-1.el6.x86_64
newt-python-0.52.11-3.el6.x86_64
python-libs-2.6.6-36.el6.x86_64
dbus-python-0.83.0-6.1.el6.x86_64
libxml2-python-2.7.6-8.el6_3.4.x86_64
python-dateutil-1.4.1-6.el6.noarch
python-pycurl-7.19.0-8.el6.x86_64
python-gudev-147.1-4.el6_0.1.x86_64
重新执行yum安装命令
[root@localhost src]# rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
查看yum命令,已成功安装
[root@localhost /]# yum
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
你需要给出命令
Usage: yum [options] COMMAND
List of Commands:
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 更新系统中的一个或多个软件包
upgrade 更新软件包同时考虑软件包取代关系
version Display a version for the machine and/or available repos.
Options:
-h, --help show this help message and exit
-t, --tolerant 容忍错误
-C, --cacheonly run entirely from system cache, don't update cache
-c [config file], --config=[config file]
配置文件路径
-R [minutes], --randomwait=[minutes]
命令最长等待时间
-d [debug level], --debuglevel=[debug level]
调试输出级别
--showduplicates 在 list/search 命令下,显示仓库里重复的条目。
-e [error level], --errorlevel=[error level]
错误输出级别
--rpmverbosity=[debug level name]
debugging output level for rpm
-q, --quiet 安静的操作
-v, --verbose verbose operation
-y, --assumeyes 回答所有的问题为是
--assumeno answer no for all questions
--version 显示 Yum 版本信息并退出
--installroot=[path] 设置目标根目录
--enablerepo=[repo] 启用一个或多个仓库(支持通配符)
--disablerepo=[repo] 禁用一个或多个仓库(支持通配符)
-x [package], --exclude=[package]
用全名或通配符排除软件包
--disableexcludes=[repo]
禁止从主配置,从仓库或者从任何位置排除
--obsoletes 升级时考虑软件包取代关系
--noplugins 禁用 Yum 插件
--nogpgcheck 禁用 gpg 签名检测
--disableplugin=[plugin]
禁用指定名称的插件
--enableplugin=[plugin]
enable plugins by name
--skip-broken 跳过有依赖问题的软件包
--color=COLOR 配置是否使用颜色
--releasever=RELEASEVER
set value of $releasever in yum config and repo files
--downloadonly don't update, just download
--downloaddir=DLDIR specifies an alternate directory to store packages
--setopt=SETOPTS set arbitrary config and repo options
插件选项:
更改(创建)yum源CentOS-Base.repo
[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2017-09-28 15:52:58-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
正在解析主机 mirrors.163.com... 123.58.190.209, 123.58.190.236, 123.58.190.228, ...
正在连接 mirrors.163.com|123.58.190.209|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2006 (2.0K) [application/octet-stream]
正在保存至: “CentOS6-Base-163.repo”
100%[======================================================================================================>] 2,006 --.-K/s in 0s
2017-09-28 15:53:03 (428 MB/s) - 已保存 “CentOS6-Base-163.repo” [2006/2006])
[root@localhost yum.repos.d]# vi CentOS6-Base-163.repo
将所有 releasever修改为具体的版本号保存就可以了,我这里写的是6.9(:0, s/$releasever/6.9/g),以后centos再更新,有可能是7.1、7.2等,这个自己打开(http://mirrors.163.com/centos)找一下就可以。
清理yum缓存
yum clean all
将服务器软件包信息缓存至本地,提高搜索安装效率
yum makecache
测试
yum search java|grep jdk
执行yum repolist查看,如果显示出repo仓库列表,并显示软件包数量则OK。(或者使用yum makecache)
使用yum安装软件包测试。
[root@localhost /]# whereis unzip
unzip:
[root@localhost /]# unzip
-bash: unzip: command not found
[root@localhost /]# yum install -y unzip zip
[root@localhost /]# unzip
至此,如果unzip有效,就说明unzip软件包安装成功,yum也就可以正常使用了。