Xiaopei's DokuWiki

These are the good times in your life,
so put on a smile and it'll be alright

User Tools

Site Tools


it:linux:package

软件管理

tips

  1. debian 有个包叫 popularity-contest, 可以反馈系统中哪些包用得最多(grep -r MAILTO /etc/cron* 发现的)
  2. 由源代码安装软件时, 可能遇到 /usr/bin/ld: cannot find -l*** 的问题, 其中 *** 表示 lib***, 即可能某些库没装, 可 aptitude search lib***-devel, 安装后应正常
  3. 由源代码安装软件时, 在 ./configuremake 后, 可用 sudo checkinstall, 填写一些信息后, 既能安装(等同 sudo make install), 又能同时打包

build-essential (essential adj.基本的) 编译所必需的软件包列表

Depends: libc6-dev | libc-dev, gcc (>= 4:4.4.3), g++ (>= 4:4.4.3), make, dpkg-dev (>= 1.13.5)

This package contains an informational list of packages which are considered essential for building Debian packages. This package also depends on the packages on that list, to make it easy to have the build-essential packages installed.

apt-cacher

用来架设 apt 服务器, 但非完整镜相, 而是保留 apt 缓存

自动更新

ubuntu 的定时无人值守安装可能出问题 hang,开可能会有问题

Ubuntu 默认会自动检查并安装安全更新

# unattended-upgrades 是已安装的
genee@jiangnan:~$ dpkg -l unattended-upgrades
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
+++-======================-======================-============================================================
ii  unattended-upgrades    0.76                   automatic installation of security upgrades

# ...且是会每天运行的
genee@jiangnan:~$ head /etc/apt/apt.conf.d/20auto-upgrades 
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

# ...运行时安装(且仅安装) security
genee@jiangnan:~$ head /etc/apt/apt.conf.d/50unattended-upgrades
// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {
	"${distro_id}:${distro_codename}-security";
//	"${distro_id}:${distro_codename}-updates";
//	"${distro_id}:${distro_codename}-proposed";
//	"${distro_id}:${distro_codename}-backports";
};

debian 下安装 rpm 包

use alien

alien -i oracle-instantclient-basic*.rpm
alien -i oracle-instantclient-sqlplus*.rpm
alien -i oracle-instantclient-devel*.rpm

列出所有软件包(并在另一台电脑重装)

# 老电脑
$ sudo dpkg --get-selections > packages.txt
# 新电脑
$ sudo dpkg --set-selections < packages.txt && sudo apt-get -u dselect-upgrade

apt - How to list all installed packages? - Ask Ubuntu

dpkg

TODO: read dpkg详解

dpkg - package manager for Debian.

dpkg can also be used as a front-end to dpkg-deb(Debian package archive (.deb) manipulation tool)

安装

-i, –install is for installing the package. If –recursive or -R option is specified, package_file must refer to a directory instead.

Installation consists of the following steps:

  1. Extract the control files of the new package.
  2. If another version of the same package was installed before the new installation, execute prerm script of the old package.
  3. Run preinst script, if provided by the package.
  4. Unpack the new files, and at the same time back up the old files, so that if something goes wrong, they can be restored.
  5. If another version of the same package was installed before the new installation, execute the postrm script of the old package. Note that this script is executed after the preinst script of the new package, because new files are written at the same time old files are removed.
  6. Configure the package. See –configure for detailed information about how this is done. Configuring consists of the following steps:
    1. Unpack the conffiles, and at the same time back up the old conffiles, so that they can be restored if something goes wrong.
    2. Run postinst script, if provided by the package.
$ sudo dpkg -i dpkgtest_1.deb 
Selecting previously deselected package dpkgtest.
(Reading database ... 66730 files and directories currently installed.)
Unpacking dpkgtest (from dpkgtest_1.deb) ...
v1 preinst
Setting up dpkgtest (1) ...
v1 postinst
 
$ sudo dpkg -i dpkgtest_2.deb 
(Reading database ... 66730 files and directories currently installed.)
Preparing to replace dpkgtest 1 (using dpkgtest_2.deb) ...
v1 prerm
v2 preinst
Unpacking replacement dpkgtest ...
v1 postrm
Setting up dpkgtest (2) ...
v2 postinst

已安装 package 的 pre|post 脚本位于 /var/lib/dpkg/info/package_name.{pre|post}{inst|rm}

