Linux软件包安装和卸载
linux系统下安装软件包的三种方法:
1.rpm工具:下载软件rpm包安装,类似Windows的exe文件
2.yum工具:类似应用商店,相比rpm安装优势在于更方便快捷,会自动安装依赖包
3.源码包:下载源码包到linux系统中,需要编译器编译安装
rpm工具用法:
rpm包的格式如下图:(zsh为包名,5.0.2为版本号,-31.el7为发布版本号)
[root@localhost Packages]# zsh-5.0.2-31.el7.x86_64.rpm
安装rpm包命令:rpm -ivh 包名
[root@localhost Packages]# rpm -ivh zsh-5.0.2-31.el7.x86_64.rpm准备中... ################################# [100%]正在升级/安装... 1:zsh-5.0.2-31.el7 ################################# [100%]
升级rpm包命令:rpm -Uvh 包名
[root@localhost Packages]# rpm -Uvh zsh-5.0.2-31.el7.x86_64.rpm
*当系统中有高版本的zsh包的时候,可以使用rpm -Uvh 升级包
卸载rpm包:rpm -e 包名
[root@localhost Packages]# rpm -e zsh #卸载不需要写包的全名
查询系统已安装的rpm包: rpm -qa
[root@localhost Packages]# rpm -qa
查询指定的包是否安装:rpm -q 包名
[root@localhost Packages]# rpm -q zsh #前文安装zsh包后已卸载所以提示未安装未安装软件包 zsh [root@localhost Packages]# rpm -q vim-enhanced #已安装的包会列出包的信息vim-enhanced-7.4.160-6.el7_6.x86_64
查询指定包的详细信息: rpm -qi 包名
[root@localhost Packages]# rpm -qi vim-enhancedName : vim-enhancedEpoch : 2Version : 7.4.160Release : 6.el7_6Architecture: x86_64Install Date: 2019年08月28日 星期三 11时22分18秒Group : Applications/EditorsSize : 2296674License : VimSignature : RSA/SHA256, 2019年07月01日 星期一 21时34分29秒, Key ID 24c6a8a7f4a80eb5Source RPM : vim-7.4.160-6.el7_6.src.rpmBuild Date : 2019年06月28日 星期五 21时59分48秒Build Host : x86-02.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem Vendor : CentOSURL : http://www.vim.org/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.
列出包的安装文件: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
查看文件由什么包安装: rpm -qf 文件绝对路径
[root@localhost Packages]# rpm -qf /usr/bin/vimdiffvim-enhanced-7.4.160-6.el7_6.x86_64
yum工具的用法:
yum list :列出yum仓库中可以安装的rpm包
[root@localhost ~]# yum list
*第三列表示仓库名,带@符号表示已安装
查看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 search 包名:搜索yum仓库中的包
[root@localhost ~]# yum search tomcat已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com=========================================================================== N/S matched: tomcat ===========================================================================tomcat-admin-webapps.noarch : The host-manager and manager web applications for Apache Tomcattomcat-docs-webapp.noarch : The docs web application for Apache Tomcattomcat-javadoc.noarch : Javadoc generated documentation for Apache Tomcattomcat-jsp-2.2-api.noarch : Apache Tomcat JSP API implementation classestomcat-jsvc.noarch : Apache jsvc wrapper for Apache Tomcat as separate servicetomcat-lib.noarch : Libraries needed to run the Tomcat Web containertomcat-servlet-3.0-api.noarch : Apache Tomcat Servlet API implementation classestomcat-webapps.noarch : The ROOT and examples web applications for Apache Tomcattomcatjss.noarch : JSS Connector for Apache Tomcat, a JSSE module for Apache Tomcat that uses JSStomcat.noarch : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 APItomcat-el-2.2-api.noarch : Expression Language v2.2 API
yum list | grep 包名:第二种搜索包的方式,显示信息更简洁
[root@localhost ~]# yum list | grep tomcattomcat.noarch 7.0.76-9.el7_6 updates tomcat-admin-webapps.noarch 7.0.76-9.el7_6 updates tomcat-docs-webapp.noarch 7.0.76-9.el7_6 updates tomcat-el-2.2-api.noarch 7.0.76-9.el7_6 updates tomcat-javadoc.noarch 7.0.76-9.el7_6 updates tomcat-jsp-2.2-api.noarch 7.0.76-9.el7_6 updates tomcat-jsvc.noarch 7.0.76-9.el7_6 updates tomcat-lib.noarch 7.0.76-9.el7_6 updates tomcat-servlet-3.0-api.noarch 7.0.76-9.el7_6 updates tomcat-webapps.noarch 7.0.76-9.el7_6 updates tomcatjss.noarch 7.2.1-8.el7_6 updates
yum -y install 包名:安装包
[root@localhost ~]# yum -y install vim-enhanced
yum grouplist:列出可以安装的环境分组和拓展组
[root@localhost ~]# yum grouplistFailed to set locale, defaulting to CLoaded plugins: fastestmirrorThere 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.aliyun.com * updates: mirrors.aliyun.comAvailable 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 WorkstationAvailable 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 ManagementDone
yum -y groupinstall 分组名:安装分组 (分组名有多个单词的情况下加单引号)
[root@localhost ~]# yum -y groupinstall 'Basic Web Server'
yum -y remove 包名:卸载包
[root@localhost ~]# yum -y remove tomcat
yum -y update 包名:更新包
[root@localhost ~]# yum -y update vim-enhancde
yum provides "/*/命令":查看命令由什么包安装以及安装路径
*当遇到命令名称与包名不一样的情况时,使用yum list | grep 包名可能找不到具体信息,使用yum provides可以根据命令找到包名以及安装路径,比如:pstree命令,pstree命令的包名为psmisc
[root@localhost ~]# yum provides "/*/pstree"已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.compsmisc-22.20-15.el7.x86_64 : Utilities for managing processes on your system源 :base匹配来源:文件名 :/usr/bin/pstree
yum搭建本地仓库:
挂载带有centos镜像的光盘:
[root@localhost ~]# mount /dev/cdrom /mnt/gp/mount: /dev/sr0 写保护,将以只读方式挂载
备份yum配置文件:
[root@localhost ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
清空配置文件:
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
新建本地yum仓库配置文件:
[root@localhost ~]# vim /etc/yum.repos.d/yumck.repo
添加以下内容:
[yumck]name=install yumck #自定义描述字符baseurl=file:///mnt/gp/ #仓库中rpm包的路径enable=1 #是否可用,改为0改仓库即变为不可用gpgcheck=0 #是否检测
清除缓存:
[root@localhost ~]# yum clean all已加载插件:fastestmirror, langpacks正在清理软件源: yumckCleaning up list of fastest mirrorsOther repos take up 197 M of disk space (use --verbose for details)
查看本地yum仓库中可安装的包:
[root@localhost ~]# yum list
安装测试:
[root@localhost ~]# yum -y install zsh已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile正在解决依赖关系--> 正在检查事务---> 软件包 zsh.x86_64.0.5.0.2-31.el7 将被 安装--> 解决依赖关系完成依赖关系解决=========================================================================================================================================================================== Package 架构 版本 源 大小===========================================================================================================================================================================正在安装: zsh x86_64 5.0.2-31.el7 yumck 2.4 M事务概要===========================================================================================================================================================================安装 1 软件包总下载量:2.4 M安装大小:5.6 MDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在安装 : zsh-5.0.2-31.el7.x86_64 1/1 验证中 : zsh-5.0.2-31.el7.x86_64 1/1 已安装: zsh.x86_64 0:5.0.2-31.el7 完毕!
查看已安装的包:
*第三列已显示该包来源于本地yum仓库
[root@localhost ~]# yum list |grep zshzsh.x86_64 5.0.2-31.el7 @yumck
更换国内yum源:
*centos默认yum源是国外的,有时候安装软件速度很慢,可以更换网易yum源解决
备份系统自带的yum配置文件:/etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# lsCentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
wget下载对应版本的repo文件:http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
或使用curl -O:
[root@localhost yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
清除缓存:
[root@localhost yum.repos.d]# yum clean all
查看更换完成的yum仓库rpm包列表:
[root@localhost yum.repos.d]# yum list
安装拓展yum源:
*当更换的国内yum仓库或系统默认yum仓库包不够时,可以添加yum拓展源(由redhat官方提供的yum拓展仓库,包数量更多)
安装拓展源 epel-release:
[root@localhost yum.repos.d]# yum -y install epel-release
查看配置文件:
*安装完成后可以看到目录下增加了epel拓展源(epel.repo、epel-testing.repo)配置文件
[root@localhost yum.repos.d]# lsCentOS7-Base-163.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repoCentOS-Base.repo.bak CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
查看yum仓库rpm包列表即可显示新增拓展源的rpm包:
[root@localhost yum.repos.d]# yum list
yum下载rpm包:
*使用yum命令安装软件包时,系统会直接将yum仓库的软件包安装到系统中
yumdownloader 命令:将yum仓库中的rpm包下载到本地不安装
[root@localhost ~]# yumdownloader zsh已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * epel: hkg.mirror.rackspace.com
查看下载好的包:
[root@localhost ~]# ls #该命令会直接把包下载到当前所在目录mytest zsh-5.0.2-31.el7.x86_64.rpm
- -resolve 参数:自动下载相关依赖包
*加上 - - resolve参数在下载目标rpm包时,会检查包的依赖关系并下载先关依赖包
[root@localhost ~]# yumdownloader --resolve zsh已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * epel: hkg.mirror.rackspace.com--> 正在检查事务---> 软件包 zsh.x86_64.0.5.0.2-31.el7 将被 安装--> 解决依赖关系完成zsh-5.0.2-31.el7.x86_64.rpm
- -destdir 参数:指定下载rpm包的存放目录
*如不指定存放目录,rpm包会存放到当前所在目录
[root@localhost ~]# yumdownloader zsh --destdir /root/mytest/已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * epel: hkg.mirror.rackspace.comzsh-5.0.2-31.el7.x86_64.rpm | 2.4 MB 00:00:00 [root@localhost ~]# ls /root/mytest/zsh-5.0.2-31.el7.x86_64.rpm
源码包安装:
*以apache2.2为例,源码包存放路径/usr/local/src/,apache2.2安装路径/usr/local/apache
在安装源码包之前先安装gcc编译器:
*gcc是GNU编译器套件(GNU Compiler Collection),它包括了C、C++、Objective-C、Fortran、Java、Ada、Go语言和 D语言的前端,也包括了这些语言的库(如 libstdc++、libgcj等等)。
[root@localhost src]# yum -y install gcc
进入指定目录下载apache2.2源码包:
[root@localhost ~]# cd /usr/local/src/[root@localhost src]# wget https://ftp.bit.nl/apache/httpd-2.2.29.tar.gz
解压apache包:
[root@localhost src]# tar -zxvf httpd-2.2.29.tar.gz
进入apache源码包目录执行如下命令:(指定安装目录生成makefile文件)
[root@localhost httpd-2.2.29]# ./configure --prefix=/usr/local/apache
查看上一条命令是否执行成功:(0代表成功,非0代表出错,源码安装要多查看命令执行结果避免出错)
[root@localhost httpd-2.2.29]# echo $?0
编译:
[root@localhost httpd-2.2.29]# make
[root@localhost httpd-2.2.29]# echo $?0
安装:
[root@localhost httpd-2.2.29]# make install
[root@localhost httpd-2.2.29]# echo $?0
安装完成:
[root@localhost httpd-2.2.29]# cd /usr/local/apache/ | lsABOUT_APACHE BuildBin.dsp config.log docs httpd.mak LAYOUT Makefile modules.lo README srclibacinclude.m4 buildconf config.nice emacs-style httpd.spec libhttpd.dep Makefile.in modules.o README.platforms supportApache.dsw buildmark.o config.status httpd include libhttpd.dsp Makefile.win NOTICE README-win32.txt testbuild CHANGES configure httpd.dep INSTALL libhttpd.mak modules NWGNUmakefile ROADMAP VERSIONINGBuildAll.dsp config.layout configure.in httpd.dsp InstallBin.dsp LICENSE modules.c os server