前提
DEB是Debian的二進制安裝包,但有時候我們從網站上只能得到源碼包,這就需要自己編譯安裝了,但我們也可以把源碼打包成DEB。
安裝checkinstall
sudo apt-get install checkinstall
示例
已nginx源碼為示例演示打包成deb的過程
- 環境查看
# 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
- 下載nginx源碼包
wget http://nginx.org/download/nginx-1.20.2.tar.gz
- 解壓
tar -xf nginx-1.20.2.tar.gz
- 安裝依賴包
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g-dev
- 編譯
cd nginx-1.20.2
./configure --prefix=/usr/local/nginx
- Make構建
make
- 打包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
