AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 28372
Accepted
myusuf3
myusuf3
Asked: 2011-02-28 14:52:17 +0800 CST2011-02-28 14:52:17 +0800 CST 2011-02-28 14:52:17 +0800 CST

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

  • 772

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

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

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

apt
  • 5 5 个回答
  • 202288 Views

5 个回答

  • Voted
  1. Best Answer
    Isaiah
    2011-02-28T15:01:00+08:002011-02-28T15:01:00+08:00

    使用命令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.
    

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

    sudo apt-get build-dep <package>  
    

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

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

     dpkg-buildpackage -rfakeroot -uc -b
    

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

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

    dpkg-buildpackage -rfakeroot -uc -b
    

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

    • 210
  2. terdon
    2014-03-19T12:03:56+08:002014-03-19T12:03:56+08:00

    通常,您可以按照以下过程获取已安装软件包的来源:

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

      在此处输入图像描述

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

       apt-get source vlc
      

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

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

    • 26
  3. kaleissin
    2013-08-21T23:37:22+08:002013-08-21T23:37:22+08:00

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

    sudo apt-get build-dep <package>
    sudo apt-get source --compile <package>
    

    为我工作。.deb 最终出现在您运行命令的目录中。

    • 19
  4. Ciro Santilli OurBigBook.com
    2015-05-17T22:57:41+08:002015-05-17T22:57:41+08:00

    hello包装的最小示例

    所有这些以及更多内容都在以下位置进行了描述:https ://www.debian.org/doc/manuals/maint-guide/build.en.html

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

    sudo apt-get install hello
    hello
    

    输出:

    Hello, world!
    

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

    apt-get source hello
    cd hello-*
    

    并打开:

    vim src/hello.c
    

    并将消息修改为:

    Hello, world hacked!
    

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

    vim tests/greeting-1
    

    然后重建:

    sudo apt-get install devscripts
    sudo apt-get build-dep hello
    debuild -b -uc -us
    

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

    dpkg-deb: building package 'hello' in '../hello_2.10-1build1_amd64.deb'.
    

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

    sudo dpkg -i ../hello_2.10-1build1_amd64.deb
    hello
    

    你去那里,它输出新消息:

    Hello, world hacked!
    

    在 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
    

    具体版本:

    bzr branch lp:ubuntu/trusty/hello
    

    您还可以使用pull-lp-source:

    sudo apt-get install ubuntu-dev-tools
    pull-lp-source hello
    

    然后你就可以编辑它了:

    cd hello
    vim some_file
    

    重建它:

    dch -i 
    debcommit
    bzr bd -- -b -us -uc
    

    并安装它:

    sudo dpkg -i ../hello.deb
    

    Ubuntu 打包指南是一个很好的信息来源。

    • 9
  5. ypid
    2015-08-02T04:52:09+08:002015-08-02T04:52:09+08:00

    要获取有关软件包的更多信息,包括上游 URL 和项目/程序联系人,您可以查看版权文件(引用自packages.debian.org)。

    当软件包包含并安装在您的系统上时,您还可以直接在/usr/share/doc/$package_or_program_name/copyright.

    看看如何下载 Debian 软件包的源代码?.

    • 3

相关问题

  • 如何编写 shell 脚本来安装应用程序列表?

  • 如何查看存档中可用的软件包的所有版本?

  • 是否可以说出我安装的哪些软件包不在原版安装中?

  • 如何删除 PPA?

  • 使用 apt-get upgrade 时如何强制安装内核更新?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    我需要什么命令来解压缩/提取 .tar.gz 文件?

    • 8 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Martin Hope
    EmmyS 我需要什么命令来解压缩/提取 .tar.gz 文件? 2011-02-09 14:50:41 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve