Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 6 章 Package Management

目錄

6.1. APT 包管理
6.1.1. apt-cache
6.1.1.1. search
6.1.1.2. depends
6.1.1.3. policy
6.1.1.4. 查看所屬鏡像
6.1.2. Apt-Get
6.1.2.1. Search
6.1.2.2. Installation
6.1.2.3. Update
6.1.2.4. Remove
6.1.2.5. purge
6.1.3. aptitude
6.1.4. Automatic Updates
6.1.4.1. 升級過程中連結中斷怎麼辦?
6.1.5. 更換 api 源鏡像
6.1.5.1. Ubuntu 18.04
6.1.6. dpkg
6.1.6.1. -i|--install 安裝.deb包
6.1.6.2. -r|--remove 卸載.deb包
6.1.6.3. -L|--listfiles <package> ... List files `owned' by package(s). 列出包中的檔案
6.1.6.4. -l|--list [<pattern> ...] List packages concisely. 列出.deb包
6.1.6.5. Status
6.1.6.6. dpkg-deb - Debian package archive (.deb) manipulation tool
6.1.6.6.1. -X, --vextract archive directory Extract and display the filenames contained by a package
6.1.6.6.2. -e, --control archive [directory] Extracts the control information files from a package archive into the specified directory.
6.1.6.6.3. -b, --build directory [archive|directory]
6.1.6.7. dpkg-reconfigure
6.1.7. Upgrading
6.1.7.1. GUI
6.1.7.2. CLI
6.1.7.3. CDROM
6.1.8. 製作.deb安裝包
6.1.8.1. checkinstall — Track installation of local software, and produce a binary manageable with your package management software.
6.1.8.2. dh_make - prepare Debian packaging for an original source archive
6.1.8.3. control
6.2. snap - Tool to interact with snaps
6.2.1. 安裝 snap
6.2.2. 列出已經安裝的snap包
6.2.3. 搜索要安裝的snap包
6.2.4. 安裝snap包
6.2.5. 更新snap包
6.2.6. 把一個包還原到以前安裝的版本
6.2.7. 刪除snap包
6.2.8. 查詢最近做的操作日誌
6.3. DNF 包管理
6.3.1. 安裝 epel-release 包
6.3.2. DNF 軟件庫管理
6.3.3. 顯示系統中可用的 DNF 軟件庫
6.3.3.1. 查看系統中所有的 DNF 軟件庫(包括禁用狀態)
6.3.4. 列出所有 RPM 包
6.3.4.1. 查看已經安裝包
6.3.4.2. 列出可用的軟件包
6.3.4.3. 顯示重複內容
6.3.5. 搜索軟件庫中的包
6.3.6. 查看軟件包詳情
6.3.7. 查找某一檔案的提供者
6.3.8. 刪除軟件包
6.4. yum - Yellowdog Updater Modified 包管理
6.4.1. Yum Resource & Yum Mirror
6.4.1.1. fastestmirror
6.4.1.2. Fedora resource
6.4.1.2.1. Fedora 5.4
6.4.1.2.2. Fedora 6.x
6.4.1.2.3. Fedora 7.x
6.4.1.3. rpmforge-release
6.4.1.3.1. CentOS 5.x
6.4.1.3.2. CentOS 6.x
6.4.1.3.3. CentALT
6.4.1.4. atomic
6.4.1.5. famillecollet
6.4.1.6. rpmfind.net
6.4.1.7. pkgs.org
6.4.1.8. China Resource
6.4.1.9. 製作本地共享源
6.4.2. yum - Yellowdog Updater Modified
6.4.2.1. YUM 源管理
6.4.2.2. install
6.4.2.3. localinstall
6.4.2.4. list
6.4.2.5. search
6.4.2.6. update / upgrade
6.4.2.7. remove
6.4.2.8. installed
6.4.2.9. group
6.4.2.9.1. grouplist
6.4.2.9.2. groupinfo
6.4.2.9.3. groupinstall
6.4.2.9.4. groupremove
6.4.2.10. 查看包的依賴關係
6.4.2.11. provides / whatprovides
6.4.3. rpm - RPM Package Manager
6.4.3.1. install/upgrade/remove
6.4.3.1.1. --prefix
6.4.3.2. query
6.4.3.2.1. changelog 查看變更日誌
6.4.4. rpmbuild - Build RPM Package(s)
6.4.4.1. RPM_directory_macros
6.4.4.2. --define 專遞模板變數
6.4.4.3. defattr
6.4.4.4. GPG 簽名
6.4.4.5. 使用 CMake3 編譯並創建RPM包
6.4.4.6. FAQ
6.5. Homebrew
6.6. 清理安裝包

6.1. APT 包管理

包管理工具

6.1.1. apt-cache

6.1.1.1. search

			
# apt-cache search tcpdump
			
			

6.1.1.2. depends

# apt-cache depends tcpdump
			

6.1.1.3. policy

$ apt-cache policy tcpdump
tcpdump:
  Installed: 4.0.0-6ubuntu3
  Candidate: 4.0.0-6ubuntu3
  Version table:
 *** 4.0.0-6ubuntu3 0
        500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
        100 /var/lib/dpkg/status

			

6.1.1.4. 查看所屬鏡像

			
neo@m-1d41c853af58:~$ apt-cache madison docker
    docker |      1.5-2 | http://mirrors.ustc.edu.cn/ubuntu cosmic/universe amd64 Packages
    docker |      1.5-2 | http://mirrors.ustc.edu.cn/ubuntu cosmic/universe i386 Packages			
			
			

6.1.2. Apt-Get

apt 命令預設從cdrom安裝

註釋/etc/apt/sources.list中的deb cdrom項, apt會從互聯網上安裝

netkiller@Linux-server:~$ sudo vi /etc/apt/sources.list
# deb cdrom:[Ubuntu-Server 6.10 _Edgy Eft_ - Release i386 (20061025.1)]/ edgy main restricted
		
apt-setup

安裝是首先會下載包到/var/cache/apt/archives/目錄

6.1.2.1. Search

Searching a software package

$ apt-cache search package
			

列出軟件包的詳細信息:

$ apt-cache show package
			

列出軟件包的依賴關係:

$ apt-cache depends package
			

列出軟件包, 以及逆向依賴的軟件包的詳細版本信息:

$ apt-cache showpkg package
			

6.1.2.2. Installation

$ sudo apt install package
			

*.deb

sudo dpkg -i *.deb
			

6.1.2.3. Update

$ apt update
$ apt upgrade
			

Smart software update

$ apt dist-upgrade
			

6.1.2.4. Remove

刪除系統中的foo軟件包

$ sudo apt remove foo
			

刪除系統中的package軟件包及其配置檔案

$ sudo apt remove --purge package
			

6.1.2.5. purge

sudo apt purge package			
			

6.1.3. aptitude

管理軟件包

neo@kerberos:~$ tasksel
neo@kerberos:~$ aptitude
		

6.1.4. Automatic Updates

sudo apt-get install unattended-upgrades
		

/etc/apt/apt.conf.d/50unattended-upgrades


		

Notifications

sudo apt-get install apticron
		

/etc/apticron/apticron.conf

EMAIL="root@example.com"
		

6.1.4.1. 升級過程中連結中斷怎麼辦?

Ubuntu 16.04 升級到 16.10 過程中SSH中斷

我猜測do-release-upgrade 一定會有恢復方案,應該是screen. 經過查看果然是 screen

開始嘗試恢復screen 提示

neo@netkiller:~$ screen -ls
No Sockets found in /var/run/screen/S-neo.

後來想到應該是root而不是當前用戶,再次查看

neo@netkiller:~$ sudo screen -ls
[sudo] password for neo:
There is a screen on:
 1955.ubuntu-release-upgrade-screen-window (11/25/2016 07:44:50 PM)       (Detached)
1 Socket in /var/run/screen/S-root.

的確如猜測一樣,現在回覆窗口吧。

neo@netkiller:~$ sudo screen -r 1955

繼續			
			

6.1.5. 更換 api 源鏡像

備份 /etc/apt/sources.list 檔案,然後覆蓋即可

		
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse		
		
		

6.1.5.1. Ubuntu 18.04

			
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
cat > /etc/apt/sources.list << EOF 
deb http://mirrors.aliyun.com/ubuntu/ xenial main 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main 
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main 
deb http://mirrors.aliyun.com/ubuntu/ xenial universe 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe 
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe 
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main 
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe 
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe 
EOF			
			
			

6.1.6. dpkg

6.1.6.1. -i|--install 安裝.deb包

$ sudo dpkg -i netkiller-1.0.deb
			

6.1.6.2. -r|--remove 卸載.deb包

$ sudo dpkg -r netkiller
			

6.1.6.3. -L|--listfiles <package> ... List files `owned' by package(s). 列出包中的檔案

