45

I am using Arch Linux. I want to do the same thing like apt-get source coreutils; is it possible to download sources with Pacman? I didn't find a solution in the man pages.

How can I get the source code of a package?

user1767316
  • 3,276
  • 3
  • 37
  • 46
Ning Sun
  • 2,145
  • 1
  • 19
  • 24
  • You can also get individual packages via svn: https://wiki.archlinux.org/index.php?title=Getting_PKGBUILDS_From_SVN – Sparhawk May 05 '15 at 13:08

3 Answers3

48
  1. pacman -S asp
  2. say if you want the source code of the Linux command find

    1. find out which package the command find belongs to: pacman -Qo $(which find). The result is "/usr/bin/find is owned by findutils 4.4.2-3".
  3. asp export findutils

  4. cd findutils
    makepkg -o
    

Now you have your source code.

McBear Holden
  • 5,741
  • 7
  • 33
  • 55
  • 1
    If you just want one package, you can do something like `abs core/wpa_supplicant`, where you prepend the package repository. You can also use `ABSROOT=/tmp/ abs core/wpa_supplicant` if you don't want to use `sudo`. – Ehtesh Choudhury Jan 19 '14 at 06:22
  • 1
    Thanks for the tip on not being sudo to download a package (which is possible with apt-get source). By the way in step 5.1 if you are looking for `find` just type `pacman -Qo find`. I personnally prefer to use `pkgfile find`. Just try it. – tiktak Jan 21 '14 at 15:50
  • You could use `makepkg -o` to only download and patch the source, instead of building the while package! – LassePoulsen Oct 19 '14 at 00:50
  • FYI, In my case, I tried to downalod `python` source, but I got `Missing dependencies` when `makepkg -o`. Use `makepkg -o -i` to skip dependency checking. – CSJ Mar 06 '16 at 18:09
24

2018 Update:

The abs tool described below has been deprecated and it along with its rsync endpoint have been dropped since mid 2017.

The asp tool now provides similar functionality. More information here.


As already mentioned you can use the ABS (Arch Build System):

Install it using pacman:

sudo pacman -S base-devel abs

First, download the ABS tree:

sudo abs

Then, get a specific package:

sudo abs [package_name]

Then copy the package, whose source you want to have, from the local abs tree (e.g. /var/abs/core/findutils) to another directory, e.g. /home/blabla/abs

Then run makepkg:

  • if you only want to get the sources and don't want to build the package you can run makepkg -od

  • otherwise run makepkg -s, which will then handle all the package's dependencies automatically

  • watch out becaouse makepkg will overwrite your modifications, use makepkg -e to build your local sources instead

If you want to install the package you've built, run

pacman -U name-of-package.xz
hendalst
  • 2,957
  • 1
  • 24
  • 25
kilian
  • 256
  • 2
  • 2
  • `makepkg -i` will install the package as well; it's also possible to use `makepkg -ei` to compile whatever is in src and install the ensuing package in one take – apurkrt Sep 06 '15 at 09:06
3

Edit: This answer is outdated due to changes on ABS.

You get the package sources from the Arch Linux SVN repository, called ABS.

First find the package online: http://www.archlinux.org/packages/?q=coreutils

Then, on the package details page, on the right side use the SVN links, e.g.: http://repos.archlinux.org/wsvn/packages/coreutils/trunk/

And there, you have a sweet "Download" button, in this case it leads to: http://repos.archlinux.org/wsvn/packages/coreutils/trunk/?op=dl&isdir=1

It is a little bit more complicated than apt-get source. But perhaps you find a tool on AUR that does the job for you, for example yaourt supports building from sources and exporting them.

ypnos
  • 50,202
  • 14
  • 95
  • 141
  • 1
    I just forgot to mention that the mentioned ABS also comes with user-space tools, so you can in fact automatically checkout all packages etc. However it is overkill for single packages. – ypnos Dec 23 '10 at 11:45
  • The repo site is just blank now. – l0b0 May 31 '14 at 08:11
  • Right, but the links on the package details page are still there, and the packages can be now found here: https://projects.archlinux.org/svntogit/packages.git/tree/ – ypnos May 31 '14 at 19:05
  • I can't see a single `Download` link, though. The only way I can see is to download each file individually by clicking on the `plain` link. – Sparhawk May 05 '15 at 10:57
  • That's because they changed to git. You can use the git command line tool though to download the whole tree at once. – ypnos May 06 '15 at 10:50
  • 4
    As already explained here and in https://www.archlinux.org/news/deprecation-of-abs/ **abs** has been replaced in favor of the new utitlity **asp** To download the sources of a specific package, you might try the following (it worked for me one second ago, but I can't confirm it always will): sudo pacman -S asp; asp checkout nano; cd repos/core-x86_64/; makepkg;h – kay Jul 11 '17 at 20:34