如果将安装一半的包强制 kill 了,可能造成 dpkg 状态混乱无法再使用,此时可 rm /var/cache/debconf/* 删除状态缓存以解决

打包

control

rules

conffiles

概念

Everything you need to know about conffiles: configuration files managed by dpkg, 讲了什么是 conffiles, 及安装时如何对 conffiles 选项自动选择.

  1. Dpkg keeps a checksum of the last installed version of configuration file.
  2. When it must install a new version, it calculates the checksum of the currently installed file and if it doesn’t match anymore, it knows that the user has edited the file.
  3. In that case, instead of overwriting the configuration file, it asks the user what to do.
  4. 当有新配置时, 若旧配置被用户修改过就会提示(用户没改过则直接覆盖). They look like this:
Configuration file `/etc/bash.bashrc'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** bash.bashrc (Y/I/N/O/D/Z) [default=N] ? 
打包

包的 conffiles 必须在 DEBIAN/conffiles 中指定:

php5-fpm.fakeroot/DEBIAN/conffiles
/etc/init.d/php5-fpm
/etc/php5/fpm/pool.d/www.conf
/etc/php5/fpm/php-fpm.conf
安装
# dpkg --version
1.16.1.2 (amd64)

查看某已安装的包有哪些文件:

dpkg-query -L <package_name>

实验而来的 conffiles 规则:

  1. 若用户未改过, 以包中为准
  2. 若新旧版本 包中 conffiles 相同, 且用户改过(包括删除), 则安装中默认会按用户配置, 忽略包配置(且无包配置备份); 此时若想还原包配置, 可用 –force-confask.
  3. 若新旧版本 包中 conffiles 不同1), 且用户改过(包括删除), 则安装中会提示. 选择 Y or I 后会用新配置并备份旧配置(foo.dpkg-old), 选择 N 后会用旧配置并备份新配置(foo.dpkg-dist).

自动使用旧配置做版本升级:

$ apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

由此设计的 LIMS2 打包/安装机制

解包

$dpkg -X foo.deb foo
$dpkg -e foo.deb foo/DEBIAN

使用ar foo.deb可解压开deb包。解压出的内容有control.tar.gz、data.tar.gz和debian-binary。debian-binary说明了deb包的版本。

另一种选择 fpm

修改 profile (如修改 PATH, 增加其他环境变量)

Adding a directory to the path of a user or all users would seem trivial, but in fact it isn't. The best place to add a directory to the path of a single user is to modify that user's .bash_profile file. To add it to all users except user root, add it to /etc/profile or /etc/profile.d/foo.sh. To also add it to the path of user root, add it to root's .bash_profile file.

Adding a Directory to the Path

参考

APT

只下载, 不安装

下载某一特定版本的软件

$ apt-get download ibus=1.3.*

禁止某软件更新

$ aptitude hold ibus
# ibus 1.4 在 emacs 中不可用

lauchpad.net & PPA

Launchpad(发射台)是Canonical有限公司所架设的网站,是一个提供维护、支援或连络Ubuntu开发者的平台。其中Launchpad提供了线上翻译软件的功能,你可以自由的参与Ubuntu或相关自由软件的开发或翻译工作。而你也可以利用该网站的回报机制来回报相关软件的Bug,或者进一步提供建议。

Personal_Package_Archive for Ubuntu — allows one to upload Ubuntu source packages to be built and published as an aptitude repository by Launchpad.

How do I use software from a PPA?

  1. $ sudo apt-get install python-software-properties
  2. 13.04 后是 apt-get install software-properties-common
  3. find PPA like ppa:gwibber-daily/ppa
  4. $ sudo add-apt-repository ppa:user/ppa-name
  5. $ sudo apt-get update
  6. $ sudo apt-get install xxx

手动添加

  1. 增加 .list, 树莓 pi, Raspberry Pi, bbb, raspbian 可使用 12.04 precise 的源 (参考: Adding PPA’s to Raspbian | kroq-gar78's webweb);
  2. 增加 key: apt-key adv –keyserver keyserver.ubuntu.com –recv-keys C7917B12, 最后一串数是 Technical details about this PPA 的 Signing key 的 1024R/C7917B12 的后半部分;

do-release-upgrade 时可能遇到的问题

LTS: 12.04 都发布了, 10.04 却还不能 do-release-upgrade

原因是针对 LTS, Ubuntu 官方建议用户等到 the first point release (约 3 个月后发布)再升级. 参考

Can't update, Some index files failed to download.

把 /var/lib/apt/lists/ 下的文件全删了(保留目录), 再 aptitude update

Could not perform immediate configuration on ...

需按以下步骤操作:

# apt-get install -o APT::Immediate-Configure=false -f apt python-minimal
# apt-get -f install
# apt-get dist-upgrade

Bug #990740 “upgrading from lucid to precise fails” : Bugs : “python-defaults” package : Ubuntu

Cache has broken packages, exiting

问题:

Subject: Cron <root@sub> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

/etc/cron.daily/apt:
Cache has broken packages, exiting

解决:

$ sudo apt-get clean

依赖地狱

Dependency hell

  • 查看安装时的依赖可使用: sudo dpkg -i * 2>&1
  • 查看本机 Ubuntu 版本可使用 cat /etc/issue 或更详细的 lsb_release -a
    $ whatis lsb_release
    lsb_release (1)      - print distribution-specific information

/etc/cron.daily/apt: Cache has broken packages, exiting 和 /boot is using 100.0%

某服务器经常报该错误. 根据 launchpad.net : Ubuntu : “apt” package : Bug #482200 的 #2, 登陆服务器使用 $ sudo apt-get clean, 但下次 cron 时又会报改错.

又发现, 登陆该服务器时 motd 有 ⇒ /boot is using 100.0% of 227MB 的警告. 该服务器是客户提供, 客户安装操作系统时对 /boot 空间分得不足.

$ df -h
/dev/sda1                   228M  228M     0 100% /boot

对该警告, 尝试 aptitude install -f 安装最新的 kernel, 并期望会删除 /boot 中的老 kernel 来解决. 但最后安装不了, 报错 failed in write on buffer copy for backend dpkg-deb during `./boot/some_package': No space left on device. No apport report written because the error message indicates a disk full error, 看来无法自动清理 /boot.

而上述 bug 的 #6 说到由于某个包没安成(依赖问题), 会让 cron 不断报改错. 这样就将这两个错连到一起了: 由于 /boot 被占满, 某些更新安装不上, 所以导致 cron.daily/apt 总在报 broken package.

删除旧 kernel 可在升级 kernel 前, 或升级 kernel 并重启后, 使用以下命令:

$ sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")

升级所有程序可使用:

$ sudo aptitude safe-upgrade
1)
包括 conffiles 指定的文件内容修改 和 conffiles 中新增
it/linux/package.txt · Last modified: 2017/09/26 21:26 by admin