Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

第 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. yum - Yellowdog Updater Modified 包管理
6.3.1. Yum Resource & Yum Mirror
6.3.1.1. fastestmirror
6.3.1.2. Fedora resource
6.3.1.2.1. Fedora 5.4
6.3.1.2.2. Fedora 6.x
6.3.1.2.3. Fedora 7.x
6.3.1.3. rpmforge-release
6.3.1.3.1. CentOS 5.x
6.3.1.3.2. CentOS 6.x
6.3.1.3.3. CentALT
6.3.1.4. atomic
6.3.1.5. famillecollet
6.3.1.6. rpmfind.net
6.3.1.7. pkgs.org
6.3.1.8. China Resource
6.3.1.9. 制作本地共享源
6.3.2. yum - Yellowdog Updater Modified
6.3.2.1. YUM 源管理
6.3.2.2. install
6.3.2.3. localinstall
6.3.2.4. list
6.3.2.5. search
6.3.2.6. update / upgrade
6.3.2.7. remove
6.3.2.8. installed
6.3.2.9. group
6.3.2.9.1. grouplist
6.3.2.9.2. groupinfo
6.3.2.9.3. groupinstall
6.3.2.9.4. groupremove
6.3.2.10. 查看包的依赖关系
6.3.2.11. provides / whatprovides
6.3.3. rpm - RPM Package Manager
6.3.3.1. install/upgrade/remove
6.3.3.1.1. --prefix
6.3.3.2. query
6.3.3.2.1. changelog 查看变更日志
6.3.4. rpmbuild - Build RPM Package(s)
6.3.4.1. RPM_directory_macros
6.3.4.2. --define 专递模板变量
6.3.4.3. defattr
6.3.4.4. GPG 签名
6.3.4.5. 使用 CMake3 编译并创建RPM包
6.3.4.6. FAQ

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.