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 479M0 479M 0% /devtmpfs 489M0 489M 0% /dev/shmtmpfs 489M 6.7M 482M 2% /runtmpfs 489M0 489M 0% /sys/fs/cgroup/dev/sr0 4.1G 4.1G0 100% /mnt/dev/sda1 197M 109M 88M 56% /boottmpfs 98M0 98M 0% /run/user/0[root@localhost ~]# cd /mnt/[root@localhost mnt]# lsCentOS_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]# lsxulrunner-31.6.0-2.el7.centos.x86_64.rpmxvattr-1.3-27.el7.x86_64.rpmxz-5.2.2-1.el7.x86_64.rpmxz-devel-5.2.2-1.el7.x86_64.rpmxz-libs-5.2.2-1.el7.x86_64.rpmyajl-2.0.4-4.el7.x86_64.rpmyelp-3.14.2-1.el7.x86_64.rpmyelp-libs-3.14.2-1.el7.x86_64.rpmyelp-xsl-3.14.0-1.el7.noarch.rpmypbind-1.37.1-7.el7.x86_64.rpmypserv-2.31-8.el7.x86_64.rpmyp-tools-2.14-3.el7.x86_64.rpmyum-3.4.3-150.el7.centos.noarch.rpmyum-langpacks-0.4.2-7.el7.noarch.rpmyum-metadata-parser-1.1.4-10.el7.x86_64.rpmyum-plugin-aliases-1.1.31-40.el7.noarch.rpmyum-plugin-changelog-1.1.31-40.el7.noarch.rpmyum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpmyum-plugin-tmprepo-1.1.31-40.el7.noarch.rpmyum-plugin-verify-1.1.31-40.el7.noarch.rpmyum-plugin-versionlock-1.1.31-40.el7.noarch.rpmyum-utils-1.1.31-40.el7.noarch.rpmzenity-3.8.0-5.el7.x86_64.rpmzip-3.0-11.el7.x86_64.rpmzlib-1.2.7-17.el7.x86_64.rpmzlib-devel-1.2.7-17.el7.x86_64.rpmzsh-5.0.2-25.el7.x86_64.rpmzziplib-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 pppppp-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-enhancedName : vim-enhancedEpoch : 2Version: 7.4.160Release: 1.el7_3.1Architecture: x86_64Install Date: 08月23日 星期三 20时09分35秒Group : Applications/EditorsSize : 2292098License: VimSignature : RSA/SHA256, 12月22日 星期四 01时14分11秒, Key ID 24c6a8a7f4a80eb5Source RPM : vim-7.4.160-1.el7_3.1.src.rpmBuild Date : 12月22日 星期四 01时00分52秒Build Host : c1bm.Relocations : (not relocatable)Packager : CentOS BuildSystem <>Vendor: CentOSURL : /Summary: A version of the VIM editor which includes recent enhancementsDescription :VIM (VIsual editor iMproved) is an updated and improved version of thevi editor. Vi was the first real screen-based editor for UNIX, and isstill very popular. VIM improves on vi by adding new features:multiple windows, multi-level undo, block highlighting and more. Thevim-enhanced package contains a version of VIM with extra, recentlyintroduced features like Python and Perl interpreters.Install the vim-enhanced package if you'd like to use a version of theVIM editor which includes recently added enhancements likeinterpreters for the Python and Perl scripting languages. You'll alsoneed 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/vimvim-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--38.0427_r30134.el7.x86_64.rpm 错误:依赖检测失败:texlive-scheme-basic 被 texlive-2:-38.0427_r30134.el7.x86_64 需要texlive-collection-latexrecommended 被 texlive-2:-38.0427_r30134.el7.x86_64 需要tex-kpathsea 被 texlive-2:-38.0427_r30134.el7.x86_64 需要tex-tetex 被 texlive-2:-38.0427_r30134.el7.x86_64 需要[root@localhost Packages]# yum install texlive已加载插件:fastestmirrorbase | 3.6 kB 00:00:00extras | 3.4 kB 00:00:00updates | 3.4 kB 00:00:00Determining fastest mirrors* base: mirrors.* extras: mirrors.* updates: mirrors.正在解决依赖关系--> 正在检查事务---> 软件包 texlive.x86_64.2.-38.0427_r30134.el7 将被 安装--> 正在处理依赖关系 texlive-scheme-basic,它被软件包 2:texlive--38.0427_r30134.el7.x86_64 需要--> 正在处理依赖关系 texlive-collection-latexrecommended,它被软件包 2:texlive--38.0427_r30134.el7.x86_64 需要--> 正在处理依赖关系 tex-tetex,它被软件包 2:texlive--38.0427_r30134.el7.x86_64 需要--> 正在处理依赖关系 tex-kpathsea,它被软件包 2:texlive--38.0427_r30134.el7.x86_64 需要--> 正在检查事务---> 软件包 texlive-collection-latexrecommended.noarch.2.svn25795.0-38.0427_r30134.el7 将被 安装···====================================================================================================================================================安装 1 软件包 (+223 依赖软件包)
列出可用的rpm包 yum list
查找一个rpm包 yum search 查找内容
[root@localhost Packages]# yum search network已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.* extras: mirrors.* updates: mirrors.=============================================================== N/S matched: network ===============================================================NetworkManager.x86_64 : Network connection manager and user applicationsNetworkManager-adsl.x86_64 : ADSL device plugin for NetworkManagerNetworkManager-bluetooth.x86_64 : Bluetooth device plugin for NetworkManagerNetworkManager-config-server.x86_64 : NetworkManager config file for "server-like" defaultsNetworkManager-dispatcher-routing-rules.noarch : NetworkManager dispatcher file for advanced routing rulesNetworkManager-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 filesNetworkManager-team.x86_64 : Team device plugin for NetworkManagerNetworkManager-tui.x86_64 : NetworkManager curses-based UI
这样查找并不严谨,搜索出来的内容太多,还可以使用grep来进行过滤
yum list |grep 'vim'
[root@localhost Packages]# yum list |grep 'vim'vim-common.x86_642: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_642:7.4.160-1.el7 @anacondagolang-vim.noarch1.3.3-2.el7_0extras protobuf-vim.x86_64 2.5.0-8.el7 basevim-X11.x86_64 2:7.4.160-1.el7_3.1 updates vim-minimal.x86_642: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.* extras: mirrors.* updates: mirrors.可用的环境分组:最小安装基础设施服务器计算节点文件及打印服务器基本网页服务器虚拟化主机带 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"已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.* extras: mirrors.* updates: mirrors.base/7/x86_64/filelists_db | 6.6 MB 00:00:01extras/7/x86_64/filelists_db | 1.1 MB 00:00:00updates/7/x86_64/filelists_db| 4.4 MB 00:00:00cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system源 :base匹配来源:文件名 :/usr/share/cmake/editors/vim2: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//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-c5212546ab01b4b7b62caba888d298ab63f53984/Godeps/_workspace/src//docker/docker/contrib/syntax/vim2: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//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/runc-b8dbc3b8e8d868723aec2fd5082e6547ec66cf58/Godeps/_workspace/src//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src//docker/docker/contrib/syntax/vim2: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//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//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/runc-81b254244390bc636b20c87c34a3d9e1a8645069/Godeps/_workspace/src//docker/docker/contrib/syntax/vim文件名 :/var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src//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 dvdbaseurl=file:///mutenable=1gpcheck=0``[root@localhost yum.repos.d]#
然后清楚下缓存 yum clean all
[root@localhost yum.repos.d]# yum clean all已加载插件:fastestmirror正在清理软件源: dvdCleaning up everythingCleaning up list of fastest mirrors[root@localhost yum.repos.d]#