Loading

Linux 应用程序的安装和管理

CentOS-Logo

Linux中,有三种安装软件的方式,分别是RPM包安装、YUM源安装、源代码编译安装。


常见应用程序目录结构

类型 路径
普通用户可执行文件 /usr/bin
管理员可执行文件 /usr/sbin
配置文件 /etc
日志文件 /var/log
应用程序参考文档 /usr/share/doc
执行文件、配置文件的man手册 /usr/share/man

常见软件包封装类型

  • RPM

扩展名.rpm,只能在使用rpm机制的Linux中安装,如RHELCentOS

  • DEB

扩展名.deb,只能在使用dpkg机制的Linux中安装,如DebianUbuntu

  • 源代码软件包

包含原始代码的.tar.gz.tar.bz2的压缩包TarBall,安装需要相应的编译工具,CC++

  • 附带安装程序的软件包

软件包中提供install.shsetup等,运行以根据向导程序的提示完成安装操作。


RPM包

查询 RPM 包信息

已安装

  • rpm -q[子选项] [准确的软件名]

-qa:显示所有以RPM方式安装的软件
-qi:查看指定软件包的名称、版本等详细信息(--info)
-ql:显示指定软件包安装的所有目录、文件列表(--list)
-qf:查看指定的文件或目录是由哪个软件包所安装的(--file)

[root@localhost ~]# rpm -qa
linux-firmware-20170606-56.gitc990aae.el7.noarch
centos-release-7-4.1708.el7.centos.x86_64
kbd-1.15.5-13.el7.x86_64
setup-2.8.71-7.el7.noarch
……      //省略
[root@localhost ~]# rpm -qa | wc -l
343
[root@localhost ~]# rpm -q vim-common
vim-common-7.4.160-6.el7_6.x86_64
[root@localhost ~]# rpm -qa | grep vim
vim-filesystem-7.4.160-6.el7_6.x86_64
vim-enhanced-7.4.160-6.el7_6.x86_64
vim-common-7.4.160-6.el7_6.x86_64
vim-minimal-7.4.160-2.el7.x86_64
[root@localhost ~]# rpm -qi vim-common
Name        : vim-common
Epoch       : 2
Version     : 7.4.160
Release     : 6.el7_6
Architecture: x86_64
Install Date: Tue 20 Aug 2019 03:18:40 PM CST
Group       : Applications/Editors
Size        : 22146036
License     : Vim
Signature   : RSA/SHA256, Mon 01 Jul 2019 09:34:28 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-6.el7_6.src.rpm
Build Date  : Fri 28 Jun 2019 09:59:48 PM CST
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : The common files needed by any version of the VIM editor
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-common package contains files which every VIM binary will need in
order to run.

If you are installing vim-enhanced or vim-X11, you'll also need
to install the vim-common package.
[root@localhost ~]# rpm -ql vim-common
/etc/vimrc
/usr/bin/xxd
/usr/share/doc/vim-common-7.4.160
/usr/share/doc/vim-common-7.4.160/Changelog.rpm
/usr/share/doc/vim-common-7.4.160/LICENSE
……      //省略
[root@localhost ~]# which vim
/usr/bin/vim
[root@localhost ~]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-6.el7_6.x86_64

未安装

  • rpm -qp[子选项] 软件路径

-qpi:查看指定软件包的名称、版本等详细信息
-qpl:显示指定软件包准备安装的所有目标目录、文件列表

[root@localhost ~]# cd /mnt/cdrom/Packages/
[root@localhost Packages]# rpm -qpi vim-common-7.4.160-2.el7.x86_64.rpm
Name        : vim-common
Epoch       : 2
Version     : 7.4.160
Release     : 2.el7
Architecture: x86_64
Install Date: (not installed)
Group       : Applications/Editors
Size        : 22146173
License     : Vim
Signature   : RSA/SHA256, Fri 11 Aug 2017 04:15:28 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-2.el7.src.rpm
Build Date  : Wed 02 Aug 2017 08:46:12 AM CST
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : The common files needed by any version of the VIM editor
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-common package contains files which every VIM binary will need in
order to run.

If you are installing vim-enhanced or vim-X11, you'll also need
to install the vim-common package.
[root@localhost Packages]# rpm -qpl vim-common-7.4.160-2.el7.x86_64.rpm
/etc/vimrc
/usr/bin/xxd
/usr/share/doc/vim-common-7.4.160
/usr/share/doc/vim-common-7.4.160/Changelog.rpm
/usr/share/doc/vim-common-7.4.160/LICENSE
……      //省略

安装、升级、卸载

-i:安装
-e:卸载
-U:检查升级,未安装则安装
-F:检查升级,未安装则不安装
--force:强制安装
--nodeps:安装、卸载、升级时,不检查与其他软件包的依赖问题。
-h:安装、升级时,以#显示进度。
-v:显示安装过程详细信息。

  • rpm -ivh:安装
[root@localhost Packages]# rpm -ivh wget-1.14-15.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:wget-1.14-15.el7                 ################################# [100%]
  • rpm -evh:卸载
[root@localhost Packages]# rpm -evh wget
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:wget-1.14-18.el7_6.1             ################################# [100%]
  • rpm --rebuilddbrpm --initdb:当RPM数据库损坏时,重建。
[root@localhost Packages]# rpm --rebuilddb
[root@localhost Packages]# rpm --initdb

YUM源

  • 安装、卸载
yum install 软件名
yum remove 软件名 / yum erase 软件名
  • 搭建本地YUM

1.挂载光盘

[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G 1015M   16G   6% /
devtmpfs                devtmpfs  901M     0  901M   0% /dev
tmpfs                   tmpfs     912M     0  912M   0% /dev/shm
tmpfs                   tmpfs     912M  8.7M  904M   1% /run
tmpfs                   tmpfs     912M     0  912M   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  143M  872M  15% /boot
tmpfs                   tmpfs     183M     0  183M   0% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0 100% /mnt/cdrom

2.备份已有的YUM

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS-* bak/

3.新建本地YUM

vi /etc/yum.repo.d/local.repo
[local]
name = centos7.4
baseurl = file:///mnt/cdrom
gpgcheck = 0
enabled = 1

4.缓存重建

yum clean all
yum list

源代码

概述

  • 需要使用源代码安装的情况:

1.安装较新版本的应用程序时
2.当前安装的程序无法满足应用需求
3.为应用程序添加新的功能

特点:源代码编译安装为使用者提供了更加灵活的程序功能定制途径,还能获得最新版本,及时修复BUG

  • 完整性校验(考虑安全因素)
md5sum 压缩包名
  • 开发环境(编译需要)

gccmake时由GUN项目所贡献的功能强大的C/C++语言编译器。

gcc --version
make --version

编译安装过程

  • 下载源代码安装包文件

  • 解包、配置、编译、安装

序号 操作 用途
1 tar 解包 解压并释放源代码包到指定目录
2 ./configure 配置 设置安装目录、安装模块等选项
3 make 编译 生成可执行的二进制文件
4 make install 安装 复制二进制文件到系统,配置应用环境
  • 测试及应用、维护软件

以后会有关于源代码安装的例子,这里不做过多介绍。

posted @ 2019-08-20 08:18  LinSenGeGe  阅读(1336)  评论(0编辑  收藏  举报