获取 Debian 源码主要有几种常见方式,取决于你是想获取 Debian 系统本身的源码,还是获取某个软件包(package)的源码。下面按常见场景说明。
apt source(推荐)这是最简单、最标准的方法。
编辑源列表文件:
sudo nano /etc/apt/sources.list
确保有 deb-src 开头的行,例如:
deb-src http://deb.debian.org/debian bookworm main
把
bookworm换成你的版本(如bullseye、trixie)。
更新索引:
sudo apt update
sudo apt install dpkg-dev
apt source 包名
示例:
apt source vim
执行后会在当前目录生成:
.dsc.orig.tar.*.debian.tar.*✅ 优点
访问:
https://packages.debian.org/
搜索软件包 → 进入版本页 → 下载:
.dsc.orig.tar.*.debian.tar.*然后使用:
dpkg-source -x xxx.dsc
Debian 不是单一源码仓库,而是由大量软件包组成。
如果你想研究:
可参考:
https://cdimage.debian.org/
ISO 本身不包含源码,源码需要从各软件包获取。
apt source linux
或指定版本:
apt source linux-image-6.1.0-amd64
deb-src 与 dget(开发者常用)dget(来源于 dsc 文件)sudo apt install devscripts
dget https://example.com/package.dsc
很多 Debian 软件包使用 Git 维护。
salsa.debian.orggit clone https://salsa.debian.org/debian/包名.git
示例:
git clone https://salsa.debian.org/debian/vim.git
| 目的 | 推荐方式 |
|---|---|
| 查看某个软件如何打包 | apt source 包名 |
| 修改并重新编译软件 | apt source + dpkg-buildpackage |
| 学习 Debian 补丁机制 | apt source |
| 获取最新 Debian 打包工作 | git clone from salsa |
| 编译内核 | apt source linux |
.orig.tar.* 中debian/patches/如果你愿意,可以告诉我:
我可以给你更精确的命令和示例。