19. 软件包安装和卸载

7.1 安装软件包的三种方法
rpm工具 Redhat package manager
yum工具 自动解决依赖问题,Redhat中收费
源码包

7.2 rpm包介绍
# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
# cd /mnt/Packages/
# ls | wc
3895

abrt-2.1.11- 48.el7.centos.x86_64.rpm
包名-版本号-发布版本号.平台.rpm

7.3 rpm工具用法
rpm is a powerful Package Manager, which can be used to build, install, query, verify, update, and erase individual software packages.

rpm -ivh rpm包文件 //安装
# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-28.el7 ################################# [100%]

--force
Same as using --replacepkgs, --replacefiles, and --oldpackage.
--replacefiles
Install the packages even if they replace files from other,
already installed, packages.
--replacepkgs
Install the packages even if some of them are already installed on this system.
--oldpackage
Allow an upgrade to replace a newer package with an older one.

--nodeps
Don't do a dependency check before installing or upgrading a package.

--prefix NEWPATH
For relocatable binary packages, translate all file paths that start with the installation prefix in the package relocation hint(s) to NEWPATH.

rpm -Uvh rpm包文件 //升级
# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm

rpm -e 包名 //卸载
# rpm -e zsh
# echo $?
0

# rpm -evh zsh
准备中... ################################# [100%]
正在清理/删除...
1:zsh-5.0.2-28.el7 ################################# [100%]

rpm -q 包名 //查询指定包是否安装
# rpm -q ppp
未安装软件包 ppp
# echo $?
1

# rpm -q vim-enhanced
vim-enhanced-7.4.160-2.el7.x86_64
# echo $?
0

rpm -qa //查询安装的包
rpm -qi 包名 //查询指定包信息
rpm -ql 包名 //列出包安装的文件
rpm -qf 文件绝对路径 //查看一个文件是由哪个包安装的

-a, --all
Query all installed packages.
# rpm -qa
open-vm-tools-10.1.5-3.el7.x86_64
grub2-common-2.02-0.64.el7.centos.noarch
kexec-tools-2.0.14-17.el7.x86_64
setup-2.8.71-7.el7.noarch
NetworkManager-tui-1.8.0-9.el7.x86_64
……

-f, --file FILE
Query package owning FILE.
# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-2.el7.x86_64

# rpm -qf `which vim`
vim-enhanced-7.4.160-2.el7.x86_64

-i, --info
Display package information, including name, version, and description.
This uses the --queryformat if one was specified.
# rpm -qi vim-enhanced
Name : vim-enhanced
Epoch : 2
Version : 7.4.160
Release : 2.el7
Architecture: x86_64
Install Date: 2017年12月21日 星期四 00时19分00秒
……

-l, --list
List files in package.
# 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

-L, --licensefiles
List only license files (implies -l).
# rpm -qL vim-enhanced
7.4 yum工具用法
yum - Yellowdog Updater Modified

SYNOPSIS
yum [options] [command] [package ...]

command is one of:
* install package1 [package2] [...]
* update [package1] [package2] [...]
* update-to [package1] [package2] [...]
* check-update
* upgrade [package1] [package2] [...]
* upgrade-to [package1] [package2] [...]
* remove | erase package1 [package2] [...]
* autoremove [package1] [...]
* list [...]
* info [...]
* provides | whatprovides feature1 [feature2] [...]
* clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
clean Is used to clean up various things
which accumulate in the yum cache directory over time.
* makecache [fast]
makecache Is used to download and
make usable all the metadata for the currently enabled yum repos.
If the argument "fast" is passed,
then we just try to make sure the repos. are current
(much like "yum clean expire-cache").
* groups [...]
* search string1 [string2] [...]
* resolvedep dep1 [dep2] [...]
(maintained for legacy reasons only - use repoquery or yum provides)
* reinstall package1 [package2] [...]
* downgrade package1 [package2] [...]
* load-transaction [txfile]
* check
* help [command]

yum list //列出可用rpm包
# vim /etc/yum.repos.d/CentOS-Base.repo

yum search vim //搜索包
This is used to find packages when you know something about the package
but aren't sure of it's name.

# yum search vim

# 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
protobuf-vim.x86_64 2.5.0-8.el7 base
vim-X11.x86_64 2:7.4.160-2.el7 base

yum install [-y]

yum grouplist
# yum grouplist > 1
# yum groups list > 2
# diff 1 2
#

yum groupinstall [-y]
# yum groupinstall 'GNOME Desktop'

yum remove [-y]
yum update [-y]
If run without any packages, update will update every currently installed package.

yum provides "/*/vim"
Is used to find out which package provides some feature or file.
# yum provides "/*/bin/vim"
# yum provides vim > 3
# yum whatprovides vim > 4
# diff 3 4
#
# ls [1-4]
1 2 3 4
# rm -f [1-4]

7.5 yum搭建本地仓库
# mount /dev/cdrom /mnt/

# cp -a /etc/yum.repos.d /etc/yum.repos.d.bak

# cd /etc/yum.repos.d
# rm -f *

# vim dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0
:x!

# 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

# yum makecache
已加载插件:fastestmirror
dvd | 3.6 kB 00:00:00
(1/2): dvd/other_db | 1.2 MB 00:00:00
(2/2): dvd/filelists_db | 3.1 MB 00:00:00
Loading mirror speeds from cached hostfile
元数据缓存已建立

# yum list | less

7.6 yum更换国内源
# rm -f dvd.repo
# cp -a ../yum.repos.d.bak/* .
# rm -f CentOS-Base.repo
# 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 7531 0 --:--:-- --:--:-- --:--:-- 7557
# yum repolist all

# mv CentOS7-Base-163.repo CentOS7-Base-163.repo.bak
# yum clean all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
To enable Red Hat Subscription Management repositories:
subscription-manager repos --enable <repo>
To enable custom repositories:
yum-config-manager --enable <repo>

# mv CentOS7-Base-163.repo.bak CentOS7-Base-163.repo
# yum repolist all

7.7 安装扩展源epel
# yum install -y epel-release
# ll epel*
-rw-r--r--. 1 root root 957 12月 28 2016 epel.repo
-rw-r--r--. 1 root root 1056 12月 28 2016 epel-testing.repo

# yum list | grep epel

7.8 yum下载rpm包
# yum install zsh --downloadonly
……
exiting because "Download Only" specified

# ls /var/cache/yum/x86_64/7/base/packages/
zsh-5.0.2-28.el7.x86_64.rpm

# yum install zsh --downloadonly --downloaddir=/tmp/
# ls /tmp/zsh-5.0.2-28.el7.x86_64.rpm
/tmp/zsh-5.0.2-28.el7.x86_64.rpm

# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.ustc.edu.cn
软件包 2:vim-enhanced-7.4.160-2.el7.x86_64 已安装并且是最新版本
无须任何处理

# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
# ls /tmp/vim-enhanced-7.4.160-2.el7.x86_64.rpm
/tmp/vim-enhanced-7.4.160-2.el7.x86_64.rpm

7.9 源码包安装
#cd /usr/local/src/
# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
# ls
httpd-2.2.34.tar.gz

# tar -zxf httpd-2.2.34.tar.gz
# ls
httpd-2.2.34 httpd-2.2.34.tar.gz

# cd httpd-2.2.34/
# less README
# less INSTAL
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.2/install.html

$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start

# ./configure -help
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2]
# ./configure --prefix=/usr/local/apache2;echo $?
……
1

# yum -y install gcc
# ./configure --prefix=/usr/local/apache2;echo $?
0

# make

# make install

# ls /usr/local/apache2/
bin build cgi-bin conf error htdocs icons include lib logs man manual modules

# /usr/local/apache2/bin/apachectl start


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值