如何使用yum安装软件

来源:互联网 发布:合同 风险控制矩阵 编辑:程序博客网 时间:2024/05/22 08:16

背景

yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。

事前准备:

本地存在OS文件或可以通过vSphere Client等相关软件加载OS文件到机器。

以加载OS文件为实例

  1. 先将OS通过软件挂载到机器上,随后将其mount到/mnt上。可以看RHEL-6.9相关信息就表明已经mount到OS资源了
[root@rhel69x64zs Packages]# mount/dev/sda1 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)none on /sys/kernel/config type configfs (rw)gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)/dev/sr0 on /media/RHEL-6.9 Server.x86_64 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)/dev/sr0 on /mnt type iso9660 (ro,loop=/dev/loop0)

2.编写yum配置文件

注:如下环境为rhel6系的,如果是rhel5系列的需要将baseurl修改为
baseurl=file:///mnt/Server

[root@rhel69x64zs Packages]# cd /etc/yum.repos.d/ [root@rhel69x64zs yum.repos.d]# ls -ltotal 12-r--r--r--. 1 root root 114 Mar  9  2017 packagekit-media.repo-rw-r--r--. 1 root root 358 Sep 15 21:04 redhat.repo-rw-r--r--. 1 root root 529 Feb 27  2017 rhel-source.repo[root@rhel69x64zs yum.repos.d]# vi zs.repo[root@rhel69x64zs yum.repos.d]# cat zs.repo[zs]-------------------  用于区分不同的repositoryname=zs------------------用于对repository的描述baseurl=file:///mnt------用于指定获取rpm包的源位置,                         支持http://、ftp://、file://三种协议。gpgcheck=0---------------定义是否对rpm包进行GPG校验。enabled=1---------------用于定义此软件仓库是否可用。                        0:不可用,1:可用[root@rhel69x64zs yum.repos.d]# yum clean all----------刷新Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Cleaning repos: InstallMedia zsCleaning up Everything[root@rhel69x64zs yum.repos.d]# yum list | grep httpd                                          ----查找httpd软件包httpd.x86_64                            2.2.15-59.el6                         @anaconda-RedHatEnterpriseLinux-201703082046.x86_64/6.9httpd-tools.x86_64                      2.2.15-59.el6                         @anaconda-RedHatEnterpriseLinux-201703082046.x86_64/6.9httpd-devel.i686                        2.2.15-59.el6                         zshttpd-devel.x86_64                      2.2.15-59.el6                         zshttpd-manual.noarch                     2.2.15-59.el6                         zslibmicrohttpd.i686                      0.9.33-4.el6                          zslibmicrohttpd.x86_64                    0.9.33-4.el6                          zs

3.配置好后就可以到使用yum进行软件的安装了,安装expect为例子

[root@rhel69x64zs yum.repos.d]# /usr/bin/expect-bash: /usr/bin/expect: No such file or directory[root@rhel69x64zs yum.repos.d]# cd[root@rhel69x64zs ~]# yum install expectLoaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Setting up Install ProcessResolving Dependencies--> Running transaction check---> Package expect.x86_64 0:5.44.1.15-5.el6_4 will be installed--> Processing Dependency: libtcl8.5.so()(64bit) for package: expect-5.44.1.15-5.el6_4.x86_64--> Running transaction check---> Package tcl.x86_64 1:8.5.7-6.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved===================================================================================================================================== Package                      Arch                         Version                                    Repository                Size=====================================================================================================================================Installing: expect                       x86_64                       5.44.1.15-5.el6_4                          zs                       256 kInstalling for dependencies: tcl                          x86_64                       1:8.5.7-6.el6                              zs                       1.9 MTransaction Summary=====================================================================================================================================Install       2 Package(s)Total download size: 2.2 MInstalled size: 4.9 MIs this ok [y/N]: yDownloading Packages:-------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                117 kB/s | 2.2 MB     00:18Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionWarning: RPMDB altered outside of yum.  Installing : 1:tcl-8.5.7-6.el6.x86_64                                                                                          1/2  Installing : expect-5.44.1.15-5.el6_4.x86_64                                                                                   2/2zs/productid                                                                                                  | 1.6 kB     00:00 ...  Verifying  : expect-5.44.1.15-5.el6_4.x86_64                                                                                   1/2  Verifying  : 1:tcl-8.5.7-6.el6.x86_64                                                                                          2/2Installed:  expect.x86_64 0:5.44.1.15-5.el6_4Dependency Installed:  tcl.x86_64 1:8.5.7-6.el6Complete![root@rhel69x64zs ~]#

4.当通过直接这样安装无法安装时,这时就需要通过以下方法来进行安装。比如缺失这个包的时候

xxxx:error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

就可以直接进入/mnt/Package目录下
这样搜ls -l |grep libstdc++
再执行yum install libstdc++命令安装即可。
5.下面还有一些常用的命令

yum install package1 安装指定的安装包package1
yum groupinsall group1 安装程序组group1
yum update package1 更新指定程序包package1
yum check-update 检查可更新的程序
yum upgrade package1 升级指定程序包package1
yum groupupdate group1 升级程序组group1
yum info package1 显示安装包信息package1
yum list 显示所有已经安装和可以安装的程序包
yum list package1 显示指定程序包安装情况package1
yum remove package1 删除程序包package1
yum groupremove group1 删除程序组group1

原创粉丝点击