安装软件包的三种方法
rpm工具
- 类似windows的exe安装包,安装简单,安装位置等都是设定好的。
yum工具
-
用python开发的工具,安装的也是rpm包
-
优点是可以自动安装一个包所依赖的一些包。rpm包在安装时候可能会需要依赖另一个包的支持,而安装另一个包,可能还需要另一个的依赖。这时候用yum就可以自动安装上所有的依赖包。方便,简单,快捷。
源码包
- 源代码包,需要编译后安装。
rpm工具的使用
找到rpm包
要想使用rpm工具,首先需要有rpm包,下面利用contos7的镜像文件里找一下rpm包。
先连接虚拟机里面的光驱,光盘文件选一下contos7的镜像。连接好后开始挂载。
挂载到/mnt/下,mount /dev/cdrom /mnt/
[root@aminglinux-01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@aminglinux-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 3.6G 15G 20% /
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 109M 88M 56% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /mnt
到mnt下看一下里面的内容。也就是光盘里的文件。rpm包是以红色名字显示的。
[root@aminglinux-01 ~]# cd /mnt/
[root@aminglinux-01 mnt]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
其中 Packages这个目录下装的就是rpm包文件。
rpm包介绍
- rpm包名组成
xz-devel-5.2.2-1.el7.x86_64.rpm
包名-版本号-发布版本号.64位或32位数系统要求
-
以这个rpm包为例子,xz-devel就是包名,5.2.2这个是版本号。1.el7是发布版本号。x86_64,运行平台,区分32位,或者64位。也有不需要区分的,都可以用。
-
contos7已经开始不区分32或者64位的,都是64位系统。一般64位系统可以安装32位的软件。反过来不可以。
rpm包的安装
-
用法:
-
安装:rpm -ivh rpm包文件
-
升级:rpm -Uvh rpm包文件
-
卸载 :rpm -e 包名
-
查询安装的包: rpm -qa
-
查询指定包是否安装 : rpm -q
-
查询指定包信息 : rpm -qi
-
列出包安装的文件 : rpm -ql
-
查看一个文件是由哪个包安装的 rpm -qf 文件绝对路径
-
rpm安装rpm -ivh rpm包文件 (这个是在当前有rpm包的目录,也可用绝对路径)
[root@aminglinux-01 Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7 ################################# [100%]
[root@aminglinux-01 Packages]#
- 卸载 :rpm -e 包名(什么都不提示是正常的)
[root@aminglinux-01 Packages]# rpm -e zsh
[root@aminglinux-01 Packages]#
- 查询安装的包: rpm -qa
python-perf-3.10.0-514.el7.x86_64
perl-XML-Dumper-0.81-17.el7.noarch
logrotate-3.8.6-12.el7.x86_64
net-snmp-agent-libs-5.7.2-28.el7.x86_64
nss-3.21.0-17.el7.x86_64
----中间省略,特别多----
dhclient-4.2.5-47.el7.centos.x86_64
crontabs-1.11-6.20121102git.el7.noarch
libdrm-2.4.67-3.el7.x86_64
- 查询指定包是否安装 : rpm -q (如果安装了,就会有显示,没安装会提示未安装)
[root@aminglinux-01 Packages]# rpm -q ppp
ppp-2.4.5-33.el7.x86_64
[root@aminglinux-01 Packages]# rpm -q pppp
未安装软件包 pppp
- 查询指定包信息 : rpm -qi (我们查一下vim-enhanced)
[root@aminglinux-01 Packages]# rpm -qi vim-enhanced
Name : vim-enhanced
Epoch : 2
Version : 7.4.160
Release : 1.el7_3.1
Architecture: x86_64
Install Date: 2017年08月23日 星期三 20时09分35秒
Group : Applications/Editors
Size : 2292098
License : Vim
Signature : RSA/SHA256, 2016年12月22日 星期四 01时14分11秒, Key ID 24c6a8a7f4a80eb5
Source RPM : vim-7.4.160-1.el7_3.1.src.rpm
Build Date : 2016年12月22日 星期四 01时00分52秒
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.
[root@aminglinux-01 Packages]#
yum工具用法
yum安装方法 yum install 包名
如下,上面讲到用rpm安装和卸载会出现依赖问题非常麻烦。如果用yum安装和卸载就会自动安装或卸载所需要的依赖。
[root@aminglinux-01 Packages]# rpm -ivh texlive-tools-svn26263.0-38.el7.noarch.rpm
错误:依赖检测失败:
texlive-base 被 texlive-tools-2:svn26263.0-38.el7.noarch 需要
texlive-kpathsea-bin 被 texlive-tools-2:svn26263.0-38.el7.noarch 需要
tex-kpathsea 被 texlive-tools-2:svn26263.0-38.el7.noarch 需要
tex(color.sty) 被 texlive-tools-2:svn26263.0-38.el7.noarch 需要
- yum安装一个包只需要直接跟包名字就可以了。
yum install 包名 ,在用texlive这个包试一下。
事务概要
==========================================================================================================================================================
安装 1 软件包 (+223 依赖软件包)
总下载量:118 M
安装大小:226 M
Is this ok [y/d/N]:
可以看到自动检测到需要223个依赖包。按y就会下载安装,按n就是不安装。如果这么多依赖用rpm一个一个安装的话会累死,这也是yum的优点。
列出可用rpm包 :yum list
yum-plugin-tmprepo.noarch 1.1.31-45.el7 base
yum-plugin-tsflags.noarch 1.1.31-45.el7 base
yum-plugin-upgrade-helper.noarch 1.1.31-45.el7 base
yum-plugin-verify.noarch 1.1.31-45.el7 base
yum-plugin-versionlock.noarch 1.1.31-45.el7 base
yum-rhn-plugin.noarch 2.0.1-10.el7 base
yum-updateonboot.noarch 1.1.31-45.el7 base
yum-utils.noarch 1.1.31-45.el7 base
zenity.x86_64 3.22.0-1.el7 base
列出的非常多, 左侧是包名字和运行平台, 中间是版本号,和平台号。 最右侧是仓库名字。@开头的是已经安装过的包。
/etc/yum.repos.d/这里面是yum仓库的配置文件。
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
yum模糊搜索包 :yum search 要搜索的包名字
用搜索vim举例。 yum search vim
[root@localhost ~]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.zju.edu.cn
==================================================================== N/S matched: vim ====================================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
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-minimal.x86_64 : A minimal version of the VIM editor
名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]#
yum 精确过滤出想要的包名:yum list |grep '包名'
用vim搜索举例 。 yum list |grep 'vim' 。不光能精确过滤,还有颜色显示。
yum grouplist 列出安装包组
[root@localhost ~]# yum grouplist
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.zju.edu.cn
可用的环境分组:
最小安装
基础设施服务器
计算节点
文件及打印服务器
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
传统 UNIX 兼容性
兼容性程序库
图形管理工具
安全性工具
开发工具
控制台互联网工具
智能卡支持
科学记数法支持
系统管理
系统管理工具
完成
中文显示可能无法使用。需要用 LANG=en 转换英文看一下
[root@localhost ~]# LANG=en
[root@localhost ~]# yum grouplist
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.zju.edu.cn
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
yum groupinstall 安装组包
- 用法 :yum groupinstall 包名 。 如果包名字有空格,用单引号引起来。如:yum groupinstall 'Development and Creative Workstation'
yum 卸载软件包 :yum remove 包名
卸载软件包也是会把所有的依赖卸载。所以卸载时候尽量不要加-y, 以免出现意外。
yum 升级软件包 :yum update 包名
如果yum update 不加包名会自动升级系统中能升级的所有包。包括系统本身。
yum provides "/*/vim" 根据命令搜索包名字
[root@localhost ~]# yum provides "/*/vim"
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.zju.edu.cn
base/7/x86_64/filelists_db | 6.9 MB 00:00:06
extras/7/x86_64/filelists_db | 519 kB 00:00:00
updates/7/x86_64/filelists_db | 1.3 MB 00:00:00
cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
Repo : base
Matched from:
Filename : /usr/share/cmake/editors/vim
2:docker-unit-test-1.13.1-53.git774336d.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo : extras
Matched from:
Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim
2:docker-unit-test-1.13.1-58.git87f2fab.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo : extras
Matched from:
Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim
2:docker-unit-test-1.13.1-63.git94f4240.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo : extras
Matched from:
Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim
git-1.8.3.1-13.el7.x86_64 : Fast Version Control System
Repo : base
Matched from:
Filename : /usr/share/doc/git-1.8.3.1/contrib/vim
2:vim-common-7.4.160-4.el7.x86_64 : The common files needed by any version of the VIM editor
Repo : base
Matched from:
Filename : /usr/share/vim
2:vim-enhanced-7.4.160-4.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : base
Matched from:
Filename : /usr/bin/vim
2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : @base
Matched from:
Filename : /usr/bin/vim
可以根据命令路径来判断包名字。比如在/bin下或者/sbin下。
yum 搭建本地仓库
有些特殊情况下,服务器没有联网,但是想要yum安装一些软件。这时候就需要搭建一个本地的yum仓库来使用。
思路是先准备一个有yum包的储存盘,比如光盘。然后把之前的yum仓库文件备份下删除,然后添加新的仓库配置文件。
- 先备份,然后删除
[root@localhost ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
[root@localhost ~]# rm -f /etc/yum.repos.d/*
- 在/etc/yum.repos.d/下创建dvd.repo ,内容如下:
[dvd]
name=install dvd
baseurl=file:///mnt 定义rpm包放在那里
enable=1 是否可用,1就是可用
gpgcheck=0 是否检测,0不检测。
- 之后要清缓存。yum clean all
[root@localhost ~]# yum clean all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: dvd
Cleaning up everything
Cleaning up list of fastest mirrors
- 然后yum list 查看下(可以看到仓库都变成了dvd)
xsettings-kde.x86_64 0.12.3-7.el7 dvd
xsom.noarch 0-10.20110809svn.el7 dvd
xterm.x86_64 295-3.el7 dvd
xulrunner.x86_64 31.6.0-2.el7.centos dvd
xvattr.x86_64 1.3-27.el7 dvd
xz-devel.x86_64 5.2.2-1.el7 dvd
yajl.x86_64 2.0.4-4.el7 dvd
yelp.x86_64 1:3.14.2-1.el7 dvd
yelp-libs.x86_64 1:3.14.2-1.el7 dvd
yelp-xsl.noarch 3.14.0-1.el7 dvd
yum 更换国内源
contos7默认yum源指向的是国外的网站,有的时候yum装程序特别的慢。这时候就需要把yum源改成国内的,下载速度就会提升。
-
首先删除rm -f CentOS-Base.repo 这个源
-
下载163源 CentOS7-Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
或者
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
-
yum clean all 清缓存
-
yum list 测试或者安装个wge试一下,就是可以用了。
安装扩展源
光安装一个163源不够用,很多rpm都没有。所以安装一个扩展源。
- yum install -y epel-release 安装
安装好后会在 /etc/yum.repos.d下新生成一个epel.repo
epel.repo
- yum list
zvbi.x86_64 0.2.35-1.el7 epel
zvbi-devel.x86_64 0.2.35-1.el7 epel
zvbi-fonts.noarch 0.2.35-1.el7 epel
zziplib.i686 0.13.62-5.el7 base
zziplib.x86_64 0.13.62-5.el7 base
zziplib-devel.i686 0.13.62-5.el7 base
yum下载rpm包
之前说过搭建本地yum仓库但是是用光驱里面的rpm包做的实验,而不是真正所需要的本地仓库。下面说一下如何用yum下载所需要的rpm包。
用法: yum install 包名 --downloadonly
这种用法限于该包还没有安装。已经安装过的会提醒。
下载到/var/cache/yum/x86_64/7/仓库名/packages下面。
用这个命令可以在已经安装该包的情况下下载rpm包:yum reinstall 包名 --downloadonly
指定下载路径 yum install 包名 --downloadonly --downloaddir=路径
- 比如用zsh这个包做实验
[root@localhost ~]# yum install zsh --downloadonly --downloaddir=/tmp/
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.tongji.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
zsh x86_64 5.0.2-28.el7 base 2.4 M
Transaction Summary
==========================================================================================================================================================
Install 1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:00:02
exiting because "Download Only" specified
[root@localhost ~]# ls /tmp/
1.txt systemd-private-a44b0f41787b47de9f672a72cec9768d-vmtoolsd.service-FOn2fg yum_save_tx.2018-05-30.11-10.T6z0Ih.yumtx
passwd.sh yum_save_tx.2018-05-30.09-10.cW8ODj.yumtx zsh-5.0.2-28.el7.x86_64.rpm
[root@localhost ~]#
源码包安装
约定:以后下载的安装包都放在 /usr/local/src/下
- 先下载一个httpd的源码包,下载好后是一个压缩包,需要解压。
[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
--2018-05-30 11:20:40-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9076901 (8.7M) [application/octet-stream]
Saving to: 'httpd-2.4.33.tar.gz'
100%[================================================================================================================>] 9,076,901 1.59MB/s in 5.9s
2018-05-30 11:20:46 (1.46 MB/s) - 'httpd-2.4.33.tar.gz' saved [9076901/9076901]
[root@localhost src]# ls
httpd-2.4.33.tar.gz
-
解压好后,进入目录,找到配置文件README 。这里面是一些软件的说明介绍。
-
还有一个文件是INSTALL 里面是安装文档。教程。开头介绍了安装步骤。
[root@localhost httpd-2.4.33]# cat INSTALL
APACHE INSTALLATION OVERVIEW
Quick Start - Unix
------------------
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
-
./configure --help是可以查看安装都有哪些功能可选安装的。
-
./configure --prefix=/usr/local/apache2 指定安装目录
[root@localhost httpd-2.4.33]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
直接报错了。 输入 echo $?查看如果是0就是上面命令执行没有问题,如果是1或则别的数说明上面命令报错了。
-
根据报错安装yum install apr apr-util apr-devel
-
然后安装yum install gcc
-
然后 make
-
然后 make install
-
卸载源码包的安装就是删除安装文件。
扩展学习
-
yum保留已经安装过的包 http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml
-
搭建局域网yum源 http://ask.apelearn.com/question/7627
-
把源码包打包成rpm包 https://jin-yang.github.io/post/linux-create-rpm-package.html
-
搭建局域网yum源 http://blog.lishiming.net/?p=500