linux安装和卸载软件
安装三种方法
rpm工具
yum工具
源码包
rpm工具使用
首先看一下什么事rpm包,可以挂载光驱看看里面有很多
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 1.3G 17G 8% /
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/sr0 4.1G 4.1G 0 100% /mnt
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
[root@localhost mnt]#
其中有一个目录是Packages,里面都是rpm包
[root@localhost Packages]# ls
xulrunner-31.6.0-2.el7.centos.x86_64.rpm
xvattr-1.3-27.el7.x86_64.rpm
xz-5.2.2-1.el7.x86_64.rpm
xz-devel-5.2.2-1.el7.x86_64.rpm
xz-libs-5.2.2-1.el7.x86_64.rpm
yajl-2.0.4-4.el7.x86_64.rpm
yelp-3.14.2-1.el7.x86_64.rpm
yelp-libs-3.14.2-1.el7.x86_64.rpm
yelp-xsl-3.14.0-1.el7.noarch.rpm
ypbind-1.37.1-7.el7.x86_64.rpm
ypserv-2.31-8.el7.x86_64.rpm
yp-tools-2.14-3.el7.x86_64.rpm
yum-3.4.3-150.el7.centos.noarch.rpm
yum-langpacks-0.4.2-7.el7.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-aliases-1.1.31-40.el7.noarch.rpm
yum-plugin-changelog-1.1.31-40.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
yum-plugin-tmprepo-1.1.31-40.el7.noarch.rpm
yum-plugin-verify-1.1.31-40.el7.noarch.rpm
yum-plugin-versionlock-1.1.31-40.el7.noarch.rpm
yum-utils-1.1.31-40.el7.noarch.rpm
zenity-3.8.0-5.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-25.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm
rpm包的格式
包名、版本号、发布版本号、平台
rpm包安装 rpm -ivh rpm包文件
-i 表示安装
-v 表示可视化
-h 表示显示安装进度
[root@localhost Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7 ################################# [100%]
[root@localhost Packages]#
rpm包升级 rpm -Uvh rpm包文件
-U : 表示升级
[root@localhost Packages]# rpm -Uvh zsh-5.0.2-25.el7.x86_64.rpm
准备中... ################################# [100%]
软件包 zsh-5.0.2-25.el7.x86_64 已经安装
rpm包卸载 rpm -e rpm包文件
[root@localhost Packages]# rpm -e zsh
[root@localhost Packages]#
什么都没有显示说明卸载成功了
查询rpm包 rpm -qa
列出的包都是已经安装的包
查询指定包是否安装 rpm -q 包名
[root@localhost Packages]# rpm -q ppp
ppp-2.4.5-33.el7.x86_64
[root@localhost Packages]# rpm -q ppp1244324
未安装软件包 ppp1244324
[root@localhost Packages]#
查询指定包信息 rpm -qi
[root@localhost 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
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@localhost Packages]#
列出包安装的文件 rpm -ql
[root@localhost 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
[root@localhost Packages]#
查看一个文件是由哪个包安装的 rpm -qf 文件绝对路径
[root@localhost Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-1.el7_3.1.x86_64
[root@localhost Packages]#
反引号查找,如果不知道文件的具体路径可以这样用
[root@localhost Packages]# rpm -qf `which cd`
bash-4.2.46-20.el7_2.x86_64
[root@localhost Packages]#
yum工具用法
在rpm工具使用时候会出现一些很复杂的依赖关系。用起来非常麻烦,这时候可以用yum工具来解决
比如用yum 安装一个texlinve和rpm安装的区别
[root@localhost Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
错误:依赖检测失败:
texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
[root@localhost Packages]# yum install texlive
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Determining fastest mirrors
* base: mirrors.zju.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 texlive.x86_64.2.2012-38.20130427_r30134.el7 将被 安装
--> 正在处理依赖关系 texlive-scheme-basic,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
--> 正在处理依赖关系 texlive-collection-latexrecommended,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
--> 正在处理依赖关系 tex-tetex,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
--> 正在处理依赖关系 tex-kpathsea,它被软件包 2:texlive-2012-38.20130427_r30134.el7.x86_64 需要
--> 正在检查事务
---> 软件包 texlive-collection-latexrecommended.noarch.2.svn25795.0-38.20130427_r30134.el7 将被 安装
···
====================================================================================================================================================
安装 1 软件包 (+223 依赖软件包)
列出可用的rpm包 yum list
查找一个rpm包 yum search 查找内容
[root@localhost Packages]# yum search network
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
=============================================================== N/S matched: network ===============================================================
NetworkManager.x86_64 : Network connection manager and user applications
NetworkManager-adsl.x86_64 : ADSL device plugin for NetworkManager
NetworkManager-bluetooth.x86_64 : Bluetooth device plugin for NetworkManager
NetworkManager-config-server.x86_64 : NetworkManager config file for "server-like" defaults
NetworkManager-dispatcher-routing-rules.noarch : NetworkManager dispatcher file for advanced routing rules
NetworkManager-glib.i686 : Libraries for adding NetworkManager support to applications (old API).
NetworkManager-glib.x86_64 : Libraries for adding NetworkManager support to applications (old API).
NetworkManager-glib-devel.i686 : Header files for adding NetworkManager support to applications (old API).
NetworkManager-glib-devel.x86_64 : Header files for adding NetworkManager support to applications (old API).
NetworkManager-libnm.i686 : Libraries for adding NetworkManager support to applications (new API).
NetworkManager-libnm.x86_64 : Libraries for adding NetworkManager support to applications (new API).
NetworkManager-libnm-devel.i686 : Header files for adding NetworkManager support to applications (new API).
NetworkManager-libnm-devel.x86_64 : Header files for adding NetworkManager support to applications (new API).
NetworkManager-libreswan.x86_64 : NetworkManager ××× plug-in for IPsec ×××
NetworkManager-libreswan-gnome.x86_64 : NetworkManager ××× plugin for libreswan - GNOME files
NetworkManager-team.x86_64 : Team device plugin for NetworkManager
NetworkManager-tui.x86_64 : NetworkManager curses-based UI
这样查找并不严谨,搜索出来的内容太多,还可以使用grep来进行过滤
yum list |grep 'vim'
[root@localhost Packages]# yum list |grep 'vim'
vim-common.x86_64 2:7.4.160-1.el7_3.1 @updates
vim-enhanced.x86_64 2:7.4.160-1.el7_3.1 @updates
vim-filesystem.x86_64 2:7.4.160-1.el7_3.1 @updates
vim-minimal.x86_64 2:7.4.160-1.el7 @anaconda
golang-vim.noarch 1.3.3-2.el7_0 extras
protobuf-vim.x86_64 2.5.0-8.el7 base
vim-X11.x86_64 2:7.4.160-1.el7_3.1 updates
vim-minimal.x86_64 2:7.4.160-1.el7_3.1 updates
[root@localhost Packages]#
列出可用的环境分组 yum grouplist
[root@localhost Packages]# yum gouplist
已加载插件:fastestmirror
没有该命令:gouplist。请使用 /usr/bin/yum --help
[root@localhost Packages]# yum grouplist
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
可用的环境分组:
最小安装
基础设施服务器
计算节点
文件及打印服务器
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
传统 UNIX 兼容性
兼容性程序库
图形管理工具
安全性工具
开发工具
控制台互联网工具
智能卡支持
科学记数法支持
系统管理
系统管理工具
完成
[root@localhost Packages]#
安装rpm包 yum install -y rpm包名
安装rpm组包 yum groupinstall rpm组包名 如果组包名是一个单词就直接输入,如果是很长的的名字中间有空格,就需要用''单引号括起来
卸载rpm包 yum remove 可以加-y 。用yum 卸载的优势是可以直接卸载所有的依赖关系。这样也是比较危险的。
升级rpm包 yum update 包名 。 如果不加上包名,yum会把系统所有的rpm包进行升级,包括系统,内核升级。
yum provides "/*/vim" 意思是当不知道vim的rpm包名字时候,用这条命令来进行查找
[root@localhost Packages]# yum provides "/*/vim"
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
base/7/x86_64/filelists_db | 6.6 MB 00:00:01
extras/7/x86_64/filelists_db | 1.1 MB 00:00:00
updates/7/x86_64/filelists_db | 4.4 MB 00:00:00
cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
源 :base
匹配来源:
文件名 :/usr/share/cmake/editors/vim
2:docker-unit-test-1.10.3-59.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
源 :extras
匹配来源:
文件名 :/var/lib/docker-unit-test/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-c5212546ab01b4b7b62caba888d298ab63f53984/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
2:docker-unit-test-1.12.5-14.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
源 :extras
匹配来源:
文件名 :/var/lib/docker-unit-test/containerd-471f03c11413d9ab1523de24d3e79ae3a7b8126e/vendor/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/runc-b8dbc3b8e8d868723aec2fd5082e6547ec66cf58/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
2:docker-unit-test-1.12.6-11.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
源 :extras
匹配来源:
文件名 :/var/lib/docker-unit-test/containerd-471f03c11413d9ab1523de24d3e79ae3a7b8126e/vendor/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/runc-81b254244390bc636b20c87c34a3d9e1a8645069/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
···
yum 搭建本地仓库
首先挂载镜像到 /mnt目录
下面可能要删除一些文件所以先拷贝一下这个目录
[root@localhost ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
[root@localhost ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
然后到yum.repos.d目录下删除所有文件
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# rm -rf ./*
然后编辑一下 dvd.repo文件,添加光盘为仓库
[root@localhost yum.repos.d]# vim dvd.repo
`
`
[dvd]
name=install dvd
baseurl=file:///mut
enable=1
gpcheck=0
`
`
[root@localhost yum.repos.d]#
然后清楚下缓存 yum clean all
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: dvd
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]#