如何安裝套件

前提

以移除「hello」這個套件為例。

安裝範例套件

安裝「hello」這個套件

$ sudo apt-get install hello

顯示

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  hello
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/28.1 kB of archives.
After this operation, 111 kB of additional disk space will be used.
Selecting previously unselected package hello.
(Reading database ... 947421 files and directories currently installed.)
Preparing to unpack .../archives/hello_2.8-4_amd64.deb ...
Unpacking hello (2.8-4) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up hello (2.8-4) ...

就會安裝「hello」這個套件了。

查看一些相關的訊息,驗證一下,是否安裝。

執行

$ dpkg -l hello

顯示

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             Architecture        Description
+++-============================-===================-===================-==============================================================
ii  hello                        2.8-4               amd64               The classic greeting, and a good example

觀看「hello」這個套件,安裝了那些檔案到系統。

$ dpkg -L hello

顯示

/.
/usr
/usr/bin
/usr/bin/hello
/usr/share
/usr/share/info
/usr/share/info/hello.info.gz
/usr/share/doc
/usr/share/doc/hello
/usr/share/doc/hello/NEWS
/usr/share/doc/hello/copyright
/usr/share/doc/hello/changelog.Debian.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/hello.1.gz

觀看「hello」這個套件,有那些「Control File」和「Maintainer Script」。

$ ls /var/lib/dpkg/info/hello* -1

顯示

/var/lib/dpkg/info/hello.list
/var/lib/dpkg/info/hello.md5sums

執行

$ ls /var/cache/apt/archives/hello*

顯示

/var/cache/apt/archives/hello_2.8-4_amd64.deb

執行

$ dpkg -s hello

顯示

Package: hello
Status: install ok installed
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

觀看「/var/lib/dpkg/status」

$ grep 'Package: hello' /var/lib/dpkg/status -A 18

顯示

Package: hello
Status: install ok installed
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

觀看「/var/lib/dpkg/available」

$ grep 'Package: hello' /var/lib/dpkg/available -A 18

顯示

Package: hello
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Size: 28148
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

dpkg 移除

執行

$ sudo dpkg -r hello

或是

$ sudo dpkg --remove hello

來移除「hello」這個套件

會顯示

