二进制源码打包成deb包的方法

前提

DEB是Debian的二进制安装包,但有时候我们从网站上只能得到源码包,这就需要自己编译安装了,但我们也可以把源码打包成DEB。

安装checkinstall

sudo apt-get install checkinstall

示例

已nginx源码为示例演示打包成deb的过程

  1. 环境查看
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal
# uname  -a
Linux liuym-virtual-machine 5.13.0-37-generic #42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  1. 下载nginx源码包
wget http://nginx.org/download/nginx-1.20.2.tar.gz
  1. 解压
tar -xf nginx-1.20.2.tar.gz
  1. 安装依赖包
 apt-get install libpcre3 libpcre3-dev
 apt-get install zlib1g-dev
  1. 编译
cd nginx-1.20.2
./configure --prefix=/usr/local/nginx
  1. Make构建
make
  1. 打包deb
# checkinstall -D

checkinstall 1.6.3, Copyright 2010 Felipe Eduardo Sanchez Diaz Duran
本软件以 GNU GPL 版权协议颁布



*****************************************
**** Debian package creation selected ***
*****************************************

软件包将用下面的值来创建:

0 -  Maintainer: [ root@liuym-virtual-machine ]
1 -  Summary: [ nginx ]
2 -  Name:    [ nginx ]
3 -  Version: [ 1.20.2 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ nginx-1.20.2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [  ]
12 - Suggests: [  ]
13 - Provides: [ nginx ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

输入一个数字来改变它们,或按回车键继续:

提示:使用以上默认控制文件control,如果需要修改则输入数字修改,否则直接回车使用默认配置即可
打包过程如下

Installing with make install...

=============================== 安装结果 =================================
make -f objs/Makefile install
make[1]: 进入目录“/root/nginx-1.20.2”
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
        || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
        || mv '/usr/local/nginx/sbin/nginx' \
                '/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
        || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
        || cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
        || cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
        '/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
        || cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
        || cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
        '/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
        || cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
        '/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
        || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
make[1]: 离开目录“/root/nginx-1.20.2”

=============================== 安装成功 =================================

Copying documentation directory...
./
./README
./CHANGES
./LICENSE

把文件拷贝到临时目录……OK

Stripping ELF binaries and libraries...OK

压缩 man 手册页……OK

创建文件列表……OK

创建 Debian 包……OK

安装 Debian 包……OK

删除临时文件……OK

删除临时目录……OK


**********************************************************************

 Done. The new package has been installed and saved to

 /root/nginx-1.20.2/nginx_1.20.2-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r nginx

**********************************************************************

会在当前目录生成deb文件

nginx_1.20.2-1_amd64.deb

拷贝该deb文件即可在其他主机安装(本机已在打包过程中安装)

dpkg -i nginx_1.20.2-1_amd64.deb
posted @ 2022-04-06 16:40  minseo  阅读(1241)  评论(0编辑  收藏  举报