0
点赞
收藏
分享

微信扫一扫

CentOS软件包管理


1 软件包管理介绍

软件包管理,顾名思义就是对Linux操作系统的软件及安装包进行管理,比如下载、安装、卸载、删除等等,就好比我们Windows上的控制面板->软件管理。

Linux(CentOS)软件包分类:

CentOS软件包管理_ssh

与Windows对比

Linux(CentOS)

Windows

rpm

exe

源码包

软件源码(.java)

二进制包

可执行文件(.jar)

软件包管理工具分类

CentOS软件包管理_centos_02

与Windows对比

Linux(CentOS)

Windows

rpm

exe直接安装

yum

先联网下载.exe再安装

2 rpm包管理

2.1 简介

名称规则:

CentOS软件包管理_ssh_03

主要功能:

安装、卸载、升级和管理软件,组件查询功能,验证功能,软件包GPG和MD5数字签名的导入、验证和发布,软件包依赖处理,选择安装,网络远程安装功能

2.2 常见命令

2.2.1 软件安装

(1)命令

rpm -i [安装包]

(2)演示

[root@iZ1608aqb7ntn9Z tmp]# rpm -i jre-7u51-linux-i586.rpm 
Unpacking JAR files...
rt.jar...
......

(3)常用参数

  • rpm -ivh [安装包] :显示安装进度
[root@iZ1608aqb7ntn9Z tmp]# rpm -ivh jre-7u51-linux-i586.rpm 
Verifying... ################################# [100%]
准备中... ################################# [100%]
......
2.2.2 已安装软件搜索

(1)命令

rpm -q [安装包名称]

(2)演示

[root@iZ1608aqb7ntn9Z tmp]# rpm -q jre
jre-1.7.0_51-fcs.i586

(3)常用参数

  • rpm -qa [安装包名称]:显示全部软件安装包
[root@iZ1608aqb7ntn9Z tmp]# rpm -qa jre
jre-1.7.0_51-fcs.i586
  • rpm -qi [安装包名称]:查看指定软件包的名称、版本、许可协议、用途描述等详细信息
[root@iZ1608aqb7ntn9Z tmp]# rpm -qi jre
Name : jre
Version : 1.7.0_51
Release : fcs
Architecture: i586
Install Date: 2021年08月30日 星期一 14时43分36秒
Group : Development/Tools
Size : 82103392
License : http://java.com/license
Signature : (none)
Source RPM : jre-1.7.0_51-fcs.src.rpm
Build Date : 2013年12月19日 星期四 11时28分49秒
Build Host : jdk7-lin2-i586.us.oracle.com
Relocations : /usr/java
Packager : Java Software <jre-comments@java.sun.com>
Vendor : Oracle Corporation
URL : URL_REF
Summary : Java Platform Standard Edition Runtime Environment
Description :
......
  • rpm -ql [安装包名称]:显示指定的软件包在当前系统中安装的所有目录、文件列表
[root@iZ1608aqb7ntn9Z tmp]# rpm -ql jre
/etc
/etc/.java
/etc/.java/.systemPrefs
/etc/.java/.systemPrefs/.system.lock
/etc/.java/.systemPrefs/.systemRootModFile
/etc/init.d/jexec
/usr
/usr/java
/usr/java/jre1.7.0_51
/usr/java/jre1.7.0_51/COPYRIGHT
/usr/java/jre1.7.0_51/LICENSE
/usr/java/jre1.7.0_51/README
......
2.2.3 已安装软件卸载

(1)命令

rpm -e [安装包/安装包名称]

(2)演示

[root@iZ1608aqb7ntn9Z tmp]# rpm -q jre
jre-1.7.0_51-fcs.i586
[root@iZ1608aqb7ntn9Z tmp]# rpm -e jre-1.7.0_51-fcs.i586
警告:文件 /usr/java/jre1.7.0_51/lib/install.jar:移除失败:没有那个文件或目录
[root@iZ1608aqb7ntn9Z tmp]# rpm -q jre
未安装软件包 jre
2.2.4 其他命令

rpm --force [安装包]:强制安装某个软件包

rpm --nodeps [安装包]:在安装或升级、卸载一个软件包时,不检查与其他软件包的依赖关系

3 yum包管理

3.1 简介

Yum 是 Red Hat 软件包管理器,它能够查询有关可用软件包的信息,从存储库获取软件包,安装和卸载软件包,以及将整个系统更新到最新的可用版本。Yum在更新,安装或删除软件包时执行自动依赖性解析,因此能够自动确定,获取和安装所有可用的依赖软件包。

3.2 配置yum源(CentOS8,其他版本建议自行百度)

