如何获取和修改通过 apt-get 安装的软件包的源代码?

myu*_*uf3 188 apt

我假设通过安装的所有应用程序apt-get都是开源的;但是对于那些以这种方式可用的应用程序,我在哪里可以获得这些应用程序的源代码并更新它们?

我有几个我经常使用的应用程序不再被积极开发,我想添加功能。我从哪里获得更新这些应用程序的权利?

在这种情况下,我指的是helanzb

Isa*_*iah 206

使用命令apt-get source <package>(不要使用 sudo)来下载包的源代码。

来自man apt-get

   source
       source causes apt-get to fetch source packages. APT will examine the
       available packages to decide which source package to fetch. It will then
       find and download into the current directory the newest available version of
       that source package while respect the default release, set with the option
       APT::Default-Release, the -t option or per package with the pkg/release
       syntax, if possible.

       Source packages are tracked separately from binary packages via deb-src type
       lines in the sources.list(5) file. This means that you will need to add such
       a line for each repository you want to get sources from. If you don't do
       this you will properly get another (newer, older or none) source version
       than the one you have installed or could install.

       If the --compile option is specified then the package will be compiled to a
       binary .deb using dpkg-buildpackage, if --download-only is specified then
       the source package will not be unpacked.

       A specific source version can be retrieved by postfixing the source name
       with an equals and then the version to fetch, similar to the mechanism used
       for the package files. This enables exact matching of the source package
       name and version, implicitly enabling the APT::Get::Only-Source option.

       Note that source packages are not tracked like binary packages, they exist
       only in the current directory and are similar to downloading source tar
       balls.
Run Code Online (Sandbox Code Playgroud)

要从源代码构建包,首先安装构建依赖项:

sudo apt-get build-dep <package>  
Run Code Online (Sandbox Code Playgroud)

然后用于dpkg-buildpackage创建.deb文件。来自APT 和 Dpkg 快速参考表

dpkg-buildpackage从 Debian 源代码树构建 Debian 软件包。您必须在源代码树的主目录中才能使其工作。示例用法:

 dpkg-buildpackage -rfakeroot -uc -b
Run Code Online (Sandbox Code Playgroud)

其中-rfakeroot指示它使用 fakeroot 程序来模拟 root 权限(出于所有权目的),-uc代表“不要对变更日志进行加密签名”,-b代表“仅构建二进制包”

在终端中,cd进入包含包源(例如~/code/hellanzb-0.13)的目录并运行以下命令:

dpkg-buildpackage -rfakeroot -uc -b
Run Code Online (Sandbox Code Playgroud)

如果构建成功,则.deb在父
目录中会有一个文件(例如~/code/hellanzb_0.13-6.1_all.deb)。

  • 如果您不想使用 apt-get 源(例如在构建从其他发行版获取的包时),请下载 3 个源文件并使用“dpkg-source -x [fine].dsc”来提取文件并应用dpkg-buildpackage 之前的差异。(http://ftp.debian.org/debian/doc/source-unpack.txt) (2认同)
  • 尝试执行此操作时出现错误“E:您必须将 'deb-src' URI 放入您的 resources.list”。我必须按照此处的说明进行修复:https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list (2认同)

ter*_*don 26

通常,您可以按照以下步骤获取已安装包的源代码:

  1. 启用源存储库。打开仪表板(左上角按钮)并搜索sources. 这应该会启动Software & Updates程序,运行它并确保您选择了“源代码”选项:

    在此处输入图片说明

  2. 打开终端并运行以下命令:

     apt-get source vlc
    
    Run Code Online (Sandbox Code Playgroud)

这会将 vlc 的源下载到您的当前目录,您可以在闲暇时查看它们。

当然,在 的情况下vlc,您也可以直接从 videolan.org 网站下载:https ://www.videolan.org/vlc/download-sources.html

  • 您不需要将 sudo 与“apt-get source”一起使用 (2认同)

kal*_*sin 19

您可以apt-get source --compile直接使用:

sudo apt-get build-dep <package>
sudo apt-get source --compile <package>
Run Code Online (Sandbox Code Playgroud)

为我工作。.deb 在您运行命令的目录中结束。

  • 也为我工作,谢谢。只有一个额外的细节:您可以使用 `sudo dpkg -i &lt;package&gt;.deb` 安装 .deb (9认同)

Cir*_*郝海东 7

hello包的最小示例

所有这些以及更多内容都在:https : //www.debian.org/doc/manuals/maint-guide/build.en.html

首先让我们获取一个示例包来修改源代码:

sudo apt-get install hello
hello
Run Code Online (Sandbox Code Playgroud)

输出:

Hello, world!
Run Code Online (Sandbox Code Playgroud)

现在让我们破解它。获取源码:

apt-get source hello
cd hello-*
Run Code Online (Sandbox Code Playgroud)

并打开:

vim src/hello.c
Run Code Online (Sandbox Code Playgroud)

并将消息修改为:

Hello, world hacked!
Run Code Online (Sandbox Code Playgroud)

然后对测试执行相同操作,否则烦人的测试将开始失败:

vim tests/greeting-1
Run Code Online (Sandbox Code Playgroud)

然后重建:

sudo apt-get install devscripts
sudo apt-get build-dep hello
debuild -b -uc -us
Run Code Online (Sandbox Code Playgroud)

在输出接近尾声时,它说:

dpkg-deb: building package 'hello' in '../hello_2.10-1build1_amd64.deb'.
Run Code Online (Sandbox Code Playgroud)

所以它在父目录上创建了 .deb ,这怎么敢。所以最后我们安装并测试修改后的包:

sudo dpkg -i ../hello_2.10-1build1_amd64.deb
hello
Run Code Online (Sandbox Code Playgroud)

就这样,它输出新消息:

Hello, world hacked!
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 18.04 上测试。

bzr答案

TODO:这个停止工作在Ubuntu 16.04 Xenial,与失败:bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/hello/".bzr branch lp:ubuntu/wily/hello工作并bzr branch lp:ubuntu/xenial/hello再次失败。出于某种原因https://code.launchpad.net/ubuntu/+source/hello不显示 Xenial:https ://web.archive.org/save/https://code.launchpad.net/ubuntu/+source /你好

正如在https://askubuntu.com/a/81889/52975 中提到的,还有一种特定于 Ubuntu 的方法与bzr.

获取最新版本:

bzr branch lp:ubuntu/hello
Run Code Online (Sandbox Code Playgroud)

具体版本:

bzr branch lp:ubuntu/trusty/hello
Run Code Online (Sandbox Code Playgroud)

您还可以使用pull-lp-source

sudo apt-get install ubuntu-dev-tools
pull-lp-source hello
Run Code Online (Sandbox Code Playgroud)

然后你就可以编辑它了:

cd hello
vim some_file
Run Code Online (Sandbox Code Playgroud)

重建它:

dch -i 
debcommit
bzr bd -- -b -us -uc
Run Code Online (Sandbox Code Playgroud)

并安装它:

sudo dpkg -i ../hello.deb
Run Code Online (Sandbox Code Playgroud)

Ubuntu的包装引导是一个很好的信息源。