(Reading database ... 947427 files and directories currently installed.)
Removing hello (2.8-4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...

就會把「hello」這個套件移除了。

另外有一種「dpkg -P」或「dpkg --purge」的移除方式,另外一篇來討論。

查看一些相關的訊息,驗證一下,是否移除。

執行

$ dpkg -l hello

顯示

dpkg-query: no packages found matching hello

觀看「hello」這個套件,安裝了那些檔案到系統,是否還存在。

$ dpkg -L hello

顯示

dpkg-query: package 'hello' is not installed
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents

觀看「hello」這個套件,那些「Control File」和「Maintainer Script」,是否還存在。

$ ls /var/lib/dpkg/info/hello* -1

顯示

ls: cannot access /var/lib/dpkg/info/hello*: No such file or directory

執行

$ ls /var/cache/apt/archives/hello*

顯示

/var/cache/apt/archives/hello_2.8-4_amd64.deb

執行

$ dpkg -s hello

顯示

dpkg-query: package 'hello' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

觀看「/var/lib/dpkg/status」

$ grep 'Package: hello' /var/lib/dpkg/status -A 18

沒有顯示訊息。

觀看「/var/lib/dpkg/available」

$ grep 'Package: hello' /var/lib/dpkg/available -A 18

顯示

Package: hello
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Size: 28148
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

apt-get 移除

執行

$ sudo apt-get remove hello

顯示

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  hello
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 111 kB disk space will be freed.
Do you want to continue? [Y/n]

按下「Enter」

顯示

(Reading database ... 947427 files and directories currently installed.)
Removing hello (2.8-4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...

aptitude 移除

執行

$ sudo aptitude remove hello

顯示

The following packages will be REMOVED:
  hello
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 111 kB will be freed.
(Reading database ... 947386 files and directories currently installed.)
Removing hello (2.8-4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...

select 移除

產生要移除的套件列表檔案「list.txt」

$ echo 'hello deinstall' > list.txt

確認觀看「list.txt」內容

$ cat list.txt

顯示

hello deinstall

設定要刪除

$ sudo dpkg --set-selections < list.txt

執行

$ dpkg --get-selections | grep hello

顯示

hello                                           deinstall

執行

$ dpkg -l hello

顯示

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             Architecture        Description
+++-============================-===================-===================-==============================================================
ri  hello                        2.8-4               amd64               The classic greeting, and a good example

執行

$ dpkg -s hello

顯示

Package: hello
Status: deinstall ok installed
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

觀看「/var/lib/dpkg/status」

$ grep 'Package: hello' /var/lib/dpkg/status -A 18

顯示

Package: hello
Status: deinstall ok installed
Priority: optional
Section: devel
Installed-Size: 108
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.8-4
Depends: libc6 (>= 2.14), dpkg (>= 1.15.4) | install-info
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 .
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
Original-Maintainer: Santiago Vila <sanvila@debian.org>
Homepage: http://www.gnu.org/software/hello/

注意「Status」那一行

Status: deinstall ok installed

這時候只要執行

$ sudo dpkg -r -a

或是

$ sudo dpkg --remove --pending

顯示

(Reading database ... 947386 files and directories currently installed.)
Removing hello (2.8-4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...

就會把「hello」這個套件移除了。

或是當你執行完「set-selections」。

執行下面的指令

$ sudo apt-get dselect-upgrade

就會出現下面的訊息

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  hello
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 111 kB disk space will be freed.
Do you want to continue? [Y/n]

按下「Enter」

就會顯示

(Reading database ... 947386 files and directories currently installed.)
Removing hello (2.8-4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...

一樣會把「hello」這個套件移除。

或是當你執行完「set-selections」。

執行下面的指令

$ sudo aptitude install

一樣會把「hello」這個套件移除。

$ man dpkg

可以看到其中一段

   Package selection states
       install
              The package is selected for installation.

       hold   A  package  marked  to be on hold is not handled by dpkg, unless
              forced to do that with option --force-hold.

       deinstall
              The package is selected for  deinstallation  (i.e.  we  want  to
              remove all files, except configuration files).

       purge  The  package  is  selected  to be purged (i.e. we want to remove
              everything from system directories, even configuration files).

強制移除

從「這篇」討論中和參考「這篇」,學到。

當有卡住的情況時,可以執行下面的指令來強制移除。 主要是加入「--force-depends」這個參數。

$ sudo dpkg -r --force-depends hello

相關文件說明

$ man dpkg

可以看到其中一段

       -?, --help
              Display a brief help message.

       --force-help
              Give help about the --force-thing options.

然後查詢「forece-thing」,就可以看到

       --force-things, --no-force-things, --refuse-things

...略...

              depends: Turn all dependency problems into warnings.

...略...

執行

$ dpkg --help

可以看到

Options:

...略...

  --force-...                Override problems (see --force-help).

...略...

執行

$ dpkg --force-help

則是可以看到

dpkg forcing options - control behaviour when problems found:
  warn but continue:  --force-<thing>,<thing>,...
  stop with error:    --refuse-<thing>,<thing>,... | --no-force-<thing>,...
 Forcing things:
  [!] all                Set all force options
  [*] downgrade          Replace a package with a lower version
      configure-any      Configure any package which may help this one
      hold               Process incidental packages even when on hold
      not-root           Try to (de)install things even when not root
      bad-path           PATH is missing important programs, problems likely
      bad-verify         Install a package even if it fails authenticity check
      bad-version        Process even packages with wrong versions
      overwrite          Overwrite a file from one package with another
      overwrite-diverted Overwrite a diverted file with an undiverted version
  [!] overwrite-dir      Overwrite one package's directory with another's file
  [!] unsafe-io          Do not perform safe I/O operations when unpacking
  [!] confnew            Always use the new config files, don't prompt
  [!] confold            Always use the old config files, don't prompt
  [!] confdef            Use the default option for new config files if one
                         is available, don't prompt. If no default can be found,
                         you will be prompted unless one of the confold or
                         confnew options is also given
  [!] confmiss           Always install missing config files
  [!] confask            Offer to replace config files with no new versions
  [!] architecture       Process even packages with wrong or no architecture
  [!] breaks             Install even if it would break another package
  [!] conflicts          Allow installation of conflicting packages
  [!] depends            Turn all dependency problems into warnings
  [!] depends-version    Turn dependency version problems into warnings
  [!] remove-reinstreq   Remove packages which require installation
  [!] remove-essential   Remove an essential package

WARNING - use of options marked [!] can seriously damage your installation.
Forcing options marked [*] are enabled by default.