Linux installation and package management

First, the package classification

1, the source package

  Source package can directly see the source code, we need to go to the official website to download the software, usually in order to facilitate the release of source package will do the packing process compression (compression format is commonly used in packaging "tar.gz"), which generally contain multiple files ( source code files, configuration and testing procedures, software, and the software installation instructions).
Advantages:
  ① open, if there is sufficient capacity, can directly modify the source code;
  corresponding function can be selected according to their needs ② When installed, the more their own system, and more stable and efficient;
  convenient ③ unloaded directly delete the installation Catalog software can be.
Disadvantages:
  ① installation step more, especially when installing large software collections, error prone;
  ② because it is compiled and installed, the installation process once a novice error is difficult to solve;
  ③ compile a long time.

2, binary packages

  Binary package is the source package after package generated after the successful compilation, is the default under Linux software installation package.
Advantages:
  ① simple package management system, you need only a few commands you can achieve the installation package, upgrading, querying, and unloading;
  ② installed much faster than the source package;
  ③ little chance of an error during the installation process.
Disadvantages:
  ① has been built, can not see the source code;
  ② inferior function selection Source Package flexibility;
  ③ the installation process have many dependencies, dependence not been resolved.

Second, the installation

1, YUM installation

  ① YUM Profile

  yum (Yellow dog Updater, Modified) is a front end package manager Shell Fedora and RedHat and CentOS in. RPM-based package management, can automatically download from the specified server RPM package and install, can automatically handle dependencies, and install all packages depending on , again and again without the cumbersome download and installation. yum provides search, install, remove one, or all of a set of packages command, and command concise and easy to remember.

  ② YUM command

  • Command interpreter

  yum - Yellowdog Updater Modified (Shell front-end package manager)

  • Command syntax

  yum [options] [command] [package …]

  Wherein, [Options] is optional, options include -H (Help), - y (the installation process when prompted to select all "yes"), - q (during installation not shown) and the like; [Command] is to be performed operation; [Package] is operation of the object.

  • Commonly used yum commands
  Ⅰ, display and search a
Command For work
yum repolist [all / enabled / disabled] Display configuration repository [All / enable / disable]
yum list [all] Show all packages
yum list | grep package name Find the specified package
yum list installed Show all of the installed packages
yum list available Display the installable software packages
yum list updates Show Package updated
yum list recent Display recently added package
yum search keyword Specified on the package keyword fuzzy query
yum info package name Displays the information package
yum provides the package name Lists the files in the package
  Ⅱ, installation
Command For work
yum install package name Install specific software package (process requires confirmation)
yum install package name -y Install specific software packages (without confirmation)
  Ⅲ, update
Command For work
yum update package name Updates the specified package
yum check-update Check the program can be updated
  Ⅳ, uninstall
Command For work
yum remove package name Uninstall the installed packages
  Ⅴ, creating and clear the cache
Command For work
yum makechche Build the cache
yum clean all clear cache

  ③ source arranged yum

  yum resources management is downloaded from the specified server, and this place is called the resource download source yum. When using yum to install the software needs at least a source yum , yum this source can be either a network source , it can also be a local source . Then as we demonstrate two ways to build yum source.

  Ⅰ, yum source network structures (source to aliyun Example)
[root@localhost ~]# yum install wget    //安装wget(一个从网络上自动下载文件的自由工具)

[root@localhost /]# cd /etc/yum.repos.d/    //备份/etc/yum/repos.d/CentOS-Base.repo文件
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.backup

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo    //下载新的CentOS-Base.repo到/etc/yum.repos.d(以CentOS-7.repo为例)
--2020-03-17 09:31:20--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.19.177.243, 111.19.210.115, 111.19.177.248, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.19.177.243|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[======================================>] 2,523       --.-K/s 用时 0s

2020-03-17 09:31:20 (10.5 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])


[root@localhost yum.repos.d]# yum clean all    //清理缓存
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors

