DevOps系列文章 : 使用dpkg命令打deb包

创建一个打包的目录,类似rpmbuild,这里创建了目录deb_build

bash 复制代码
mkdir  deb_build

目标

我有一个hello的二进制文件hello和源码hello.c, 准备安装到/opt/helloworld目录中

步骤

  1. 在deb_build目录创建一个文件夹用于存放我的安装文件
bash 复制代码
mkdir helloworld
  1. 在helloworld文件里创建DEBIAN文件夹和opt文件夹
  2. 在DEBIAN文件夹创建一个文件control
  3. 在opt文件夹新建一个helloworld文件夹,存放上hello和hello.c,如下
markdown 复制代码
$ tree helloworld/
helloworld/
├── DEBIAN
│   └── control
└── opt
    └── helloworld
        ├── hello
        └── hello.c
 
3 directories, 3 files

control文件类似rpm的spec文件,包含deb的包信息

只要把想安装的文件写到对应目录就可以安装到对应的系统目录

这里描述一个最简易的control文件

makefile 复制代码
Package: helloworld
Description: my deb test
Maintainer: username <user@mail.com>
Version: 0.1
Architecture: all
  1. 回到deb_build目录,执行dpkg -b helloworld即可在当前目录生成deb包
go 复制代码
$ dpkg -b helloworld
dpkg-deb: building package 'hello' in 'helloworld.deb'.

也可以指定dpkg -b hellorld hellorld-0.1-all.deb

vhdl 复制代码
$ dpkg -b helloworld helloworld-0.1-all.deb
dpkg-deb: building package 'helloworld' in 'helloworld-0.1-all.deb'.
  1. 观看deb包的信息
makefile 复制代码
查看包的字段信息:
$ dpkg -f helloworld-0.1-all.deb 
Package: helloworld
Description: my deb test
Maintainer: WangLin <email@163.com>
Version: 0.1
Architecture: all
查看deb包的详细信息:
$ dpkg -I helloworld-0.1-all.deb 
 new Debian package, version 2.0.
 size 2804 bytes: control archive=296 bytes.
     112 bytes,     5 lines      control              
 Package: helloworld
 Description: my deb test
 Maintainer: WangLin <email@163.com>
 Version: 0.1
 Architecture: all
查看deb包中的文件列表:
$ dpkg -c helloworld-0.1-all.deb
drwxrwxr-x wanglin/wanglin   0 2023-01-11 07:51 ./
drwxrwxr-x wanglin/wanglin   0 2023-01-11 07:54 ./opt/
drwxrwxr-x wanglin/wanglin   0 2023-01-11 07:54 ./opt/helloworld/
-rwxrwxr-x wanglin/wanglin 8304 2023-01-11 07:53 ./opt/helloworld/hello
-rw-rw-r-- wanglin/wanglin  100 2023-01-11 07:53 ./opt/helloworld/hello.c
  1. 安装打好的deb包
scss 复制代码
$ sudo dpkg -i helloworld-0.1-all.deb 
Selecting previously unselected package helloworld.
(Reading database ... 208913 files and directories currently installed.)
Preparing to unpack helloworld-0.1-all.deb ...
Unpacking helloworld (0.1) ...
Setting up helloworld (0.1) ...

此时/opt/helloworld/hello和hello.c 就安装在/opt/helloworld目录下了

检测安装效果

  • 查看包安装
sql 复制代码
$ dpkg -l helloworld
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  helloworld              0.1              all              my deb test
  • 检测/opt/helloworld目录
shell 复制代码
$ ls /opt/helloworld/
hello  hello.c

$ sudo /opt/helloworld/hello
hello world
  • 查看包的安装信息
avrasm 复制代码
$ dpkg -s helloworld
Package: helloworld
Status: install ok installed
Maintainer: WangLin <email@163.com>
Architecture: all
Version: 0.1
Description: my deb test
  • 查看/var/lib/dpkg/status中的记录
avrasm 复制代码
$ cat /var/lib/dpkg/status|grep helloworld -A 5
Package: helloworld
Status: install ok installed
Maintainer: WangLin <email@163.com>
Architecture: all
Version: 0.1
Description: my deb test
  • 查看deb包安装了哪些文件
bash 复制代码
$ dpkg -L helloworld
/.
/opt
/opt/helloworld
/opt/helloworld/hello
/opt/helloworld/hello.c
相关推荐
张人玉几秒前
LiveCharts WPF MVVM 图表开发笔记
大数据·分布式·wpf·livecharts
醉风塘1 分钟前
Oracle闪回技术深度解析:时间旅行者的数据库指南
数据库·oracle
qq_12498707534 分钟前
基于springboot的智能医院挂号系统(源码+论文+部署+安装)
java·人工智能·spring boot·后端·毕业设计
悲喜自渡7217 分钟前
Docker指令自存
java·docker·eureka
Dingdangr9 分钟前
基于Python的火焰识别系统设计与实现(含论文、开题报告及答辩PPT)
java·python·测试工具·安全
IT·陈寒9 分钟前
零配置、开箱即用:seekdb 如何成为 AI 时代的“全能嵌入式数据库”? ——基于 OceanBase seekdb 的实践体验与 AI 开发思考
数据库·人工智能·oceanbase
梁同学与Android10 分钟前
Android ---【经验篇】Fragment 生命周期高频面试题(附标准答案)
java·面试·fragment面试
速易达网络12 分钟前
Java Web + Vue 前后端分离跨域解决方案
java·开发语言
建投数据12 分钟前
建投数据再度获评国家级“高新技术企业”
大数据·人工智能
艺杯羹13 分钟前
Thymeleaf模板引擎:让Spring Boot页面开发更简单高效
java·spring boot·后端·thymeleadf