[root@iZ1608aqb7ntn9Z yum.repos.d]# touch CentOS-AppStream.repo CentOS-BaseOS.repo CentOS-Extras.repo
[root@iZ1608aqb7ntn9Z yum.repos.d]# ls
CentOS-AppStream.repo CentOS-centosplus.repo CentOS-Extras.repo CentOS-Sources.repo
CentOS-BaseOS.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo docker-ce.repo
CentOS-Base.repo.bak CentOS-epel.repo CentOS-PowerTools.repo kubernetes.repo
[root@iZ1608aqb7ntn9Z yum.repos.d]# vim CentOS-AppStream.repo
# 写入文件
[aliyun-AppStream]
name=CentOS-$releasever - AppStream
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# 写入完成
[root@iZ1608aqb7ntn9Z yum.repos.d]# vim CentOS-BaseOS.repo
# 写入文件
[aliyun-BaseOS]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# 写入完成
[root@iZ1608aqb7ntn9Z yum.repos.d]# vim CentOS-Extras.repo
# 写入文件
[aliyun-extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# 写入完成
[root@iZ1608aqb7ntn9Z yum.repos.d]# dnf -y install epel-release
[root@iZ1608aqb7ntn9Z yum.repos.d]# dnf clean all
[root@iZ1608aqb7ntn9Z yum.repos.d]# dnf makecache
[root@iZ1608aqb7ntn9Z yum.repos.d]# dnf repolist
仓库 'aliyun-AppStream' 在配置中缺少名称,将使用 id。
仓库 'aliyun-BaseOS' 在配置中缺少名称,将使用 id。
仓库 'aliyun-extras' 在配置中缺少名称,将使用 id。
Repository centosplus is listed more than once in the configuration
仓库 id 仓库名称
aliyun-AppStream aliyun-AppStream
aliyun-BaseOS aliyun-BaseOS
aliyun-extras aliyun-extras
base CentOS-8 - Base - mirrors.aliyun.com
docker-ce-stable Docker CE Stable - x86_64
epel Extra Packages for Enterprise Linux 8 - x86_64
extras CentOS-8 - Extras - mirrors.aliyun.com
kubernetes Kubernetes
updates CentOS-8 - Updates - mirrors.aliyun.com
[root@iZ1608aqb7ntn9Z yum.repos.d]# rm -rf CentOS-AppStream.repo CentOS-BaseOS.repo CentOS-Extras.repo

3.3 常用命令

3.3.1 安装

(1)命令

yum install [安装包名称]

(2)演示

[root@iZ1608aqb7ntn9Z yum.repos.d]# yum install redis
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:02:07 前,执行于 2021年08月30日 星期一 16时06分30秒。
依赖关系解决。
==========================================================================================================================
软件包 架构 版本 仓库 大小
==========================================================================================================================
安装:
redis x86_64 5.0.3-2.module_el8.2.0+318+3d7e67ea AppStream 925 k
启用模块流:
redis 5

事务概要
==========================================================================================================================
安装 1 软件包

总下载:925 k
安装大小:3.2 M
确定吗?[y/N]: y
......

(3)常用参数

  • yum -y install [安装包名称]:无询问安装
[root@iZ1608aqb7ntn9Z yum.repos.d]# yum -y install gcc
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - Base - mirrors.aliyun.com 14 MB/s | 5.6 MB 00:00
CentOS-8 - Extras - mirrors.aliyun.com 38 kB/s | 10 kB 00:00
CentOS-8 - AppStream - mirrors.aliyun.com 21 MB/s | 8.8 MB 00:00
......
3.3.2 查看已安装的安装包

(1)命令

  • yum list : 列出所有可安装的软件包
  • yum list updates : 列出所有可更新的软件包
  • yum list installed: 列出所有已安装的软件包

(2)演示

命令的结果显示较长,在这里不做演示

3.3.3 查找安装包

(1)命令

yum search [要查找的关键词]

(2)演示

[root@iZ1608aqb7ntn9Z tmp]# yum search vim
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:05:07 前,执行于 2021年08月30日 星期一 16时06分30秒。
================================================= 名称 和 概况 匹配:vim =================================================
awesome-vim-colorschemes.noarch : Collection of color schemes for Neo/vim, merged for quick use
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editor
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
geany-plugins-vimode.x86_64 : Vim-mode plugin for Geany
neovim.x86_64 : Vim-fork focused on extensibility and agility
python-neovim-doc.noarch : Documentation for python-neovim
python3-neovim.noarch : Python client to Neovim
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System - GVim
vim-airline.noarch : Lean & mean status/tabline for vim that's light as air
vim-ansible.noarch : Vim plugin for syntax highlighting ansible's common filetypes
......
3.3.4 卸载

(1)命令

yum remove [安装包或关键词]

(2)演示

[root@iZ1608aqb7ntn9Z tmp]# yum remove vim
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
依赖关系解决。
......
移除 4 软件包
......

4 源码包和二进制包

4.1 介绍

源码包就是软件的开发源码,比如用C语言开发的软件源码一般都会是以.c结尾的文件集,用Java开发的软件源码都是以.java为后缀的文件,因此源码包并不能直接安装运行,需要编译之后才能进行安装和运行,Linux中常见的软件源码安装包都是以.tar.gz结尾的压缩文件,将其解压后就可以看见软件的开发源码。

例如Maven,上边的红框框里就是二进制包,下边的红框框就是源码包,压缩格式分别是.zip和.tar.gz

CentOS软件包管理_centos_04

4.2 常见的解压命令

(1)zip压缩包

nuzip [压缩包名称] :解压zip的压缩包

(2)tar.gz压缩包

tar -zxvf [压缩包名称] :解压tar.gz压缩包

tar -xvf [压缩包名称] :解压tar压缩包

5 总结

在CentOS中有rpm和yum两种软件包管理,总结优缺点,rpm包安装简便不用联网,但是如果出现依赖关系无法自动解决,需要手动寻找依赖,yum包安装需要联网,可以自动解决依赖。



举报

相关推荐

0 条评论