如何用Firefox官网二进制文件构建Ubuntu的firefox.deb包?
嘿,这个需求我刚好折腾过!其实用预编译二进制包打包成.deb比从源码编译打包简单不少,下面我一步步给你说怎么做——你提到的那个Stack Overflow回答思路是对的,但针对Firefox的场景可以更细化:
首先得安装Ubuntu打包必备的工具,然后创建规范的工作目录结构:
- 安装依赖工具:
sudo apt install devscripts debhelper dpkg-dev - 创建分层工作目录(方便后续打包识别):
mkdir -p firefox-deb-build/firefox/usr/lib/firefox mkdir -p firefox-deb-build/firefox/usr/bin mkdir -p firefox-deb-build/debian
去Firefox官网下载你需要的版本(比如Developer Edition),然后把解压后的内容放到我们指定的目录里:
# 切换到目标目录 cd firefox-deb-build/firefox/usr/lib/firefox # 替换成你下载的包路径,--strip-components=1是为了去掉多余的外层文件夹 tar -xjf /path/to/your/downloaded/firefox-package.tar.bz2 --strip-components=1
为了让系统能像自带Firefox一样调用这个包,需要做软链接和桌面入口:
- 创建命令行软链接(命名成
firefox-dev避免和系统自带Firefox冲突):ln -s /usr/lib/firefox/firefox ../bin/firefox-dev - 创建桌面快捷方式(先建对应目录):
mkdir -p ../share/applications cat > ../share/applications/firefox-dev.desktop <<EOF [Desktop Entry] Name=Firefox Developer Edition Comment=Browse the web with developer tools Exec=firefox-dev %u Terminal=false Type=Application Icon=/usr/lib/firefox/browser/chrome/icons/default/default128.png Categories=Network;WebBrowser;Development; MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;video/webm;application/x-xpinstall; EOF
这部分是.deb打包的关键,所有包的元数据、打包规则都在debian目录里:
4.1 创建control文件(包的基本信息)
这个文件定义包名、版本、依赖、描述等:
cat > ../../debian/control <<EOF Source: firefox-dev Section: web Priority: optional Maintainer: Your Name <your-email@example.com> Build-Depends: debhelper-compat (= 13) Standards-Version: 4.5.1 Package: firefox-dev Architecture: amd64 Depends: \${shlibs:Depends}, \${misc:Depends}, libgtk-3-0, libdbus-glib-1-2, libxt6, libpulse0 Description: Firefox Developer Edition (Official Precompiled) This package uses Mozilla's official precompiled binaries instead of Ubuntu's patched source code. It includes all developer tools and the latest pre-release features. EOF
注意:Architecture要和你下载的二进制包架构匹配(比如amd64或i386);Depends可以参考Ubuntu官方Firefox包的依赖,或者用ldd /usr/lib/firefox/firefox | grep -v "not found"排查缺失的库。
4.2 创建rules文件(打包规则)
因为我们不需要编译,只需要复制文件,所以规则很简单:
cat > ../../debian/rules <<EOF #!/usr/bin/make -f %: dh \$@ override_dh_auto_build: # 无需编译,直接使用预编译二进制包 override_dh_auto_install: cp -r ../firefox/* debian/firefox-dev/ EOF
给文件加上执行权限:
chmod +x ../../debian/rules
4.3 创建compat文件(指定debhelper版本)
echo 13 > ../../debian/compat
4.4 创建copyright文件(版权声明)
主要声明Mozilla的版权和你的打包信息:
cat > ../../debian/copyright <<EOF Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Firefox Developer Edition Upstream-Contact: Mozilla Corporation Source: Mozilla Official Website Files: * Copyright: 2004-$(date +%Y) Mozilla Corporation License: MPL-2.0 License: MPL-2.0 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one from Mozilla's official website. EOF
4.5 创建changelog文件(版本变更记录)
用dch命令生成更规范:
cd ../../debian dch --create -v 1.0.0-1 --package firefox-dev "Initial package using official precompiled binaries"
执行后会打开编辑器,补充你的名字和邮箱,保存退出即可。
回到最上层的firefox-deb-build目录,执行打包命令:
cd ../.. debuild -us -uc
-us -uc参数表示不进行GPG签名(如果你没有签名密钥的话用这个,有密钥可以去掉)。执行完成后,上级目录会生成类似firefox-dev_1.0.0-1_amd64.deb的包文件。
安装测试一下:
sudo dpkg -i firefox-dev_1.0.0-1_amd64.deb
如果出现依赖缺失,执行sudo apt -f install自动补全即可。安装后你可以在应用菜单找到Firefox Developer Edition,或者直接在终端输入firefox-dev启动。
内容的提问来源于stack exchange,提问作者wheeler