$ dpkg -L netkiller|more
/.
/opt
/opt/neo
/opt/neo/netkiller-1.0
/opt/neo/netkiller-1.0/linux
/opt/neo/netkiller-1.0/linux/docbook.css
/opt/neo/netkiller-1.0/linux/apas03.html
/opt/neo/netkiller-1.0/linux/shell
			

6.1.6.4. -l|--list [<pattern> ...] List packages concisely. 列出.deb包

			
$ sudo dpkg -l netkiller
$ dpkg -l netkiller
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
un  netkiller      <none>         (no description available)
			
			

6.1.6.5. Status

系統上裝了哪些軟件包

要查看 Debian 系統上安裝的所有軟件包的狀態, 運行

     dpkg --list

輸出每個軟件包的一行簡單介紹, 2字元的狀態標誌, 包名, 所安裝版本, 和簡要描述.

查看以 "foo" 開頭的軟件包的狀態, 執行:

     dpkg --list 'foo*'

要得到某個軟件包的更詳細信息, 執行:

     dpkg --status packagename
			

List of installed software packages

$ dpkg-query -W
			

Description of installed software packages

$ dpkg -l
			

找出一個檔案的歸屬包

dpkg --search cachemgr
squid3-cgi: /usr/lib/cgi-bin/cachemgr3.cgi
squid3-cgi: /usr/share/man/man8/cachemgr3.cgi.8.gz
squid3-cgi: /etc/squid3/cachemgr.conf
			

