rpm工具使用、yum工具使用、源碼包安裝、yum更換國內源、使用系統盤搭建本地倉庫源
rpm工具:預先在Linux機器上編譯並打包安裝的文件,安裝迅速。(缺點:安裝程序包時,有可能因為依賴另外一個程序包而無法安裝)
yum工具:可以使用工具安裝時,同時將依賴的另外的程序包同時安裝好;(CentOS中免費,Red Hat裏需要付費)
源碼包:一般源碼包都是通過C語言開發出來的,Linux機器必須安裝gcc才能編譯;
檢測命令
echo $?
檢查上一條命令是否錯誤
0為正確 1為錯誤
RPM工具
rpm包格式:包名、版本號、發布版本號、平臺
舉例:libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm
包名為:libjpeg-turbo-devel
版本號:1.2.90
發布版本號:5.el7
平臺:x86_64
準備工作:
光驅設置好系統安裝盤鏡像,將光驅掛載到/mnt目錄下:
[root@shu-test ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 寫保護,將以只讀方式掛載 [root@shu-test ~]# df -h |grep -v tmpfs 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 28G 1.5G 27G 6% / /dev/sda1 197M 97M 100M 50% /boot /dev/sr0 4.3G 4.3G 0 100% /mnt [root@shu-test ~]# cd /mnt/ [root@shu-test 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 [root@shu-test mnt]#
安裝RPM包
格式:
rpm -ivh [rpm包文件]
[root@shu-test Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
準備中... ################################# [100%]
正在升級/安裝...
1:zsh-5.0.2-28.el7 ################################# [100%]
[root@shu-test Packages]#
升級RPM包
格式:
rpm -Uvh [rpm包文件]
卸載RPM包
格式:
rpm -e [rpm包名]
[root@shu-test Packages]# rpm -e zsh
[root@shu-test Packages]#
查詢
查詢安裝的包
格式:
rpm -qa
查詢指定包是否安裝
格式:
rpm -q [包名]
查詢指定包信息
格式:
rpm -qi [包名]
列出包安裝的文件
格式:
rpm -ql [包名]
[root@shu-test 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@shu-test Packages]#
列出某個文件屬於哪個RPM包
格式:
rpm -qf [文件絕對路徑]
[root@shu-test Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-2.el7.x86_64
[root@shu-test Packages]#
yum工具
yum工具最大的優勢就是可以在聯網去下載所需要的RPM包,然後自動安裝。如果要安裝的RPM包郵依賴關系,yum工具會幫我們依次安裝所有相關的RPM包;
列出所有RPM包
格式:
yum list
[root@shu-test Packages]# yum list | head -n 10
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
已安裝的軟件包
GeoIP.x86_64 1.5.0-11.el7 @anaconda
NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libnm.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-team.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-tui.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-wifi.x86_64 1:1.8.0-9.el7 @anaconda
由於管道被破壞而退出
[root@shu-test Packages]#
搜索RPM包
格式:
yum search [關鍵詞]
[root@shu-test Packages]# yum search vim
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
======================================== N/S matched: vim ========================================
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editor
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
neovim.x86_64 : Vim-fork focused on extensibility and agility
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
python2-neovim.noarch : Python client to Neovim
python34-neovim.noarch : Python client to Neovim
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-go.x86_64 : Go development plugin for Vim
vim-gtk-syntax.noarch : Vim syntax highlighting for GLib, Gtk+, Gstreamer, and more
vim-minimal.x86_64 : A minimal version of the VIM editor
vim-vimoutliner.noarch : Script for building an outline editor on top of Vim
xtuple-csvimp-devel.x86_64 : CSVImp development files
vim-halibut.noarch : Syntax file for the halibut manual tool
xtuple-csvimp.x86_64 : xTuple data import utility
名稱和簡介匹配 only,使用“search all”試試。
[root@shu-test Packages]#
使用管道符搜索
yum list | grep ‘vim‘
[root@shu-test Packages]# yum list | grep ‘vim‘
vim-common.x86_64 2:7.4.160-2.el7 @base
vim-enhanced.x86_64 2:7.4.160-2.el7 @base
vim-filesystem.x86_64 2:7.4.160-2.el7 @base
vim-minimal.x86_64 2:7.4.160-2.el7 @anaconda
beakerlib-vim-syntax.noarch 1.16-3.el7 epel
fluxbox-vim-syntax.noarch 1.3.7-1.el7 epel
neovim.x86_64 0.2.0-2.el7 epel
protobuf-vim.x86_64 2.5.0-8.el7 base
python2-neovim.noarch 0.1.13-3.el7 epel
python34-neovim.noarch 0.1.13-3.el7 epel
vim-X11.x86_64 2:7.4.160-2.el7 base
vim-go.x86_64 1.8-3.el7 epel
vim-gtk-syntax.noarch 20130716-1.el7 epel
vim-halibut.noarch 1.2-1.el7 epel
vim-vimoutliner.noarch 0.3.7-5.el7 epel
xtuple-csvimp.x86_64 0.5.4-8.el7 epel
xtuple-csvimp-devel.x86_64 0.5.4-8.el7 epel
[root@shu-test Packages]#
安裝RPM包
格式:
yum install [-y] [包名]
[root@shu-test Packages]# yum install -y protobuf
已加載插件:fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 8.0 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): epel/x86_64/updateinfo | 866 kB 00:00:05
(2/4): epel/x86_64/primary_db | 6.2 MB 00:00:00
(3/4): extras/7/x86_64/primary_db | 145 kB 00:00:05
(4/4): updates/7/x86_64/primary_db | 5.2 MB 00:00:09
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 protobuf.x86_64.0.2.5.0-8.el7 將被 安裝
--> 解決依賴關系完成
依賴關系解決
==================================================================================================
Package 架構 版本 源 大小
==================================================================================================
正在安裝:
protobuf x86_64 2.5.0-8.el7 base 338 k
事務概要
==================================================================================================
安裝 1 軟件包
總下載量:338 k
安裝大小:1.1 M
Downloading packages:
protobuf-2.5.0-8.el7.x86_64.rpm | 338 kB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : protobuf-2.5.0-8.el7.x86_64 1/1
驗證中 : protobuf-2.5.0-8.el7.x86_64 1/1
已安裝:
protobuf.x86_64 0:2.5.0-8.el7
完畢!
[root@shu-test Packages]#
卸載RPM包
格式:
yum remove [-y] [RPM包]
升級RPM包
格式:
yum update [-y] [RPM包]
根據命令來查詢安裝包
格式:
yum provides “[命令]”
yum provides "/*/vim"
搭建yum本地倉庫
當系統無法聯網時,就無法便捷實用yum工具了,此時我們可以實用光盤系統制作yum源;
掛載鏡像到/mnt目錄
mount /dev/cdrom /mnt
備份文件
cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
刪除文件
[root@shu-test Packages]# cd /etc/yum.repos.d
[root@shu-test yum.repos.d]# rm -rf ./*
創建新文件
/etc/yum.repos.d/dvd.repo
以及文件內容
[root@shu-test yum.repos.d]# vim /etc/yum.repos.d/dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpcheck=0
清除緩存
yum clean all
[root@shu-test yum.repos.d]# yum clean all
已加載插件:fastestmirror
正在清理軟件源: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@shu-test yum.repos.d]#
刷新生成緩存
yum makecache
[root@shu-test yum.repos.d]# yum makecache
已加載插件:fastestmirror
dvd | 3.6 kB 00:00:00
(1/4): dvd/group_gz | 156 kB 00:00:00
(2/4): dvd/filelists_db | 3.1 MB 00:00:00
(3/4): dvd/primary_db | 3.1 MB 00:00:00
(4/4): dvd/other_db | 1.2 MB 00:00:00
Determining fastest mirrors
元數據緩存已建立
[root@shu-test yum.repos.d]#
安裝軟件包
[root@shu-test yum.repos.d]# yum install -y tftp
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 tftp.x86_64.0.5.2-13.el7 將被 安裝
--> 解決依賴關系完成
依賴關系解決
==================================================================================================
Package 架構 版本 源 大小
==================================================================================================
正在安裝:
tftp x86_64 5.2-13.el7 dvd 35 k
事務概要
==================================================================================================
安裝 1 軟件包
總下載量:35 k
安裝大小:48 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : tftp-5.2-13.el7.x86_64 1/1
驗證中 : tftp-5.2-13.el7.x86_64 1/1
已安裝:
tftp.x86_64 0:5.2-13.el7
完畢!
[root@shu-test yum.repos.d]#
更換yum倉庫源
yum聯網下載源一般都是國外網絡資源,我們為了更快安裝可以更換為國內的資源下載;
進入目錄
cd /etc/yum.repos.d
刪除文件
rm -rf CentOS-Base.repo
下載163源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@shu-test yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-01-09 01:13:09-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主機 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在連接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo”
100%[========================================================>] 1,572 --.-K/s 用時 0s
2018-01-09 01:13:15 (108 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])
[root@shu-test yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@shu-test yum.repos.d]#
或者
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum下載rpm包
有時候我們需要下載RPM包但不安裝,僅僅是復制給其他機器使用;
下載RPM包而不安裝
默認RPM包保存路徑為/var/cache/yum/x86_64/7/base/packages/
格式:
yum install [包名] -y --downloadonly
[root@shu-test yum.repos.d]# yum install zsh --downloadonly
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 zsh.x86_64.0.5.0.2-28.el7 將被 安裝
--> 解決依賴關系完成
依賴關系解決
==================================================================================================
Package 架構 版本 源 大小
==================================================================================================
正在安裝:
zsh x86_64 5.0.2-28.el7 base 2.4 M
事務概要
==================================================================================================
安裝 1 軟件包
總計:2.4 M
安裝大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
[root@shu-test yum.repos.d]# rpm -q zsh
未安裝軟件包 zsh
[root@shu-test yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
zsh-5.0.2-28.el7.x86_64.rpm
[root@shu-test yum.repos.d]#
指定下載RPM包的保存路徑
格式:
yum install [包名] --downloadonly --downloaddir=[路徑]
[root@shu-test yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 zsh.x86_64.0.5.0.2-28.el7 將被 安裝
--> 解決依賴關系完成
依賴關系解決
==================================================================================================
Package 架構 版本 源 大小
==================================================================================================
正在安裝:
zsh x86_64 5.0.2-28.el7 base 2.4 M
事務概要
==================================================================================================
安裝 1 軟件包
總下載量:2.4 M
安裝大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
[root@shu-test yum.repos.d]# ls /tmp/
1.txt
b
d6z
d6z.tar
systemd-private-29a53244520c4fe384fbfe93dd3912c7-chronyd.service-4xzXLI
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vgauthd.service-G8e3b4
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vmtoolsd.service-w9qRlq
yum_save_tx.2018-01-09.01-34.V0zRaP.yumtx
yum_save_tx.2018-01-09.01-36.aUdoib.yumtx
yum_save_tx.2018-01-09.01-37.eAOZ3u.yumtx
yum_save_tx.2018-01-09.01-43.UDTWTf.yumtx
zsh-5.0.2-28.el7.x86_64.rpm
[root@shu-test yum.repos.d]#
下載已安裝的RPM包
格式:
yum reinstall -y [包名] --downloadonly --downloaddir=[路徑]
[root@shu-test yum.repos.d]# yum reinstall vim-enhanced.x86_64 --downloadonly --downloaddir=/tmp/
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 vim-enhanced.x86_64.2.7.4.160-2.el7 將被 已重新安裝
--> 解決依賴關系完成
依賴關系解決
==================================================================================================
Package 架構 版本 源 大小
==================================================================================================
重新安裝:
vim-enhanced x86_64 2:7.4.160-2.el7 base 1.0 M
事務概要
==================================================================================================
重新安裝 1 軟件包
總下載量:1.0 M
安裝大小:2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-2.el7.x86_64.rpm | 1.0 MB 00:00:06
exiting because "Download Only" specified
[root@shu-test yum.repos.d]# ls /tmp/
1.txt
b
d6z
d6z.tar
systemd-private-29a53244520c4fe384fbfe93dd3912c7-chronyd.service-4xzXLI
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vgauthd.service-G8e3b4
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vmtoolsd.service-w9qRlq
vim-enhanced-7.4.160-2.el7.x86_64.rpm
yum_save_tx.2018-01-09.01-34.V0zRaP.yumtx
yum_save_tx.2018-01-09.01-36.aUdoib.yumtx
yum_save_tx.2018-01-09.01-37.eAOZ3u.yumtx
yum_save_tx.2018-01-09.01-43.UDTWTf.yumtx
yum_save_tx.2018-01-09.01-46.58Zlvk.yumtx
zsh-5.0.2-28.el7.x86_64.rpm
[root@shu-test yum.repos.d]#
源碼包安裝
刪除目錄即可刪除源碼包;
源碼包的編譯必須通過GCC編譯器,所以必須安裝好gcc才能正常安裝源碼包;
yum install -y gcc
進入下載目錄
cd /usr/local/src
下載源碼包
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
[root@shu-test src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
--2018-01-09 01:51:34-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
正在解析主機 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.178, 2402:f000:1:416:101:6:6:178
正在連接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.178|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:7684419 (7.3M) [application/octet-stream]
正在保存至: “httpd-2.2.34.tar.gz”
100%[========================================================>] 7,684,419 1.09MB/s 用時 6.8s
2018-01-09 01:51:46 (1.08 MB/s) - 已保存 “httpd-2.2.34.tar.gz” [7684419/7684419])
[root@shu-test src]#
解壓源碼包
tar -zxvf httpd-2.2.34.tar.gz
查看如何安裝
more INSTALL
安裝方法
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
指定安裝路徑
./configure --prefix=/usr/local/apache2
編譯
make
安裝源碼包
make install
運行進程
/usr/local/apache2/bin/apachectl start
rpm工具使用、yum工具使用、源碼包安裝、yum更換國內源、使用系統盤搭建本地倉庫源