I am assuming that all application installed through apt-get are open source; but for those that are available in that manner, where can I get the source code for these applications as well as update them?

I have a couple applications I use regularly that aren't being actively developed any longer and I would like to add features. Where would I go to get the rights to update these applications?

In this case specifically, I am referring to the hellanzb package

  • 7
    apt-get does support closed-source programs as well, so your initial assumption is incorrect. – Flimm Jan 7 '13 at 14:47

Use the command apt-get source <package> (don't use sudo with it) to download the source of a package.

From man apt-get:

       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

To build a package from source, first install the build dependencies:

sudo apt-get build-dep <package>  

Then use dpkg-buildpackage to create a .deb file. From APT and Dpkg Quick Reference Sheet:

dpkg-buildpackage Builds a Debian package from a Debian source tree. You must be in the main directory of the source tree for this to work. Sample usage:

 dpkg-buildpackage -rfakeroot -uc -b

Where -rfakeroot instructs it to use the fakeroot program to simulate root privileges (for ownership purposes), -uc stands for "Don't cryptographically sign the changelog", and -b stands for "Build the binary package only"

In a terminal, cd into the directory containing the package source (e.g ~/code/hellanzb-0.13) and run the following command:

dpkg-buildpackage -rfakeroot -uc -b

If the build is successful, there will be a .deb file located in the parent
directory (e.g ~/code/hellanzb_0.13-6.1_all.deb).

  • how can I install from the modified source. as well as commit it back for other users to use. Thanks! – myusuf3 Feb 28 '11 at 5:32
  • 1
    @dustyprogrammer Updated my answer with instructions on creating a .deb package from the source code. As for getting your modified package into the repositories, you should talk to a MOTU about that. – Isaiah Feb 28 '11 at 6:48
  • @DoR is there a way to create a deb that installs by default in a custom directory? the same way we can install using the --prefix during the configure process? actually i cant find the tarballs for the source of a library,thats why i cant configure --prefix,and make install it.. but that pakages source is available through apt,so i was thinking to install the source package in the desired prefix. – ashishsony Jan 16 '13 at 8:06
  • 2
    If you don't want to use apt-get source (for example when building a package taken from other distro) download the 3 source files and use 'dpkg-source -x [fine].dsc' to extract the files and apply the diffs before dpkg-buildpackage. (ftp.debian.org/debian/doc/source-unpack.txt) – Shlomi Loubaton Mar 23 '14 at 10:33
  • Does sudo apt-get build-dep <package> install the dependencies as binaries? If so, this is not a complete build from source. How does one make build-dep install dependencies from source? – Hello World Oct 1 '14 at 13:47

In general, you can get the source of an installed package by following this procedure:

  1. Enable the source repositories. Open the dashboard (top left button) and search for sources. That should bring up the Software & Updates program, run that and make sure you have the "Source code" option selected:

    enter image description here

  2. Open a terminal and run this command:

     apt-get source vlc

That will download vlc's sources to your current directory and you can view them at your leisure.

Of course, in the case of vlc, you can also download them directly from the videolan.org website: https://www.videolan.org/vlc/download-sources.html

  • 1
    You shouldn't need to use sudo with 'apt-get source' – Squidly Feb 3 '15 at 15:01
  • @MrBones argh! No, of course you don't, force of habit. Thanks for pointing it out. – terdon Feb 4 '15 at 12:11
  • in the terminal: software-properties-gtk <--- that will launch the "Software & Updates" GUI panel. (It did not show up in the dashboard search for me for whatever reason.) – pestophagous Apr 15 '17 at 2:10

You can use apt-get source --compile directly:

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

Worked for me. The .deb winds up in the directory you ran the command from.

  • 9
    Worked for me as well, thanks. Just one extra detail: you can install the .deb with sudo dpkg -i <package>.deb – waldyrious Nov 23 '13 at 18:00
  • Best solution except that apt will revert to the repository version because you forgot to document the changelog with "dch -i". – Futal Aug 24 '16 at 13:44

Minimal example with the hello package

All of this and more is described at: https://www.debian.org/doc/manuals/maint-guide/build.en.html

First let's get a sample package to modify the source for:

sudo apt-get install hello


Hello, world!

Now let's hack it up. Get the source:

apt-get source hello
cd hello-*

and open:

vim src/hello.c

and modify the message to:

Hello, world hacked!

Then do the same on the test otherwise the annoying test will start failing:

vim tests/greeting-1

Then rebuild with:

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

Near the end of the output, it says:

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

so it created the .deb on the parent directory, how dare it. So finally we install and test the modified package:

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

and there you go, it outputs the new message:

Hello, world hacked!

Tested on Ubuntu 18.04.

Old bzr answer

TODO: this stopped working on Ubuntu 16.04 Xenial, failing with: bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/hello/".. bzr branch lp:ubuntu/wily/hello works and bzr branch lp:ubuntu/xenial/hello fails again. For some reason https://code.launchpad.net/ubuntu/+source/hello does not show Xenial: https://web.archive.org/save/https://code.launchpad.net/ubuntu/+source/hello

As mentioned at https://askubuntu.com/a/81889/52975 there is also a Ubuntu-specific approach with bzr.

Get the latest version:

bzr branch lp:ubuntu/hello

Specific version:

bzr branch lp:ubuntu/trusty/hello

You can also use pull-lp-source:

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

Then you'll be able to edit it:

cd hello
vim some_file

Rebuild it:

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

And install it:

sudo dpkg -i ../hello.deb

The Ubuntu packaging guide is a good source of information.

  • bzr branch lp:ubuntu/hello bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/hello/". bzr branch lp:ubuntu/xenial/lightdm bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/xenial/lightdm/". Ubuntu packaging guide, specifically 4.2. Getting the source says: bzr branch ubuntu:lightdm lightdm.quickswitch bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/lightdm/". What a mess. :-( – Stéphane Gourichon Aug 15 '16 at 16:58
  • Used pull-lp-source instead, but then we don't get a bzr repository. bzr bd -- -b -us -uc says bzr: ERROR: Not a branch: "/org/gourichon/localdata/SG/projects/sysadmin/sysadmin_ergozel/2016/2016-08-15/blouarp/lightdm-1.18.3/". :-/ Thanks for any hint. – Stéphane Gourichon Aug 15 '16 at 17:03
  • @StéphaneGourichon hummm, I reproduce you on Ubuntu 16.04 Xenial. Adding the specific version works: bzr lp:ubuntu/wily/hello, but for some reason there is no xenial version? And none shows on: code.launchpad.net/ubuntu/+source/hello Go figure. – Ciro Santilli 新疆再教育营六四事件法轮功郝海东 Aug 17 '16 at 7:01
  • 1
    Thanks for taking care of reproducing. Kind of picked the wrong card, then. Opened bugs.launchpad.net/ubuntu/+source/bzr/+bug/1614053 mentioning this page. – Stéphane Gourichon Aug 17 '16 at 10:53
  • 1
    More convenient than some of the other approaches. And thanks for the other insider tips :) – nealmcb May 3 '18 at 18:57

To get more information about a package including upstream URL and project/program contacts you can have a look at the copyright file (referenced from packages.debian.org).

When the package is included and installed on your system, you can also read the copyright file directly at /usr/share/doc/$package_or_program_name/copyright.

See how to download Debian package's source code?.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.