20181009 CentOS安装软件、rpm和yum工具用法、yum搭建本地仓库

牧云@^-^@ 提交于 2020-03-15 03:36:15

安装方法:

  • rpm 工具
  • yum 工具 (python写的,安装的也是rpm包,会安装对应的依赖)
  • 源码包

rpm工具使用

  • 设置光驱并挂载
  • rpm包格式,报名,版本号,发布版本号、平台
  • rpm -ivh rpm包文件 # 安装
  • rpm -Uvh rpm包文件 # 升级
  • rpm -e 包名 # 卸载
  • rpm -qa # 查询安装的包
  • rpm -q 包名 # 查询指定包是否安装
  • rpm -qi 包名 # 查询指定包信息
  • rpm -ql 包名 # 列出包安装的文件
  • rpm -qf 文件绝对路径 # 查看一个文件是由哪个包安装的

虚拟机中设置光驱并挂载
光驱设置,如下图
挂载光驱

[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

[root@centos01 ~]# ls /mnt/Packages/ | head # 可以查看到镜像中的包
389-ds-base-1.3.1.6-25.el7.x86_64.rpm
389-ds-base-libs-1.3.1.6-25.el7.x86_64.rpm
abattis-cantarell-fonts-0.0.12-3.el7.noarch.rpm
abrt-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-ccpp-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-kerneloops-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-pstoreoops-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-python-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-vmcore-2.1.11-12.el7.centos.x86_64.rpm
abrt-addon-xorg-2.1.11-12.el7.centos.x86_64.rpm

rpm命令的常用选项操作

[root@centos01 ~]# rpm -ivh /mnt/Packages/zsh-5.0.2-7.el7.x86_64.rpm 
# 安装,如果/zsh-5.0.2-7.el7.x86_64.rpm有相关的依赖,会提示先安装对应的依赖包
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-7.el7                  ################################# [100%]

[root@centos01 ~]# rpm -e zsh # 卸载,成功不会有提示,但错误会有相应的提示

[root@centos01 ~]# rpm -q ppp # 查询指定包是否安装
ppp-2.4.5-33.el7.x86_64
[root@centos01 ~]# rpm -q zsh
package zsh is not installed

[root@centos01 ~]# rpm -qi vim-enhanced
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 4.el7
Architecture: x86_64
Install Date: Sat 29 Sep 2018 08:37:28 AM CST
Group       : Applications/Editors
Size        : 2296714
License     : Vim
Signature   : RSA/SHA256, Wed 25 Apr 2018 07:50:34 PM CST, Key ID 24c6a8a7f4a80e             b5
Source RPM  : vim-7.4.160-4.el7.src.rpm
Build Date  : Wed 11 Apr 2018 07:55:09 AM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.

Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package.

[root@centos01 ~]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor

[root@centos01 ~]# rpm -qf /usr/bin/vimtutor
vim-enhanced-7.4.160-4.el7.x86_64

yum工具

  • yum list # 列出所有可用的rpm包
  • ls /etc/yum.repos.d # 查看yum的资源配置文件
  • yum search vim # 搜索包
  • yum install [-y] # -y 安装时不进行提示
  • yum grouplist # 查看所有的组
  • yum remove [-y] # 删除包,同时删除相关依赖
  • yum update [-y] # 不加包名时,会升级系统中所有的rpm包,并且还会升级系统和内核,所以用该选项进行升级一定要注意!!
  • yum provides "/*/vim" # 只知道vim命名,搜索对应需要安装的包
[root@centos01 yum.repos.d]# yum list | head #@anaconda中的@代表已经安装的
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
ModemManager-glib.x86_64               1.1.0-6.git20130913.el7         @anaconda
NetworkManager.x86_64                  1:0.9.9.1-13.git20140326.4dba720.el7
                                                                       @anaconda
NetworkManager-glib.x86_64             1:0.9.9.1-13.git20140326.4dba720.el7
                                                                       @anaconda
NetworkManager-tui.x86_64              1:0.9.9.1-13.git20140326.4dba720.el7
                                                                       @anaconda

[root@centos01 ~]# yum grouplist  
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.njupt.edu.cn
 * updates: centost5.centos.org
Available environment groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[root@centos01 ~]# yum groupinstall 'Compute Node'
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
updates/7/x86_64/primary_db                                   | 6.0 MB  00:04:04
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.njupt.edu.cn
 * updates: centost5.centos.org
Warning: Group scientific does not have any packages to install.
Resolving Dependencies
--> Running transaction check
---> Package NetworkManager.x86_64 1:0.9.9.1-13.git20140326.4dba720.el7 will be obsoleted
...
Transaction Summary
=====================================================================================
Install  73 Packages (+86 Dependent packages)
Upgrade   5 Packages (+33 Dependent packages)


[root@centos01 ~]# yum remove ppp
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package ppp.x86_64 0:2.4.5-33.el7 will be erased
--> Processing Dependency: ppp = 2.4.5 for package: 1:NetworkManager-0.9.9.1-13.git20140326.4dba720.el7.x86_64
--> Running transaction check
---> Package NetworkManager.x86_64 1:0.9.9.1-13.git20140326.4dba720.el7 will be erased
--> Processing Dependency: NetworkManager(x86-64) = 1:0.9.9.1-13.git20140326.4dba720.el7 for package: 1:NetworkManager-tui-0.9.9.1-13.git20140326.4dba720.el7.x86_64
--> Running transaction check
---> Package NetworkManager-tui.x86_64 1:0.9.9.1-13.git20140326.4dba720.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================
 Package             Arch    Version                                Repository  Size
=====================================================================================
Removing:
 ppp                 x86_64  2.4.5-33.el7                           @anaconda  852 k
Removing for dependencies:
 NetworkManager      x86_64  1:0.9.9.1-13.git20140326.4dba720.el7   @anaconda  5.9 M
 NetworkManager-tui  x86_64  1:0.9.9.1-13.git20140326.4dba720.el7   @anaconda  253 k

Transaction Summary
=====================================================================================
Remove  1 Package (+2 Dependent packages)

yum 本地仓库

  • 挂载镜像到/mnt/目录
  • cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak # 备份原有的资源配置目录
  • rm -f /etc/yum.repos.d/* # 删除所有配置文件
  • vim /etc/yum.repos.dvd.repo # 新建yum的配置文件,内容如下
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0
yum clean all  # 清除缓存
yum list

实际操作记录

[root@centos01 ~]# cp /etc/yum.repos.d /etc/yum.repos.d.bak -r
[root@centos01 ~]# cd /etc/yum.repos.d
[root@centos01 yum.repos.d]# rm -rf *
[root@centos01 yum.repos.d]# ls
[root@centos01 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: dvd
Cleaning up everything
Cleaning up list of fastest mirrors

[root@centos01 yum.repos.d]# yum list | tail -n 50
                                       7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-14-75dpi.noarch 7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-15-75dpi.noarch 7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-2-100dpi.noarch 7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-2-75dpi.noarch  7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-9-100dpi.noarch 7.5-9.el7                       dvd
xorg-x11-fonts-ISO8859-9-75dpi.noarch  7.5-9.el7                       dvd
xorg-x11-fonts-Type1.noarch            7.5-9.el7                       dvd
xorg-x11-fonts-cyrillic.noarch         7.5-9.el7                       dvd
xorg-x11-fonts-ethiopic.noarch         7.5-9.el7                       dvd
xorg-x11-fonts-misc.noarch             7.5-9.el7                       dvd
xorg-x11-glamor.x86_64                 0.5.1-4.20140115gitfb4d046c.el7 dvd
xorg-x11-proto-devel.noarch            7.7-8.el7.1                     dvd
xorg-x11-server-Xephyr.x86_64          1.15.0-7.el7                    dvd
xorg-x11-server-Xorg.x86_64            1.15.0-7.el7                    dvd
xorg-x11-server-common.x86_64          1.15.0-7.el7                    dvd
xorg-x11-server-utils.x86_64           7.7-4.el7                       dvd
xorg-x11-utils.x86_64                  7.5-13.1.el7                    dvd
xorg-x11-xauth.x86_64                  1:1.0.7-6.1.el7                 dvd
xorg-x11-xbitmaps.noarch               1.1.1-6.el7                     dvd
xorg-x11-xinit.x86_64                  1.3.2-13.el7                    dvd
xorg-x11-xkb-utils.x86_64              7.7-9.1.el7                     dvd
xpp3.noarch                            1.1.3.8-11.el7                  dvd
xrestop.x86_64                         0.4-14.el7                      dvd
xsane-common.x86_64                    0.999-9.el7                     dvd
xsane-gimp.x86_64                      0.999-9.el7                     dvd
xsettings-kde.x86_64                   0.12.3-7.el7                    dvd
xsom.noarch                            0-10.20110809svn.el7            dvd
xterm.x86_64                           295-3.el7                       dvd
xulrunner.x86_64                       24.5.0-1.el7.centos             dvd
xvattr.x86_64                          1.3-27.el7                      dvd
xz-devel.x86_64                        5.1.2-8alpha.el7                dvd
yajl.x86_64                            2.0.4-4.el7                     dvd
yelp.x86_64                            1:3.8.1-7.el7                   dvd
yelp-libs.x86_64                       1:3.8.1-7.el7                   dvd
yelp-xsl.noarch                        3.8.1-2.el7                     dvd
yp-tools.x86_64                        2.14-3.el7                      dvd
ypbind.x86_64                          3:1.37.1-7.el7                  dvd
ypserv.x86_64                          2.31-8.el7                      dvd
yum-langpacks.noarch                   0.4.2-3.el7                     dvd
yum-plugin-aliases.noarch              1.1.31-24.el7                   dvd
yum-plugin-changelog.noarch            1.1.31-24.el7                   dvd
yum-plugin-tmprepo.noarch              1.1.31-24.el7                   dvd
yum-plugin-verify.noarch               1.1.31-24.el7                   dvd
yum-plugin-versionlock.noarch          1.1.31-24.el7                   dvd
yum-utils.noarch                       1.1.31-24.el7                   dvd
zenity.x86_64                          3.8.0-4.el7                     dvd
zlib-devel.x86_64                      1.2.7-13.el7                    dvd
zsh.x86_64                             5.0.2-7.el7                     dvd
zziplib.x86_64                         0.13.62-5.el7                   dvd
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!