linux系統(tǒng)下安裝軟件包的三種方法:
1.rpm工具:下載軟件rpm包安裝,類似Windows的exe文件
2.yum工具:類似應(yīng)用商店,相比rpm安裝優(yōu)勢(shì)在于更方便快捷,會(huì)自動(dòng)安裝依賴包
3.源碼包:下載源碼包到linux系統(tǒng)中,需要編譯器編譯安裝
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)安寧免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
rpm工具用法:
rpm包的格式如下圖:(zsh為包名,5.0.2為版本號(hào),-31.el7為發(fā)布版本號(hào))
[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
準(zhǔn)備中... ################################# [100%]
正在升級(jí)/安裝...
1:zsh-5.0.2-31.el7 ################################# [100%]
升級(jí)rpm包命令:rpm -Uvh 包名
[root@localhost Packages]# rpm -Uvh zsh-5.0.2-31.el7.x86_64.rpm
*當(dāng)系統(tǒng)中有高版本的zsh包的時(shí)候,可以使用rpm -Uvh 升級(jí)包
卸載rpm包:rpm -e 包名
[root@localhost Packages]# rpm -e zsh #卸載不需要寫包的全名
查詢系統(tǒng)已安裝的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 #已安裝的包會(huì)列出包的信息
vim-enhanced-7.4.160-6.el7_6.x86_64
查詢指定包的詳細(xì)信息: rpm -qi 包名
[root@localhost Packages]# rpm -qi vim-enhanced
Name : vim-enhanced
Epoch : 2
Version : 7.4.160
Release : 6.el7_6
Architecture: x86_64
Install Date: 2019年08月28日 星期三 11時(shí)22分18秒
Group : Applications/Editors
Size : 2296674
License : Vim
Signature : RSA/SHA256, 2019年07月01日 星期一 21時(shí)34分29秒, Key ID 24c6a8a7f4a80eb5
Source RPM : vim-7.4.160-6.el7_6.src.rpm
Build Date : 2019年06月28日 星期五 21時(shí)59分48秒
Build Host : x86-02.bsys.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.
列出包的安裝文件: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 文件絕對(duì)路徑
[root@localhost Packages]# rpm -qf /usr/bin/vimdiff
vim-enhanced-7.4.160-6.el7_6.x86_64
yum工具的用法:
yum list :列出yum倉(cāng)庫(kù)中可以安裝的rpm包
[root@localhost ~]# yum list
*第三列表示倉(cāng)庫(kù)名,帶@符號(hào)表示已安裝
查看yum倉(cāng)庫(kù)配置文件:
[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倉(cāng)庫(kù)中的包
[root@localhost ~]# yum search tomcat
已加載插件:fastestmirror
Loading 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 Tomcat
tomcat-docs-webapp.noarch : The docs web application for Apache Tomcat
tomcat-javadoc.noarch : Javadoc generated documentation for Apache Tomcat
tomcat-jsp-2.2-api.noarch : Apache Tomcat JSP API implementation classes
tomcat-jsvc.noarch : Apache jsvc wrapper for Apache Tomcat as separate service
tomcat-lib.noarch : Libraries needed to run the Tomcat Web container
tomcat-servlet-3.0-api.noarch : Apache Tomcat Servlet API implementation classes
tomcat-webapps.noarch : The ROOT and examples web applications for Apache Tomcat
tomcatjss.noarch : JSS Connector for Apache Tomcat, a JSSE module for Apache Tomcat that uses JSS
tomcat.noarch : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
tomcat-el-2.2-api.noarch : Expression Language v2.2 API
yum list | grep 包名:第二種搜索包的方式,顯示信息更簡(jiǎn)潔
[root@localhost ~]# yum list | grep tomcat
tomcat.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:列出可以安裝的環(huán)境分組和拓展組
[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.aliyun.com
* updates: mirrors.aliyun.com
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 -y groupinstall 分組名:安裝分組 (分組名有多個(gè)單詞的情況下加單引號(hào))
[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 "/*/命令":查看命令由什么包安裝以及安裝路徑
*當(dāng)遇到命令名稱與包名不一樣的情況時(shí),使用yum list | grep 包名可能找不到具體信息,使用yum provides可以根據(jù)命令找到包名以及安裝路徑,比如:pstree命令,pstree命令的包名為psmisc
[root@localhost ~]# yum provides "/*/pstree"
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
psmisc-22.20-15.el7.x86_64 : Utilities for managing processes on your system
源 :base
匹配來(lái)源:
文件名 :/usr/bin/pstree
yum搭建本地倉(cāng)庫(kù):
掛載帶有centos鏡像的光盤:
[root@localhost ~]# mount /dev/cdrom /mnt/gp/
mount: /dev/sr0 寫保護(hù),將以只讀方式掛載
備份yum配置文件:
[root@localhost ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
清空配置文件:
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
新建本地yum倉(cāng)庫(kù)配置文件:
[root@localhost ~]# vim /etc/yum.repos.d/yumck.repo
添加以下內(nèi)容:
[yumck]
name=install yumck #自定義描述字符
baseurl=file:///mnt/gp/ #倉(cāng)庫(kù)中rpm包的路徑
enable=1 #是否可用,改為0改倉(cāng)庫(kù)即變?yōu)椴豢捎?gpgcheck=0 #是否檢測(cè)
清除緩存:
[root@localhost ~]# yum clean all
已加載插件:fastestmirror, langpacks
正在清理軟件源: yumck
Cleaning up list of fastest mirrors
Other repos take up 197 M of disk space (use --verbose for details)
查看本地yum倉(cāng)庫(kù)中可安裝的包:
[root@localhost ~]# yum list
安裝測(cè)試:
[root@localhost ~]# yum -y install zsh
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 zsh.x86_64.0.5.0.2-31.el7 將被 安裝
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
===========================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
===========================================================================================================================================================================
正在安裝:
zsh x86_64 5.0.2-31.el7 yumck 2.4 M
事務(wù)概要
===========================================================================================================================================================================
安裝 1 軟件包
總下載量:2.4 M
安裝大?。?.6 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : zsh-5.0.2-31.el7.x86_64 1/1
驗(yàn)證中 : zsh-5.0.2-31.el7.x86_64 1/1
已安裝:
zsh.x86_64 0:5.0.2-31.el7
完畢!
查看已安裝的包:
*第三列已顯示該包來(lái)源于本地yum倉(cāng)庫(kù)
[root@localhost ~]# yum list |grep zsh
zsh.x86_64 5.0.2-31.el7 @yumck
更換國(guó)內(nèi)yum源:
*centos默認(rèn)yum源是國(guó)外的,有時(shí)候安裝軟件速度很慢,可以更換網(wǎng)易yum源解決
備份系統(tǒng)自帶的yum配置文件:/etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# ls
CentOS-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下載對(duì)應(yīng)版本的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倉(cāng)庫(kù)rpm包列表:
[root@localhost yum.repos.d]# yum list
安裝拓展yum源:
*當(dāng)更換的國(guó)內(nèi)yum倉(cāng)庫(kù)或系統(tǒng)默認(rèn)yum倉(cāng)庫(kù)包不夠時(shí),可以添加yum拓展源(由redhat官方提供的yum拓展倉(cāng)庫(kù),包數(shù)量更多)
安裝拓展源 epel-release:
[root@localhost yum.repos.d]# yum -y install epel-release
查看配置文件:
*安裝完成后可以看到目錄下增加了epel拓展源(epel.repo、epel-testing.repo)配置文件
[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo
CentOS-Base.repo.bak CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
查看yum倉(cāng)庫(kù)rpm包列表即可顯示新增拓展源的rpm包:
[root@localhost yum.repos.d]# yum list
yum下載rpm包:
*使用yum命令安裝軟件包時(shí),系統(tǒng)會(huì)直接將yum倉(cāng)庫(kù)的軟件包安裝到系統(tǒng)中
yumdownloader 命令:將yum倉(cāng)庫(kù)中的rpm包下載到本地不安裝
[root@localhost ~]# yumdownloader zsh
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: hkg.mirror.rackspace.com
查看下載好的包:
[root@localhost ~]# ls #該命令會(huì)直接把包下載到當(dāng)前所在目錄
mytest zsh-5.0.2-31.el7.x86_64.rpm
- -resolve 參數(shù):自動(dòng)下載相關(guān)依賴包
*加上 - - resolve參數(shù)在下載目標(biāo)rpm包時(shí),會(huì)檢查包的依賴關(guān)系并下載先關(guān)依賴包
[root@localhost ~]# yumdownloader --resolve zsh
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: hkg.mirror.rackspace.com
--> 正在檢查事務(wù)
---> 軟件包 zsh.x86_64.0.5.0.2-31.el7 將被 安裝
--> 解決依賴關(guān)系完成
zsh-5.0.2-31.el7.x86_64.rpm
- -destdir 參數(shù):指定下載rpm包的存放目錄
*如不指定存放目錄,rpm包會(huì)存放到當(dāng)前所在目錄
[root@localhost ~]# yumdownloader zsh --destdir /root/mytest/
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: hkg.mirror.rackspace.com
zsh-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語(yǔ)言和 D語(yǔ)言的前端,也包括了這些語(yǔ)言的庫(kù)(如 libstdc++、libgcj等等)。
[root@localhost src]# yum -y install gcc
進(jìn)入指定目錄下載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
進(jìn)入apache源碼包目錄執(zhí)行如下命令:(指定安裝目錄生成makefile文件)
[root@localhost httpd-2.2.29]# ./configure --prefix=/usr/local/apache
查看上一條命令是否執(zhí)行成功:(0代表成功,非0代表出錯(cuò),源碼安裝要多查看命令執(zhí)行結(jié)果避免出錯(cuò))
[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/ | ls
ABOUT_APACHE BuildBin.dsp config.log docs httpd.mak LAYOUT Makefile modules.lo README srclib
acinclude.m4 buildconf config.nice emacs-style httpd.spec libhttpd.dep Makefile.in modules.o README.platforms support
Apache.dsw buildmark.o config.status httpd include libhttpd.dsp Makefile.win NOTICE README-win32.txt test
build CHANGES configure httpd.dep INSTALL libhttpd.mak modules NWGNUmakefile ROADMAP VERSIONING
BuildAll.dsp config.layout configure.in httpd.dsp InstallBin.dsp LICENSE modules.c os server