Linux软件包安装和卸载

7.1、安装软件包的三种方法

  • 三种方法:rpm工具(redhat packges manager)、yum工具(Python开发的工具,支持自动安装依赖包)、源码包(源代码,需要编译成可执行的文件后再安装,三种方法中难度系数最大)
  • rpm工具安装类似于Windows下.exe文件,安装路径和文件名基本都是固定的
  • yum是另一种rpm工具

7.2、rpm包介绍

  • rpm工具使用
  1. 设置光驱挂载
  2. rpm包格式,包名、版本号、发布版本号、平台
  3. rpm -ivh rpm包文件 安装
  4. rpm -Uvh rpm包文件 升级
  5. rpm -e 包名 卸载
  6. rpm -qa 查询安装的包
  7. rpm -q包名 查询指定包是否安装
  8. rpm -qi 包名 查询指定包信息
  9. rpm -ql包名 列出包安装的文件
  10. rpm -qf 文件绝对路径 查看一个文件是由哪个包安装的
  • 挂载光驱
1. [root@localhost ~]# df -h 
	2. Filesystem             Size  Used Avail Use% Mounted on
	3. /dev/mapper/rhel-root   37G  1.1G   36G   3% /
	4. devtmpfs               902M     0  902M   0% /dev
	5. tmpfs                  912M     0  912M   0% /dev/shm
	6. tmpfs                  912M  8.6M  904M   1% /run
	7. tmpfs                  912M     0  912M   0% /sys/fs/cgroup
	8. /dev/sda1             1014M  139M  876M  14% /boot
	9. tmpfs                  183M     0  183M   0% /run/user/0
	10. [root@localhost ~]# mount /dev/cdrom /mnt/
	11. mount: /dev/sr0 is write-protected, mounting read-only
	12. [root@localhost ~]# cd /mnt/
	13. [root@localhost mnt]# ls
	14. addons  EULA  images    LiveOS      Packages       repodata                 RPM-GPG-KEY-redhat-release
	15. EFI     GPL   isolinux  media.repo  release-notes  RPM-GPG-KEY-redhat-beta  TRANS.TBL
	16. [root@localhost mnt]# 
  • rpm包都存放在Packages/目录下】

  • 第一部分字符串是包名

  • 第二部分-后面是版本号(主版本号,次版本号,小版本或者修正版本)

  • 第三部分是发布版本号(el7)

  • 第四部分是平台位数(32位和64位,centos7不区分32位和64位)64位向下兼容32位

  • 第五部分是后缀名

7.3、rpm工具用法

  • 安装rpm包:rpm -ivh
