How to download source code with Pacman on Arch Linux?

38,283

Solution 1


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

Solution 2

  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.

Solution 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.

Share:
38,283

Related videos on Youtube

Ning Sun
Author by

Ning Sun

Updated on August 01, 2021

Comments

  • Ning Sun
    Ning Sun almost 3 years

    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?

  • ypnos
    ypnos over 13 years
    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.
  • Ehtesh Choudhury
    Ehtesh Choudhury over 10 years
    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.
  • tiktak
    tiktak over 10 years
    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.
  • l0b0
    l0b0 about 10 years
    The repo site is just blank now.
  • ypnos
    ypnos about 10 years
    Right, but the links on the package details page are still there, and the packages can be now found here: projects.archlinux.org/svntogit/packages.git/tree
  • LassePoulsen
    LassePoulsen over 9 years
    You could use makepkg -o to only download and patch the source, instead of building the while package!
  • Sparhawk
    Sparhawk about 9 years
    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.
  • ypnos
    ypnos about 9 years
    That's because they changed to git. You can use the git command line tool though to download the whole tree at once.
  • apurkrt
    apurkrt almost 9 years
    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
  • CSJ
    CSJ over 8 years
    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.
  • kay
    kay almost 7 years
    As already explained here and in 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

Related