[root@localhost yum.repos.d]# yum makecache    //构建缓存
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                     | 3.6 kB     00:00
extras                                                   | 2.9 kB     00:00
updates                                                  | 2.9 kB     00:00
(1/10): base/7/x86_64/group_gz                             | 165 kB   00:00
(2/10): base/7/x86_64/filelists_db                         | 7.3 MB   00:02
(3/10): base/7/x86_64/other_db                             | 2.6 MB   00:00
(4/10): extras/7/x86_64/filelists_db                       | 216 kB   00:00
(5/10): extras/7/x86_64/other_db                           | 106 kB   00:00
(6/10): base/7/x86_64/primary_db                           | 6.0 MB   00:03
(7/10): updates/7/x86_64/filelists_db                      | 4.0 MB   00:01
(8/10): updates/7/x86_64/other_db                          | 493 kB   00:01
(9/10): updates/7/x86_64/primary_db                        | 6.7 MB   00:02
(10/10): extras/7/x86_64/primary_db                        | 164 kB   00:04
元数据缓存已建立
  Ⅱ, local source structures yum

  In the absence of network conditions, yum can use a local CD-ROM (image file) as yum source, Linux system installation image file will contain almost all commonly used the RPM package, and therefore sufficient to meet our needs.

[root@localhost ~]# mount /dev/sr0 /media/    //挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# cd /etc/yum.repos.d/    //备份yum源配置文件
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv Cen* backup/

[root@localhost yum.repos.d]# cp backup/CentOS-Media.repo CentOS-Media.repo    //我们以CentOS-Media.repo为模板进行修改(此文件就是以本地光盘作为 yum源的模板文件,只需进行简单的修改即可)
[root@localhost yum.repos.d]# vim CentOS-Media.repo
[CentOS]    //软件源的名字,不能为空
name=CentOS-Media    //软件源的描述
baseurl=file:///media/    //指定服务器地址,因为是本地文件所以使用file,在这里一定要注意是三个"/",其中前两个是标准格式,第三个是目录路径。
gpgcheck=0    //表示下载软件包时是否检查签名,0表示不检查,1表示检查
enabled=1    //表示是否启用这个软件源,0表示不启用,1表示启用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7    //开启gpgcheck后通过gpgkey来指定相应的签名认证信息路径

[root@localhost yum.repos.d]# yum clean all    //清理缓存
已加载插件:fastestmirror
正在清理软件源: CentOS
Cleaning up list of fastest mirrors
Other repos take up 79 M of disk space (use --verbose for details)

[root@localhost yum.repos.d]# yum makecache    //构建缓存
已加载插件:fastestmirror
Determining fastest mirrors
CentOS                                                   | 3.6 kB     00:00
(1/4): CentOS/group_gz                                     | 166 kB   00:00
(2/4): CentOS/filelists_db                                 | 3.2 MB   00:00
(3/4): CentOS/primary_db                                   | 3.1 MB   00:00
(4/4): CentOS/other_db                                     | 1.3 MB   00:00
元数据缓存已建立

2, RPM installation

  ① RPM Profile

  rpm (redhat package manager) was originally Red Hat Linux distributions designed to manage the Linux program suite, because it is easy to follow and powerful GPL rules, so popular. Gradually adopted by other distributions. yum can automatically determine the dependency, a plurality of one-time installation rpm package, but the principle and one mounted rpm package is no essential difference.

  Where ② RPM package?

[root@localhost ~]# mount /dev/sr0 /media/   //首先需要挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# cd /media/    //进入挂载点
[root@localhost media]# ll    //Package这个目录里就是自带编译好的rpm程序包
总用量 686
-rw-rw-r--. 1 root root     14 11月 26 2018 CentOS_BuildTag
drwxr-xr-x. 3 root root   2048 11月 26 2018 EFI
-rw-rw-r--. 1 root root    227 8月  30 2017 EULA
-rw-rw-r--. 1 root root  18009 12月 10 2015 GPL
drwxr-xr-x. 3 root root   2048 11月 26 2018 images
drwxr-xr-x. 2 root root   2048 11月 26 2018 isolinux
drwxr-xr-x. 2 root root   2048 11月 26 2018 LiveOS
`drwxrwxr-x. 2 root root 663552 11月 26 2018 Packages`
drwxrwxr-x. 2 root root   4096 11月 26 2018 repodata
-rw-rw-r--. 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root   2883 11月 26 2018 TRANS.TBL
[root@localhost media]# cd Packages/    //进入Package目录
[root@localhost Packages]# ls    //rpm包命名原则:软件包名-版本号-发布次数-适用系统-适用的CPU架构平台_支持系统位数.包扩展名(rpm)
...
zenity-3.28.1-1.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-18.el7.x86_64.rpm
zlib-devel-1.2.7-18.el7.x86_64.rpm
zsh-5.0.2-31.el7.x86_64.rpm
zziplib-0.13.62-9.el7.x86_64.rpm
...

  ③ RPM command

  • Command interpreter

  rpm - RPM Package Manager (RPM Package Manager)

  • Command syntax

  rpm [options] ... [complete package]

  • Commonly used command rpm
  Ⅰ, installation

  rpm -ivh 完整软件包名