1. [root@localhost mnt]# cd Packages/
	2. [root@localhost Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm 
	3. warning: zsh-5.0.2-25.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
	4. Preparing...                          ################################# [100%]
	5. Updating / installing...
	6.    1:zsh-5.0.2-25.el7                 ################################# [100%]
	7. [root@localhost Packages]# 

  • 升级rpm包:rpm -Uvh

  • 卸载rpm包:rpm -e zsh(卸载包是会有提示依赖包)

1. [root@localhost Packages]# rpm -e zsh
	2. [root@localhost Packages]# 


  • 查询已经安装的rpm包:rpm -qa
  • 参数-q查询指定包是否已经安装过、
1. [root@localhost Packages]# rpm -qi cryptsetup-libs-1.7.2-1.el7.x86_64.rpm 
	2. package cryptsetup-libs-1.7.2-1.el7.x86_64.rpm is not installed
	3. [root@localhost Packages]# rpm -q cryptsetup-libs-1.7.2-1.el7.x86_64.rpm 
	4. package cryptsetup-libs-1.7.2-1.el7.x86_64.rpm is not installed
	5. [root@localhost Packages]# rpm -qf /usr/bin/vi
	6. vim-minimal-7.4.160-1.el7.x86_64
	7. [root@localhost Packages]# 

7.4、yum工具

  • yum list 列出可用的rpm包

  • ls /etc/yum.repos.d

  • yum search vim 搜索包

  • yum install [-y]

  • yum grouplist

  • yum groupinstall [-y]

  • yum remove [-y]

  • yum update [-y]

  • yum provides "/*/vim"

  • rpm安装时如果包有依赖则提示错误,yum则可以自动解决依赖关系

1. [root@liyanglinux-01 Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
	2. 错误:依赖检测失败:
	3.     texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	4.     texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	5.     tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	6.     tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	7. [root@liyanglinux-01 Packages]# yum install texlive-2012-38.20130427_r30134.el7.x86_64.rpm
	8. 已加载插件:fastestmirror
	9. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
	10. 正在检查 texlive-2012-38.20130427_r30134.el7.x86_64.rpm: 2:texlive-2012-38.20130427_r30134.el7.x86_64
	11. texlive-2012-38.20130427_r30134.el7.x86_64.rpm 将被安装
	12. 正在解决依赖关系
	13. --> 正在检查事务
	14. ---> 软件包 texlive.x86_64.2.2012-38.20130427_r30134.el7 将被 安装
	15. --> 正在处理依赖关系 texlive-scheme-basic,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
	16. base                                                                                                                                                                    | 3.6 kB  00:00:00     
	17. extras                                                                                                                                                                  | 3.4 kB  00:00:00     
	18. updates                                                                                                                                                                 | 3.4 kB  00:00:00     
	19. (1/2): extras/7/x86_64/primary_db                                                                                                                                       | 129 kB  00:00:00     
	20. (2/2): updates/7/x86_64/primary_db                                                                                                                                      | 3.6 MB  00:00:01     
	21. Determining fastest mirrors
	22. * base: mirrors.aliyun.com
	23. * extras: mirrors.aliyun.com
	24. * updates: mirrors.aliyun.com
	25. ^C--> 正在处理依赖关系 texlive-collection-latexrecommended,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
	26. [root@liyanglinux-01 Packages]#



  • yum list 第一列是包名,第二列是版本号,第三列是仓库名;
1. [root@liyanglinux-02 Packages]# yum list
	2. 已加载插件:fastestmirror
	3. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
	4. Determining fastest mirrors
	5. yum-rhn-plugin.noarch                                                                                2.0.1-9.el7                                                                      base     
	6. yum-updateonboot.noarch                                                                              1.1.31-42.el7                                                                    base     
	7. yum-utils.noarch                                                                                     1.1.31-42.el7                                                                    base     
	8. zenity.x86_64                                                                                        3.22.0-1.el7                                                                     base     
	9. zlib.i686                                                                                            1.2.7-17.el7                                                                     base     
	10. zlib-devel.i686                                                                                      1.2.7-17.el7                                                                     base     
	11. zlib-devel.x86_64                                                                                    1.2.7-17.el7                                                                     base     
	12. zlib-static.i686                                                                                     1.2.7-17.el7                                                                     base     
	13. zlib-static.x86_64                                                                                   1.2.7-17.el7                                                                     base     
	14. zsh.x86_64                                                                                           5.0.2-28.el7                                                                     base     
	15. zsh-html.x86_64                                                                                      5.0.2-28.el7                                                                     base     
	16. zziplib.i686                                                                                         0.13.62-5.el7                                                                    base     
	17. zziplib.x86_64                                                                                       0.13.62-5.el7                                                                    base     
	18. zziplib-devel.i686                                                                                   0.13.62-5.el7                                                                    base     
	19. zziplib-devel.x86_64                                                                                 0.13.62-5.el7                                                                    base     
	20. zziplib-utils.x86_64                                                                                 0.13.62-5.el7                                                                    base     



  • base配置文件在/etc/yum.repos.d/CentOS-Base.repo下
1. [root@liyanglinux-02 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo
	2. # CentOS-Base.repo
	3. #
	4. # The mirror system uses the connecting IP address of the client and the
	5. # update status of each mirror to pick mirrors that are updated to and
	6. # geographically close to the client.  You should use this for CentOS updates
	7. # unless you are manually picking other mirrors.
	8. #
	9. # If the mirrorlist= does not work for you, as a fall back you can try the
	10. # remarked out baseurl= line instead.
	11. #
	12. #
	13. [base]
	14. name=CentOS-$releasever - Base
	15. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
	16. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
	17. gpgcheck=1
	18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
	19. #released updates
	20. [updates]
	21. name=CentOS-$releasever - Updates
	22. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
	23. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
	24. gpgcheck=1
	25. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
	26. #additional packages that may be useful
	27. [extras]
	28. name=CentOS-$releasever - Extras
	29. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
	30. #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
	31. gpgcheck=1
	32. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
	33. #additional packages that extend functionality of existing packages
	34. [centosplus]
	35. name=CentOS-$releasever - Plus
	36. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
	37. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
	38. gpgcheck=1
	39. enabled=0
	40. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
	41. [root@liyanglinux-02 Packages]#

  • yum search vim 搜索vim相关的包
1. [root@liyanglinux-02 ~]# yum search vim
	2. 已加载插件:fastestmirror
	3. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
	4. Loading mirror speeds from cached hostfile
	5. * base: mirrors.cn99.com
	6. * extras: mirrors.aliyun.com
	7. * updates: mirrors.cn99.com
	8. ====================================================================================== N/S matched: vim =======================================================================================
	9. protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
	10. vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
	11. vim-common.x86_64 : The common files needed by any version of the VIM editor
	12. vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
	13. vim-filesystem.x86_64 : VIM filesystem layout
	14. vim-minimal.x86_64 : A minimal version of the VIM editor
	15.   名称和简介匹配 only,使用“search all”试试。
	16. [root@liyanglinux-02 ~]#

* yum list |grep 'vim'精准搜索



1. [root@liyanglinux-02 ~]# yum list |grep 'vim'
2. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
3. vim-common.x86_64                           2:7.4.160-2.el7            [@base](https://my.oschina.net/baescn)      
4. vim-enhanced.x86_64                         2:7.4.160-2.el7            [@base](https://my.oschina.net/baescn)    
5. vim-filesystem.x86_64                       2:7.4.160-2.el7            [@base](https://my.oschina.net/baescn)    
6. vim-minimal.x86_64                          2:7.4.160-1.el7            @anaconda       
7. protobuf-vim.x86_64                         2.5.0-8.el7                base     
8. vim-X11.x86_64                              2:7.4.160-2.el7            base     
9. vim-minimal.x86_64                          2:7.4.160-2.el7            base     
10. [root@liyanglinux-02 ~]#
  • yum install -y 包名,参数-y安装时不再询问是否安装
  • yum grouplist列出组
    1. [root@liyanglinux-02 ~]# yum grouplist
	2. 已加载插件:fastestmirror
	3. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
	4. 没有安装组信息文件
	5. Maybe run: yum groups mark convert (see man yum)
	6. Loading mirror speeds from cached hostfile
	7. * base: mirrors.cn99.com
	8. * extras: mirrors.aliyun.com
	9. * updates: mirrors.cn99.com
	10. 可用的环境分组:
	11.    最小安装
	12.    基础设施服务器
	13.    计算节点
	14.    文件及打印服务器
	15.    基本网页服务器
	16.    虚拟化主机
	17.    带 GUI 的服务器
	18.    GNOME 桌面
	19.    KDE Plasma Workspaces
	20.    开发及生成工作站
	21. 可用组:
	22.    传统 UNIX 兼容性
	23.    兼容性程序库
	24.    图形管理工具
	25.    安全性工具
	26.    开发工具
	27.    控制台互联网工具
	28.    智能卡支持
	29.    科学记数法支持
	30.    系统管理
	31.    系统管理工具
	32. 完成
	33. [root@liyanglinux-02 ~]#

  • yum groupinstall -y 包名,安装组件
  • yum remove 卸载包
  • yum update 不加任何包名则默认升级所有(包括系统)
  • yum provides "/*/vim"搜索出所有关于vim命令的包

7.5、yum搭建本地仓库

  • 挂载镜像到/mnt目录
  • cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
  • rm -f /etc/yum.repos.d/*
  • vim /etc/yum.repos.d/dvd.repo 内容如下
    1. [root@liyanglinux-02 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
	2. [root@liyanglinux-02 ~]# cd /etc/yum.repos.d
	3. [root@liyanglinux-02 yum.repos.d]# ls
	4. CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
	5. [root@liyanglinux-02 yum.repos.d]# rm -f ./*
	6. [root@liyanglinux-02 yum.repos.d]# vim dvd.repo
	7. [dvd]
	8. name=install dvd
	9. baseurl=file:///mnt    /base位置
	10. enable=1                /是否可用:1表示可用,0表示不可用
	11. gpcheck=0             /0表示不检测
	12. :wq

  • yum clean all 清空yum
  • yum list |less 查看本地yum仓库
    1. zip.x86_64                              3.0-11.el7                     @anaconda
	2. zlib.x86_64                             1.2.7-17.el7                   @anaconda         /@anaconda表示已经安装过的
	3. 可安装的软件包
	4. 389-ds-base.x86_64                      1.3.5.10-11.el7                dvd      
	5. 389-ds-base-libs.x86_64                 1.3.5.10-11.el7                dvd      /dvd表示本地搭建的yum仓库
	6. ElectricFence.x86_64                    2.2.2-39.el7                   dvd   


  • 搭建本地yum仓库便于安装,如果使用rpm安装则提示依赖包;

扩展学习

  • 使yum保留已经下载的rpm包
  • 目的:升级或者重新安装使用
  • 操作:修改/etc/yum.conf文件
        1. [main]
	2. cachedir=/home/soft1/yumcache    /cachedir是指一个路径,存放下载的包的位置
	3. keepcache=1    /keepcache=1时表示保存已经下载的rpm包
	4. dubuglevel=2

  • yum局域网软件源搭建

yum局域网软件源搭建部分转载

转载于:https://my.oschina.net/u/3706694/blog/1573152

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值