Three ways to install software packages under Linux
- rpmtools
- yumtools
- Source package installation
yum is a tool for installing RPM packages unique to Redhat, which is quite convenient to use. Because using RPM to install a package may fail to install because the package depends on another package, using the yum tool can be installed together with the dependent package. CentOS can also use yum tool, and yum can be used for free in CentOS, but yum can only be used after paying for it in Redhat, and yum cannot be used by default.
RPMtools
RPM is short for "Redhat Package Manager". RPM is a set of management programs that install required packages on Linux hosts in a database-recorded manner. There is a database about RPM in the Linux system, which records the installed packages and dependencies between packages. RPM packages are pre-compiled and packaged files on Linux machines, and are very quick to install. However, there are also some disadvantages, such as the installation environment must be the same as or equivalent to the environment at compile time; there is interdependence between packages; when uninstalling a package, you need to uninstall the dependent package first, if the dependent package is the system If necessary, you cannot uninstall this package, otherwise it will cause the system to crash. RHEL, CentOS, and SUSE systems can all use rpm packages.
In the opened Vmware virtual machine, click the small CD-ROM icon at the bottom right, select "Connect", and connect the system installation disk to the Linux system.
- Mount the CD-ROM to the /mnt directory
[root@centos-01 mytest]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.3G 27G 5% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 197M 97M 100M 50% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@centos-01 mytest]# ls /mnt/
[root@centos-01 mytest]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos-01 mytest]# cd /mnt/
[root@centos-01 mnt]# ls
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
[root@centos-01 mnt]# cd Packages/
There are many files in the /mnt/Packages directory .rpm
, which are RPM packages. RPM package format: package name-version number-release version number-platform.rpm.
install rpm package
- "-i": install
- "-v": visualize
- "-h": show installation progress
- "
--force
": Force installation, even if overwriting files belonging to other packages - "
--nodeps
": When the rpm package to be installed depends on other packages, even if other packages are not installed, install this package
[root@centos-01 Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
upgrade rpm package
- "-U": upgrade
Orderrpm -Uvh filename
uninstall rpm package
Orderrpm -e filename
The filename here is the rpm package name. There is a difference between the filename that follows during uninstallation and the one during installation. An existing file is used as a parameter during installation, and only the package name is required during uninstallation.
[root@centos-01 Packages]# rpm -e zsh
Query all installed rpm packages of the current system
[root@centos-01 Packages]# rpm -qa
Check whether the rpm package is installed
Order:rpm -q 包名
[root@centos-01 Packages]# rpm -q vim
未安装软件包 vim
[root@centos-01 Packages]# rpm -q vim-enhanced
vim-enhanced-7.4.160-2.el7.x86_64
Query information about installed rpm packages
Order:rpm -qi 包名
[root@centos-01 Packages]# rpm -qi vim-enhanced
Name : vim-enhanced
Epoch : 2
Version : 7.4.160
Release : 2.el7
Architecture: x86_64
Install Date: 2018年04月22日 星期日 15时39分56秒
Group : Applications/Editors
Size : 2292098
License : Vim
Signature : RSA/SHA256, 2017年08月11日 星期五 04时15分38秒, Key ID 24c6a8a7f4a80eb5
Source RPM : vim-7.4.160-2.el7.src.rpm
Build Date : 2017年08月02日 星期三 08时46分12秒
Build Host : c1bm.rdu2.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.
List files installed by rpm package
Order:rpm -ql 包名
[root@centos-01 Packages]# 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
Check which package a file was installed by
Order:rpm -qf 文件的绝对路径
[root@centos-01 Packages]# which vim
/usr/bin/vim
[root@centos-01 Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-2.el7.x86_64
[root@centos-01 Packages]# rpm -qf `which vim`
vim-enhanced-7.4.160-2.el7.x86_64
yumtools
The yum tool is much easier to use than the rpm tool. Of course, the premise is that the currently used Linux system supports yum. The biggest advantage of yum is that it can download the required rpm packages from the Internet, and then install them automatically. During this process, if the rpm packages to be installed have dependencies, yum will resolve these dependencies and install all rpm packages in turn.
List all available rpm packages
[root@centos-01 Packages]# yum list
search for rpm packages
[root@centos-01 Packages]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
===================================== N/S matched: vim =====================================
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editor
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
neovim.x86_64 : Vim-fork focused on extensibility and agility
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
python2-neovim.noarch : Python client to Neovim
python34-neovim.noarch : Python client to Neovim
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-go.x86_64 : Go development plugin for Vim
vim-gtk-syntax.noarch : Vim syntax highlighting for GLib, Gtk+, Gstreamer, and more
vim-jellybeans.noarch : A colorful, dark color scheme for Vim
vim-minimal.x86_64 : A minimal version of the VIM editor
vim-toml.noarch : Vim syntax for TOML
vim-vimoutliner.noarch : Script for building an outline editor on top of Vim
xtuple-csvimp-devel.x86_64 : CSVImp development files
vim-fugitive.noarch : A Git wrapper so awesome, it should be illegal
vim-halibut.noarch : Syntax file for the halibut manual tool
xtuple-csvimp.x86_64 : xTuple data import utility
名称和简介匹配 only,使用“search all”试试。
[root@centos-01 Packages]# yum list |grep 'vim'
vim-common.x86_64 2:7.4.160-2.el7 @base
vim-enhanced.x86_64 2:7.4.160-2.el7 @base
vim-filesystem.x86_64 2:7.4.160-2.el7 @base
vim-minimal.x86_64 2:7.4.160-2.el7 @anaconda
beakerlib-vim-syntax.noarch 1.17-13.el7 epel
fluxbox-vim-syntax.noarch 1.3.7-1.el7 epel
neovim.x86_64 0.2.0-2.el7 epel
protobuf-vim.x86_64 2.5.0-8.el7 base
python2-neovim.noarch 0.1.13-3.el7 epel
python34-neovim.noarch 0.1.13-3.el7 epel
vim-X11.x86_64 2:7.4.160-2.el7 base
vim-fugitive.noarch 2.2-8.el7 epel
vim-go.x86_64 1.8-3.el7 epel
vim-gtk-syntax.noarch 20130716-1.el7 epel
vim-halibut.noarch 1.2-1.el7 epel
vim-jellybeans.noarch 1.6-1.el7 epel
vim-toml.noarch 0-0.1.20180306git624f024.el7 epel
vim-vimoutliner.noarch 0.4.0-8.el7 epel
xtuple-csvimp.x86_64 0.5.4-8.el7 epel
xtuple-csvimp-devel.x86_64 0.5.4-8.el7 epel
install rpm package
Order:yum install [-y] [rpm包名]
If you do not add the "-y" option, it will be installed interactively with the user. First, the rpm package information that needs to be installed will be listed, and then the user will be asked if they need to be installed. Enter y to install it, and enter n to not install it. With the "-y" option, the step of asking the user to install is omitted.
List packages (packages) installed in groups on the system
[root@centos-01 Packages]# yum grouplist
[root@centos-01 Packages]# LANG=en
[root@centos-01 Packages]# yum grouplist
In the group listed, select Install Virtualization Host
[root@centos-01 Packages]# yum groupinstall "Virtualization Host"
uninstall rpm package
Order:yum remove [-y] [rpm包名]
When uninstalling a certain rpm package, you must see it clearly, and do not uninstall it together with other important rpm packages, so as not to affect the normal business.
upgrade rpm package
Order:yum update [-y] [rpm包]
List which files are provided by a package
[root@centos-01 Packages]# yum provides "/*/vim"
Failed to set locale, defaulting to C
After the front is set to en English, the following error occurs
Failed to set locale, defaulting to C
Then set it back to Chinese
[root@centos-01 Packages]# LANG=zh_CN.UTF-8
yum builds local warehouse
When introducing the RPM tool earlier, the CD-ROM drive has been mounted to the /mnt directory. If the current virtual machine is not mounted, please refer to the beginning of the RPM tool.
[root@centos-01 Packages]# ls /mnt/
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
[root@centos-01 Packages]# cd
[root@centos-01 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
[root@centos-01 ~]# cd /etc/yum.repos.d
[root@centos-01 yum.repos.d]# ls
CentOS.repo epel.repo
[root@centos-01 yum.repos.d]# rm -rf ./*
[root@centos-01 yum.repos.d]# vi dvd.repo
Add to
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0
save and exit
[root@centos-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@centos-01 yum.repos.d]# yum list
Change yum repository source
[root@centos-01 yum.repos.d]# ls
dvd.repo
[root@centos-01 yum.repos.d]# rm -f dvd.repo
Use wget
or curl
command to download CentOS7-Base-163.repo
[root@centos-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@centos-01 yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1572 100 1572 0 0 8395 0 --:--:-- --:--:-- --:--:-- 8451
[root@centos-01 yum.repos.d]# ls
CentOS7-Base-163.repo
[root@centos-01 yum.repos.d]# yum list
[root@centos-01 yum.repos.d]# yum clean all
[root@centos-01 yum.repos.d]# yum repolist all
Install the extension source epel
[root@centos-01 yum.repos.d]# yum install -y epel-release
[root@centos-01 yum.repos.d]# ls
CentOS7-Base-163.repo epel.repo epel-testing.repo
[root@centos-01 yum.repos.d]# yum list
[root@centos-01 yum.repos.d]# yum list |grep epel
[root@centos-01 yum.repos.d]# yum repolist all
yum download rpm package
yum install 包名 --downloadonly
[root@centos-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/
base epel epel-testing extras updates
centosplus epel-debuginfo epel-testing-debuginfo timedhosts
dvd epel-source epel-testing-source timedhosts.txt
/var/cache/yum/x86_64/7/
Under the directory, there are folders corresponding to different sources. The rpm package downloaded by yum will be stored in the corresponding source /packages
directory according to the download source, such as: /var/cache/yum/x86_64/7/updates/packages/
, /var/cache/yum/x86_64/7/base/packages/
.
Specify the download rpm path
yum install 包名 --downloadonly --downloaddir=路径
Download the installed rpm package
yum reinstall 包名 --downloadonly --downloaddir=路径
[root@centos-01 yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirror01.idc.hinet.net
软件包 2:vim-enhanced-7.4.160-2.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@centos-01 yum.repos.d]# ls /tmp/
1.txt systemd-private-2186b3ce9fed4170938e51d9b57ddad3-chronyd.service-i763QZ
2.txt.gz systemd-private-2186b3ce9fed4170938e51d9b57ddad3-vgauthd.service-Q0qSiA
3.txt.bz2 systemd-private-2186b3ce9fed4170938e51d9b57ddad3-vmtoolsd.service-saunXb
4.txt.xz yum_save_tx.2018-05-05.19-44.not9LG.yumtx
mytest
[root@centos-01 yum.repos.d]# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 vim-enhanced.x86_64.2.7.4.160-2.el7 将被 已重新安装
--> 解决依赖关系完成
依赖关系解决
======================================================================================================
Package 架构 版本 源 大小
======================================================================================================
重新安装:
vim-enhanced x86_64 2:7.4.160-2.el7 base 1.0 M
事务概要
======================================================================================================
重新安装 1 软件包
总下载量:1.0 M
安装大小:2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-2.el7.x86_64.rpm | 1.0 MB 00:00:00
exiting because "Download Only" specified
[root@centos-01 yum.repos.d]# ls /tmp/
1.txt
2.txt.gz
3.txt.bz2
4.txt.xz
mytest
systemd-private-2186b3ce9fed4170938e51d9b57ddad3-chronyd.service-i763QZ
systemd-private-2186b3ce9fed4170938e51d9b57ddad3-vgauthd.service-Q0qSiA
systemd-private-2186b3ce9fed4170938e51d9b57ddad3-vmtoolsd.service-saunXb
vim-enhanced-7.4.160-2.el7.x86_64.rpm
yum_save_tx.2018-05-05.19-44.not9LG.yumtx
yum_save_tx.2018-05-05.21-20.Iue83X.yumtx
Source package installation
[root@centos-01 yum.repos.d]# cd
[root@centos-01 ~]# cd /usr/local/src/
[root@centos-01 src]# ls
[root@centos-01 src]# wget http://archive.apache.org/dist/httpd/httpd-2.2.9.tar.gz
[root@centos-01 src]# ls
httpd-2.2.9.tar.gz
[root@centos-01 src]# tar -zxvf httpd-2.2.9.tar.gz
[root@centos-01 src]# ls
httpd-2.2.9 httpd-2.2.9.tar.gz
[root@centos-01 src]# cd httpd-2.2.9
[root@centos-01 httpd-2.2.9]# ls
ABOUT_APACHE BuildBin.dsp docs InstallBin.dsp modules ROADMAP
acinclude.m4 buildconf emacs-style LAYOUT NOTICE server
Apache.dsw CHANGES httpd.dsp libhttpd.dsp NWGNUmakefile srclib
apachenw.mcp.zip config.layout httpd.spec LICENSE os support
build configure include Makefile.in README test
BuildAll.dsp configure.in INSTALL Makefile.win README.platforms VERSIONING
[root@centos-01 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring Apache Portable Runtime library ...
checking for APR... reconfig
configuring package in srclib/apr now
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.3.0
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr [root@centos-01 httpd-2.2.9]# echo $?
1
echo $?
A non-zero value is displayed, indicating that the previous command is wrong and gcc needs to be installed.
The compiler in the Linux system is used to compile the source code package. Common source code packages are generally developed in the C language, which is also because the C language is the most standard programming language on Linux. The C compiler on Linux is called gcc.
[root@centos-01 httpd-2.2.9]# yum install gcc
Installing a source package usually requires three steps:
./configure
In this step, you can customize the function and add the corresponding options. The specific options can be viewed through the./configure --help
command. In this step, it will automatically detect whether the Linux system and related packages have the libraries required for compiling the source package, because once a library is missing, the compilation cannot be completed.Makefile
A file is generated only after the test passes .make
Using this command willMakefile
compile according to the parameters preset in the file. In this step, gcc is actually working.make install
Installation steps, the process of generating relevant software storage directories and configuration files.
The above three steps, not all source package software are the same. After getting the source code package and decompressing it, go to the directory to find the relevant help documentation. Usually starts with INSTALL
or README
as the filename.
[root@centos-01 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2
[root@centos-01 httpd-2.2.9]# echo $?
0
[root@centos-01 httpd-2.2.9]# make
[root@centos-01 httpd-2.2.9]# echo $?
0
[root@centos-01 httpd-2.2.9]# make install
[root@centos-01 httpd-2.2.9]# echo $?
0
[root@centos-01 httpd-2.2.9]# ls /usr/local/apache2/
bin build cgi-bin conf error htdocs icons include lib logs man manual modules
To uninstall the source package, just delete the installed folder. After the source package is installed, if there is no startup or other operations, you can delete the specified folder at this time.