5

I was trying to install a package for robotic operational system (ROS). And I just go ahead and type sudo apt-get install <package>

After installation, I see a list of files in /opt/share folders, which are the packages I want.

But if I go into src, the source code (.cpp files) aren't there.

I can see the source code if I go to developer's github pages, but how come the package is installed without using the source code? How can I download the source code and install the package using apt-get install command?

  • As a sidenote, I think it is quite unusual for something to land in /opt/share from standard repositories, isn't it? – Hagen von Eitzen Jul 30 '15 at 5:33
  • @HagenvonEitzen yes. There is NO default software that uses /opt/ Would be a violation of the filesystem hierarchy system. – Rinzwind Jul 30 '15 at 6:39
10

By default apt-get install does not download the source codes of packages. There is a specific apt-get option to do that which is source.

From 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 respecting 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 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; otherwise you will probably get either the wrong (too old/too new) source versions or none at all.

So the syntax to download the source package of something to the current directory would be (no need to be root):

apt-get source <package_name>

Also note that as the man pages says you need to have the deb-src repositories enabled for all the regular deb repositories you want to keep track of source packages. The simplest way to do that would be to just add -src to the original repo's initial deb string:

deb http://archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted

On a different note, you might have checked the /usr/src directory which is the designated place for all kernel sources.

2

@heemayl answer tells you how to get the source code but in case you are wondering

how come the package is installed without using the source code?

It is because Ubunutu does not build packages from source and instead downloads precompiled binaries.

A distro like Gentoo Linux however would download the source and build a package locally.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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