Options For work
-i Installation (install)
-v Displays detailed information (verbose)
-h Show progress bar (hash), each # represents progress% 2
--force Mandatory installation
--nodeps Ignore dependence
  Ⅱ, upgrade

  rpm -Uvh 完整软件包名     If the software is not installed directly installed; if not install the upgrade to the latest version
  rpm -Fvh 完整软件包名     if the software is not installed, is not installed, you must install a lower version to upgrade

Options For work
-U Upgrade or install
-F upgrade
  Ⅲ, uninstall

  Uninstall RPM packages to consider dependencies between packages,After install uninstall, uninstall after installation.
  rpm -e 软件包名

Options For work
-e Uninstall (erase)
  Ⅳ, inquiry

  rpm -q 软件包名         Query whether the package installation
  rpm -qa           queries all installed packages
  rpm -qi           query information package
  rpm -qf 文件名        which RPM package query system files that belong to
  rpm -qR 软件包名       independent inquiry package

Options For work
-q Query (query)
-a All (all)
-i Package information (information)
-f System file belongs package (file)
-R Package dependencies (rely)
  IV, calibration

  rpm -V 已安装的软件包名

Options For work
-V To calibrate the specified rpm package file (Verify)

  After executionNo tips, It indicates that the file installed by the package were not altered.

3, the installation source

  ① Installation

  Ⅰ, Download Source Package

  Download software specified source package (suffix "tar.gz" or "tar.bz2") to under "/ usr / local / src" directory (recommend you go to the official website to download).

  Ⅱ, extract the source packet
[root@localhost src]# tar -zxvf 软件包全名    //解压后缀名为tar.gz的源码包
[root@localhost src]# tar -jxvf 软件包全名    //解压后缀名为tar.bz2的源码包
  Ⅲ, switch to the source directory (decompressed) for performing a subsequent operation

  We can see the INSTALL file, some of which read the installation instructions. In general source installation requires three steps:Configuration (configure) → compile (make) → installation (make install)

  a, configure # ./configure

  You can be parameterized with the following:

Parameter For work
Installation path --prefix = Specify the installation path
--enable-FEATURE Enable a feature
--disable-FEATURE Disabling a feature
--with-package = path where the packet Associated with other software

  Configuration operations mainlyDefinition of the required options检测系统环境是否符合安装要求(例如,是否有gcc编译器,是否满足依赖需求等)、把系统环境的检测结果和定义好的功能选项写入 Makefile 文件(后续的编译和安装需要依赖这个文件的内容)。

  b、编译 # make

  make 会调用 gcc 编译器,并读取 Makefile 文件中的信息进行系统软件编译。

  c、安装 # make install

  根据Makefile定义的文件路径进行安装,整个过程不报错,即为安装成功。如果出现"error"或"warning"且安装过程停止,表示安装失败;但是如果仅出现警告信息,但安装过程还在继续,这并不是安装失败!

tips:如果在 “./configure” 或 “make” 两步中出现错误,则在重新执行这两步前必须执行 make clean 命令,它会清空 Makefile 文件或编译产生的 “.o” 头文件。

  ② 卸载

  源码包卸载非常简单便利,只需要直接删除软件的安装目录即可,但删除前记得将软件的服务停止哦!

发布了12 篇原创文章 · 获赞 220 · 访问量 2万+

Guess you like

Origin blog.csdn.net/weixin_43898125/article/details/104903507