6.1.6.6. dpkg-deb - Debian package archive (.deb) manipulation tool

6.1.6.6.1. -X, --vextract archive directory Extract and display the filenames contained by a package
$ dpkg -X dmd_2.057-0_amd64.deb dmd_2.057-0_amd64
				
6.1.6.6.2. -e, --control archive [directory] Extracts the control information files from a package archive into the specified directory.
$ dpkg -e dmd_2.057-0_amd64.deb

$ find DEBIAN/
DEBIAN/
DEBIAN/conffiles
DEBIAN/md5sum
DEBIAN/control
				
6.1.6.6.3. -b, --build directory [archive|directory]

在你的目錄下創建DEBIAN目錄與control檔案

				
mkdir DEBIAN/

cat >> DEBIAN/control <<EOF
Package: netkiller
Version: 1.0-0
Architecture: amd64
Maintainer: Neo Chen <netkiller@msn.com>
Installed-Size: 51196
Depends: libc6-dev, gcc, gcc-multilib, libc6 (>= 2.11), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1)
Section: devel
Priority: optional
Description: Netkiller ebook
 .
 Main designer: Neo Chen
 .
 Homepage: http://netkiller.github.com/
 .
EOF
				
				
				
$ dpkg -b dlang dlang.deb
dpkg-deb: building package `netkiller' in `dlang.deb'.		

$ dpkg --info dlang.deb
 new debian package, version 2.0.
 size 263266 bytes: control archive= 371 bytes.
     354 bytes,    14 lines      control              
 Package: netkiller
 Version: 1.0-0
 Architecture: amd64
 Maintainer: Neo Chen <netkiller@msn.com>
 Installed-Size: 51196
 Depends: libc6-dev, gcc, gcc-multilib, libc6 (>= 2.11), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1)
 Section: devel
 Priority: optional
 Description: Netkiller ebook
  .
  Main designer: Neo Chen
  .
  Homepage: http://netkiller.github.com/
  .

$ dpkg --contents dlang.deb
drwxr-xr-x neo/neo           0 2012-02-06 11:22 ./
-rw-r--r-- neo/neo         144 2012-02-01 16:35 ./hello.lst
-rwxr-xr-x neo/neo         321 2012-01-08 21:25 ./test.d
-rw-r--r-- neo/neo         207 2012-02-01 15:57 ./d4py.d
-rwxr-xr-x neo/neo      919366 2012-02-01 16:28 ./hello
-rw-r--r-- neo/neo        6452 2012-02-01 16:28 ./hello.o
-rwxr--r-- neo/neo          80 2012-01-08 21:28 ./hello.d

				
				

6.1.6.7. dpkg-reconfigure

$ sudo dpkg-reconfigure package
			

所有未完成的配置步驟,主要是你在安裝過程中出現中斷後,可以使用下面命令補救。

$ sudo dpkg --configure -a			
			

6.1.7. Upgrading

升級到最新開發版

6.1.7.1. GUI

update-manager --devel-release
			

6.1.7.2. CLI

$ sudo do-release-upgrade

$ lsb_release -a
			

升級到最新開發版

vim /etc/update-manager/release-upgrades 檔案,把裡面的
Prompt=lts
改為
Prompt=normal
			
sudo do-release-upgrade -d
			

6.1.7.3. CDROM

$ sudo mount -t iso9660 -o loop ~/maverick-alternate-i386.iso /cdrom
$ sudo /cdrom/cdromupgrade
			

6.1.8. 製作.deb安裝包

6.1.8.1. checkinstall — Track installation of local software, and produce a binary manageable with your package management software.

$ tar xxx.tar.gz
$ cd xxx
$ ./configure
$ make			
			
$ sudo apt-get install checkinstall		
			

6.1.8.2. dh_make - prepare Debian packaging for an original source archive

http://www.debian.org/doc/manuals/maint-guide/index.zh-cn.html

http://www.debian.org/doc/manuals/maint-guide/

6.1.8.3. control

Architecture: any | amd64 | i386 The generated binary package is an architecture dependent one usually in a compiled language.

Architecture: all The generated binary package is an architecture independent one usually consisting of text, images, or scripts in an interpreted language.