用python開發的工具,安裝的也是rpm包html
優勢是能夠自動安裝一個包所依賴的一些包。rpm包在安裝時候可能會須要依賴另外一個包的支持,而安裝另外一個包,可能還須要另外一個的依賴。這時候用yum就能夠自動安裝上全部的依賴包。方便,簡單,快捷。python
要想使用rpm工具,首先須要有rpm包,下面利用contos7的鏡像文件裏找一下rpm包。linux
先鏈接虛擬機裏面的光驅,光盤文件選一下contos7的鏡像。鏈接好後開始掛載。git
掛載到/mnt/下,mount /dev/cdrom /mnt/github
[root@aminglinux-01 ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 寫保護,將以只讀方式掛載 [root@aminglinux-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 3.6G 15G 20% / 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/sda1 197M 109M 88M 56% /boot tmpfs 98M 0 98M 0% /run/user/0 /dev/sr0 4.1G 4.1G 0 100% /mnt
到mnt下看一下里面的內容。也就是光盤裏的文件。rpm包是以紅色名字顯示的。docker
[root@aminglinux-01 ~]# cd /mnt/ [root@aminglinux-01 mnt]# ls CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
其中 Packages這個目錄下裝的就是rpm包文件。apache
xz-devel-5.2.2-1.el7.x86_64.rpm 包名-版本號-發佈版本號.64位或32位數系統要求
以這個rpm包爲例子,xz-devel就是包名,5.2.2這個是版本號。1.el7是發佈版本號。x86_64,運行平臺,區分32位,或者64位。也有不須要區分的,均可以用。vim
contos7已經開始不區分32或者64位的,都是64位系統。通常64位系統能夠安裝32位的軟件。反過來不能夠。windows
用法:centos
安裝:rpm -ivh rpm包文件
升級:rpm -Uvh rpm包文件
卸載 :rpm -e 包名
查詢安裝的包: rpm -qa
查詢指定包是否安裝 : rpm -q
查詢指定包信息 : rpm -qi
列出包安裝的文件 : rpm -ql
查看一個文件是由哪一個包安裝的 rpm -qf 文件絕對路徑
rpm安裝rpm -ivh rpm包文件 (這個是在當前有rpm包的目錄,也可用絕對路徑)
[root@aminglinux-01 Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm 準備中... ################################# [100%] 正在升級/安裝... 1:zsh-5.0.2-25.el7 ################################# [100%] [root@aminglinux-01 Packages]#
[root@aminglinux-01 Packages]# rpm -e zsh [root@aminglinux-01 Packages]#
python-perf-3.10.0-514.el7.x86_64 perl-XML-Dumper-0.81-17.el7.noarch logrotate-3.8.6-12.el7.x86_64 net-snmp-agent-libs-5.7.2-28.el7.x86_64 nss-3.21.0-17.el7.x86_64 ----中間省略,特別多---- dhclient-4.2.5-47.el7.centos.x86_64 crontabs-1.11-6.20121102git.el7.noarch libdrm-2.4.67-3.el7.x86_64
[root@aminglinux-01 Packages]# rpm -q ppp ppp-2.4.5-33.el7.x86_64 [root@aminglinux-01 Packages]# rpm -q pppp 未安裝軟件包 pppp
[root@aminglinux-01 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 <http://bugs.centos.org> 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@aminglinux-01 Packages]#
以下,上面講到用rpm安裝和卸載會出現依賴問題很是麻煩。若是用yum安裝和卸載就會自動安裝或卸載所須要的依賴。
[root@aminglinux-01 Packages]# rpm -ivh texlive-tools-svn26263.0-38.el7.noarch.rpm 錯誤:依賴檢測失敗: texlive-base 被 texlive-tools-2:svn26263.0-38.el7.noarch 須要 texlive-kpathsea-bin 被 texlive-tools-2:svn26263.0-38.el7.noarch 須要 tex-kpathsea 被 texlive-tools-2:svn26263.0-38.el7.noarch 須要 tex(color.sty) 被 texlive-tools-2:svn26263.0-38.el7.noarch 須要
yum install 包名 ,在用texlive這個包試一下。
事務概要 ========================================================================================================================================================== 安裝 1 軟件包 (+223 依賴軟件包) 總下載量:118 M 安裝大小:226 M Is this ok [y/d/N]:
能夠看到自動檢測到須要223個依賴包。按y就會下載安裝,按n就是不安裝。若是這麼多依賴用rpm一個一個安裝的話會累死,這也是yum的優勢。
yum-plugin-tmprepo.noarch 1.1.31-45.el7 base yum-plugin-tsflags.noarch 1.1.31-45.el7 base yum-plugin-upgrade-helper.noarch 1.1.31-45.el7 base yum-plugin-verify.noarch 1.1.31-45.el7 base yum-plugin-versionlock.noarch 1.1.31-45.el7 base yum-rhn-plugin.noarch 2.0.1-10.el7 base yum-updateonboot.noarch 1.1.31-45.el7 base yum-utils.noarch 1.1.31-45.el7 base zenity.x86_64 3.22.0-1.el7 base
列出的很是多, 左側是包名字和運行平臺, 中間是版本號,和平臺號。 最右側是倉庫名字。@開頭的是已經安裝過的包。
/etc/yum.repos.d/這裏面是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
用搜索vim舉例。 yum search vim
[root@localhost ~]# yum search vim 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn ==================================================================== N/S matched: vim ==================================================================== protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions vim-X11.x86_64 : The VIM version of the vi editor for the X Window System vim-common.x86_64 : The common files needed by any version of the VIM editor vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements vim-filesystem.x86_64 : VIM filesystem layout vim-minimal.x86_64 : A minimal version of the VIM editor 名稱和簡介匹配 only,使用「search all」試試。 [root@localhost ~]#
用vim搜索舉例 。 yum list |grep 'vim' 。不光能精確過濾,還有顏色顯示。
[root@localhost ~]# yum grouplist 已加載插件:fastestmirror 沒有安裝組信息文件 Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn 可用的環境分組: 最小安裝 基礎設施服務器 計算節點 文件及打印服務器 基本網頁服務器 虛擬化主機 帶 GUI 的服務器 GNOME 桌面 KDE Plasma Workspaces 開發及生成工做站 可用組: 傳統 UNIX 兼容性 兼容性程序庫 圖形管理工具 安全性工具 開發工具 控制檯互聯網工具 智能卡支持 科學記數法支持 系統管理 系統管理工具 完成
中文顯示可能沒法使用。須要用 LANG=en 轉換英文看一下
[root@localhost ~]# LANG=en [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.huaweicloud.com * updates: mirrors.zju.edu.cn 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
卸載軟件包也是會把全部的依賴卸載。因此卸載時候儘可能不要加-y, 以避免出現意外。
若是yum update 不加包名會自動升級系統中能升級的全部包。包括系統自己。
[root@localhost ~]# yum provides "/*/vim" Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn base/7/x86_64/filelists_db | 6.9 MB 00:00:06 extras/7/x86_64/filelists_db | 519 kB 00:00:00 updates/7/x86_64/filelists_db | 1.3 MB 00:00:00 cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system Repo : base Matched from: Filename : /usr/share/cmake/editors/vim 2:docker-unit-test-1.13.1-53.git774336d.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim 2:docker-unit-test-1.13.1-58.git87f2fab.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim 2:docker-unit-test-1.13.1-63.git94f4240.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim git-1.8.3.1-13.el7.x86_64 : Fast Version Control System Repo : base Matched from: Filename : /usr/share/doc/git-1.8.3.1/contrib/vim 2:vim-common-7.4.160-4.el7.x86_64 : The common files needed by any version of the VIM editor Repo : base Matched from: Filename : /usr/share/vim 2:vim-enhanced-7.4.160-4.el7.x86_64 : A version of the VIM editor which includes recent enhancements Repo : base Matched from: Filename : /usr/bin/vim 2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent enhancements Repo : @base Matched from: Filename : /usr/bin/vim
能夠根據命令路徑來判斷包名字。好比在/bin下或者/sbin下。
有些特殊狀況下,服務器沒有聯網,可是想要yum安裝一些軟件。這時候就須要搭建一個本地的yum倉庫來使用。
思路是先準備一個有yum包的儲存盤,好比光盤。而後把以前的yum倉庫文件備份下刪除,而後添加新的倉庫配置文件。
[root@localhost ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak [root@localhost ~]# rm -f /etc/yum.repos.d/*
[dvd] name=install dvd baseurl=file:///mnt 定義rpm包放在那裏 enable=1 是否可用,1就是可用 gpgcheck=0 是否檢測,0不檢測。
[root@localhost ~]# yum clean all Failed to set locale, defaulting to C Loaded plugins: fastestmirror Cleaning repos: dvd Cleaning up everything Cleaning up list of fastest mirrors
xsettings-kde.x86_64 0.12.3-7.el7 dvd xsom.noarch 0-10.20110809svn.el7 dvd xterm.x86_64 295-3.el7 dvd xulrunner.x86_64 31.6.0-2.el7.centos dvd xvattr.x86_64 1.3-27.el7 dvd xz-devel.x86_64 5.2.2-1.el7 dvd yajl.x86_64 2.0.4-4.el7 dvd yelp.x86_64 1:3.14.2-1.el7 dvd yelp-libs.x86_64 1:3.14.2-1.el7 dvd yelp-xsl.noarch 3.14.0-1.el7 dvd
contos7默認yum源指向的是國外的網站,有的時候yum裝程序特別的慢。這時候就須要把yum源改爲國內的,下載速度就會提高。
首先刪除rm -f CentOS-Base.repo 這個源
下載163源 CentOS7-Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 或者 curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all 清緩存
yum list 測試或者安裝個wge試一下,就是能夠用了。
光安裝一個163源不夠用,不少rpm都沒有。因此安裝一個擴展源。
安裝好後會在 /etc/yum.repos.d下新生成一個epel.repo
epel.repo
zvbi.x86_64 0.2.35-1.el7 epel zvbi-devel.x86_64 0.2.35-1.el7 epel zvbi-fonts.noarch 0.2.35-1.el7 epel zziplib.i686 0.13.62-5.el7 base zziplib.x86_64 0.13.62-5.el7 base zziplib-devel.i686 0.13.62-5.el7 base
以前說過搭建本地yum倉庫可是是用光驅裏面的rpm包作的實驗,而不是真正所須要的本地倉庫。下面說一下如何用yum下載所須要的rpm包。
這種用法限於該包尚未安裝。已經安裝過的會提醒。
下載到/var/cache/yum/x86_64/7/倉庫名/packages下面。
[root@localhost ~]# yum install zsh --downloadonly --downloaddir=/tmp/ Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * epel: mirrors.tongji.edu.cn Resolving Dependencies --> Running transaction check ---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================== Package Arch Version Repository Size ========================================================================================================================================================== Installing: zsh x86_64 5.0.2-28.el7 base 2.4 M Transaction Summary ========================================================================================================================================================== Install 1 Package Total download size: 2.4 M Installed size: 5.6 M Background downloading packages, then exiting: zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:00:02 exiting because "Download Only" specified [root@localhost ~]# ls /tmp/ 1.txt systemd-private-a44b0f41787b47de9f672a72cec9768d-vmtoolsd.service-FOn2fg yum_save_tx.2018-05-30.11-10.T6z0Ih.yumtx passwd.sh yum_save_tx.2018-05-30.09-10.cW8ODj.yumtx zsh-5.0.2-28.el7.x86_64.rpm [root@localhost ~]#
[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz --2018-05-30 11:20:40-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 9076901 (8.7M) [application/octet-stream] Saving to: 'httpd-2.4.33.tar.gz' 100%[================================================================================================================>] 9,076,901 1.59MB/s in 5.9s 2018-05-30 11:20:46 (1.46 MB/s) - 'httpd-2.4.33.tar.gz' saved [9076901/9076901] [root@localhost src]# ls httpd-2.4.33.tar.gz
解壓好後,進入目錄,找到配置文件README 。這裏面是一些軟件的說明介紹。
還有一個文件是INSTALL 裏面是安裝文檔。教程。開頭介紹了安裝步驟。
[root@localhost httpd-2.4.33]# cat INSTALL APACHE INSTALLATION OVERVIEW Quick Start - Unix ------------------ For complete installation documentation, see [ht]docs/manual/install.html or http://httpd.apache.org/docs/2.4/install.html $ ./configure --prefix=PREFIX $ make $ make install $ PREFIX/bin/apachectl start
./configure --help是能夠查看安裝都有哪些功能可選安裝的。
./configure --prefix=/usr/local/apache2 指定安裝目錄
[root@localhost httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation.
直接報錯了。 輸入 echo $?查看若是是0就是上面命令執行沒有問題,若是是1或則別的數說明上面命令報錯了。
根據報錯安裝yum install apr apr-util apr-devel
而後安裝yum install gcc
而後 make
而後 make install
卸載源碼包的安裝就是刪除安裝文件。