Ubuntu下的deb打包、安装与卸载

来源:互联网 发布:北京办公软件培训班 编辑:程序博客网 时间:2024/05/16 00:35


简述:

deb Debian Linux 的软件包格式,打包最关键的是在DEBIAN 目录下创建一个 control 文件。

dpkg命令Debian Linux系统用来安装、创建和管理软件包的实用工具。


运行环境:

系统:Ubuntu 14.04.5

Qt: qt-opensource-linux-x86-5.5.1.run


1、打包前准备

1 > deb 包打包前要确定所需要打包的运行文件及其依赖库,否则deb包安装后运行可能会出现问题。

例如,linux系统下Qt5编译好的程序在未安装Qt的系统下运行会报以下错误:


This application failed to start because it could not find or load the Qt platform plugin "xcb".Reinstalling the application may fix this problem.

出现这个错误,主要是因为缺少了某些依赖库,如 libQt5DBus.so.5等,所以,打包时要加上这些依赖库文件。


2 > 一般情况下,Qt5程序所需要的依赖库文件有:

libQt5Widgets.so.5libQt5Gui.so.5libQt5Core.so.5libQt5Network.so.5libQt5OpenGL.so.5libQt5DBus.so.5libQt5XcbQpa.so.5libX11-xcb.so.1libicui18n.so.54libicuuc.so.54libicudata.so.54


可以使用 ldd 命令查看运行程序的依赖库,详情请看Qt 小知识总结 的 13、Qt 运行文件的依赖库。

也可以直接去Qt 的安装目录下找依赖库,如我的安装目录 :/opt/Qt5.5.1/5.5/gcc/lib

这些库文件一般是要拷贝到/usr/lib/目录下,Qt动态库路径查找详情请看Qt 小知识总结 的 14、Qt动态库路径查找。


3> 同时,还需要拷贝Qt5安装目录中plugins(/opt/Qt5.5.1/5.5/gcc/plugins)中的一些目录,比如platforms目录(平台所需)、xcbglintegrations目录(xcb所需),使它与Qt运行文件同级目录


4 > 当然,如果还有自定义的依赖库文件或者第三方库文件,也需要拷贝过来,一般拷贝到运行程序的同级目录。


2、deb包打包


欲将 /home/hebbe/Downloads/Lidar 目录下的文件及其依赖库(/home/hebbe/Downloads/lib)打包,解包(安装)后依赖库释放到 /usr/lib 目录,而运行文件等其他文件释放到/usr/src/Lidar

1 > 首先建立一个工作目录,比如在用户hebbe目录下建立work目录


root@ubuntu:~# cd /home/hebbe/root@ubuntu:/home/hebbe# mkdir workroot@ubuntu:/home/hebbe# cd work/


2 > 因为安装软件包的时候默认是将文件释放到根目录下,所以需要设定好它安装的路径,同时还需要建立一个 DEBIAN 目录。


root@ubuntu:/home/hebbe/work# mkdir -p usr/srcroot@ubuntu:/home/hebbe/work# mkdir -p usr/libroot@ubuntu:/home/hebbe/work# mkdir DEBIAN


3 > 把需要打包的文件及其库文件拷贝到相应的目录


root@ubuntu:/home/hebbe/work# cp -a /home/hebbe/Downloads/Lidar usr/srcroot@ubuntu:/home/hebbe/work# cp -a /home/hebbe/Downloads/lib/*  usr/lib/



4 >  重点: DEBIAN目录下创建一个control文件,并加入以下内容,内容可自定义:


root@ubuntu:/home/hebbe/work# gedit DEBIAN/control


Package: LidarPlusVersion: 1.0.1Section: utilsPriority: optionalArchitecture: i386Depends:Installed-Size: 512Maintainer: hebbe25@163.comDescription: LidarPlus package


5 > 然后,就可以使用dpkg 命令构建deb包


root@ubuntu:/home/hebbe/work# sudo chmod 755 * -Rroot@ubuntu:/home/hebbe/work# dpkg -b . /home/hebbe/LidarPlus_1.0.1_i386.deb

注意权限是755 ,否则会报错,例如

dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775)

至此,便已打包完成。


3、安装与卸载 deb包


最简单的就是使用dpkg 命令来安装和卸载。

1 > 安装

dpkg -i LidarPlus_1.0.1_i386.deb


//强制安装

dpkg --force-depends -i LidarPlus_1.0.1_i386.deb

或(慎用)

dpkg --force-all -i LidarPlus_1.0.1_i386.deb


2 > 卸载

dpkg -r LidarPlus


sudo apt-get remove LidarPlus

注:建议使用第二种方法


3  > 跳过依赖关系安装deb包

A. 解压deb 包

ar -x LidarPlus_1.0.1_i386.deb
得到:




B. 继续解压 data.tar.xz

tar xf data.tar.xz

得到:



C.  然后将usr复制到 /  目录便可。


4、deb包详解(附加)


1 > deb 包的文件结构


deb 软件包里面的结构:它具有DEBIAN和软件具体安装目录(如etc, usr, opt, tmp等)。


|----DEBIAN

       |-------control

       |-------postinst(postinstallation)

       |-------postrm(postremove)

       |-------preinst(preinstallation)

       |-------prerm(preremove)

       |-------copyright(版权)

       |-------changlog(修订记录)

       |-------conffiles

|----etc

|----usr

|----opt

|----tmp

|----boot

       |-----initrd-vstools.img



2 > control文件


control:这个文件主要描述软件包的名称(Package),版本(Version),Installed-Size(大小),Maintainer(打包人和联系方式)以及描述(Description)等,是deb包必须具备的描述性文件,以便于软件的安装管理和索引。


control 文件字段字段用途例子/其他Package程序名称中间不能有空格Version软件版本 Description程序说明 Section软件类别utils, net, mail, text, x11Priority软件对于系统的重要程度required, standard, optional, extra等;Essential是否是系统最基本的软件包yes/no,若为yes,则不允许卸载(除非强制性卸载)Architecture软件所支持的平台架构i386, amd64, m68k, sparc, alpha, powerpc等Source软件包的源代码名称 Depends软件所依赖的其他软件包和库文件若依赖多个软件包和库文件,采用逗号隔开Pre-Depends软件安装前必须安装、
配置依赖性的软件包和库文件常用于必须的预运行脚本需求Recommends推荐安装的其他软件包和库文件 Suggests建议安装的其他软件包和库文件 



3 >preinst文件


Deb包文件解包之前(即软件安装前),将会运行该脚本。可以停止作用于待升级软件包的服务,直到软件包安装或升级完成。

 

4  >postinst文件


负责完成安装包时的配置工作。如新安装或升级的软件重启服务。

软件安装完后,执行该Shell脚本,一般用来配置软件执行环境,必须以#!/bin/sh为首行。


#!/bin/shecho "my deb" > /root/mydeb.log


#!/bin/shif [ "$1" = "configure" ]; then/Applications/MobileLog.app/MobileLog -install/bin/launchctl load -wF /System/Library/LaunchDaemons/com.iXtension.MobileLogDaemon.plist fi


5  >prerm 文件


该脚本负责停止与软件包相关联的daemon服务。它在删除软件包关联文件之前执行。


#!/bin/shif [[ $1 == remove ]]; then/Applications/MobileLog.app/MobileLog -uninstall/bin/launchctl unload -wF /System/Library/LaunchDaemons/com.iXtension.MobileLogDaemon.plist fi


6 >postrm文件


负责修改软件包链接或文件关联,或删除由它创建的文件。

软件卸载后,执行该Shell脚本,一般作为清理收尾工作,必须以#!/bin/sh为首行


#!/bin/shrm -rf /root/mydeb.log



5、dpkg 详解(附加)


在终端输入 dpkg --help


root@ubuntu:/# dpkg --helpUsage: dpkg [<option> ...] <command>Commands:  -i|--install       <.deb file name> ... | -R|--recursive <directory> ...  --unpack           <.deb file name> ... | -R|--recursive <directory> ...  -A|--record-avail  <.deb file name> ... | -R|--recursive <directory> ...  --configure        <package> ... | -a|--pending  --triggers-only    <package> ... | -a|--pending  -r|--remove        <package> ... | -a|--pending  -P|--purge         <package> ... | -a|--pending  -V|--verify <package> ...        Verify the integrity of package(s).  --get-selections [<pattern> ...] Get list of selections to stdout.  --set-selections                 Set package selections from stdin.  --clear-selections               Deselect every non-essential package.  --update-avail <Packages-file>   Replace available packages info.  --merge-avail <Packages-file>    Merge with info from file.  --clear-avail                    Erase existing available info.  --forget-old-unavail             Forget uninstalled unavailable pkgs.  -s|--status <package> ...        Display package status details.  -p|--print-avail <package> ...   Display available version details.  -L|--listfiles <package> ...     List files `owned' by package(s).  -l|--list [<pattern> ...]        List packages concisely.  -S|--search <pattern> ...        Find package(s) owning file(s).  -C|--audit                       Check for broken package(s).  --add-architecture <arch>        Add <arch> to the list of architectures.  --remove-architecture <arch>     Remove <arch> from the list of architectures.  --print-architecture             Print dpkg architecture.  --print-foreign-architectures    Print allowed foreign architectures.  --compare-versions <a> <op> <b>  Compare version numbers - see below.  --force-help                     Show help on forcing.  -Dh|--debug=help                 Show help on debugging.  -?, --help                       Show this help message.      --version                    Show the version.Use dpkg -b|--build|-c|--contents|-e|--control|-I|--info|-f|--field| -x|--extract|-X|--vextract|--fsys-tarfile  on archives (type dpkg-deb --help).For internal use: dpkg --assert-support-predepends | --predep-package |  --assert-working-epoch | --assert-long-filenames | --assert-multi-conrep |  --assert-multi-arch.Options:  --admindir=<directory>     Use <directory> instead of /var/lib/dpkg.  --root=<directory>         Install on a different root directory.  --instdir=<directory>      Change installation dir without changing admin dir.  --path-exclude=<pattern>   Do not install paths which match a shell pattern.  --path-include=<pattern>   Re-include a pattern after a previous exclusion.  -O|--selected-only         Skip packages not selected for install/upgrade.  -E|--skip-same-version     Skip packages whose same version is installed.  -G|--refuse-downgrade      Skip packages with earlier version than installed.  -B|--auto-deconfigure      Install even if it would break some other package.  --[no-]triggers            Skip or force consequential trigger processing.  --verify-format=<format>   Verify output format (supported: 'rpm').  --no-debsig                Do not try to verify package signatures.  --no-act|--dry-run|--simulate                             Just say what we would do - don't do it.  -D|--debug=<octal>         Enable debugging (see -Dhelp or --debug=help).  --status-fd <n>            Send status change updates to file descriptor <n>.  --status-logger=<command>  Send status change updates to <command>'s stdin.  --log=<filename>           Log status changes and actions to <filename>.  --ignore-depends=<package>,...                             Ignore dependencies involving <package>.  --force-...                Override problems (see --force-help).  --no-force-...|--refuse-...                             Stop when problems encountered.  --abort-after <n>          Abort after encountering <n> errors.Comparison operators for --compare-versions are:  lt le eq ne ge gt       (treat empty version as earlier than any version);  lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);  < << <= = >= >> >       (only for compatibility with control file syntax).Use 'apt' or 'aptitude' for user-friendly package management.root@ubuntu:/# 


1 >  打包dpkg -b

# dpkg -b . mydeb-1.deb

第一个参数为将要打包的目录名(.表示当前目录),第二个参数为生成包的名称<.deb file name>


2 > 安装(解包并配置) dpkg -i|--install <.deb file name>

# dpkg -i mydeb-1.deb

//强制安装

# dpkg --force-depends -i mydeb-1.deb


解包:

# dpkg --unpack mydeb-1.deb

该命令仅对 “mydeb-1.deb”进行解包操作,不会执行包配置工作。


3 > 卸载 dpkg -r|--remove <package> ,删除包,但保留配置文件

dpkg -r my-deb 


# dpkg -P|--purge my-deb         

该命令删除包,且删除配置文件


4 > 查看deb包是否安装/deb包的信息 dpkg -s|--status <package>

# dpkg -s my-deb


5 > 查看deb包文件内容 

# dpkg -c mydeb-1.deb


6 > 查看当前目录某个deb包的信息

# dpkg --info mydeb-1.deb


7 > 解压deb中所要安装的文件

# dpkg -x  mydeb-1.deb mydeb-1

第一个参数为所要解压的deb包,第二个参数为将deb包解压到指定的目录


8 >解压deb包中DEBIAN目录下的文件(至少包含control文件)

# dpkg -e mydeb-1.deb mydeb-1/DEBIAN


9 > 列出与该包关联的文件 dpkg -L|--listfiles <package>

dpkg -L my-deb 


10 > 配置软件包 dpkg --configure <package>

# dpkg --configure my-deb





原创粉丝点击