How to download source code with Pacman on Arch Linux?
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 automaticallywatch 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
pacman -S asp
-
say if you want the source code of the Linux command
find
- 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".
- find out which package the command
asp export findutils
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.
Related videos on Youtube
Ning Sun
Updated on August 01, 2021Comments
-
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 over 13 yearsI 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 over 10 yearsIf you just want one package, you can do something like
abs core/wpa_supplicant
, where you prepend the package repository. You can also useABSROOT=/tmp/ abs core/wpa_supplicant
if you don't want to usesudo
. -
tiktak over 10 yearsThanks 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 typepacman -Qo find
. I personnally prefer to usepkgfile find
. Just try it. -
l0b0 about 10 yearsThe repo site is just blank now.
-
ypnos about 10 yearsRight, 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 over 9 yearsYou could use
makepkg -o
to only download and patch the source, instead of building the while package! -
Sparhawk about 9 yearsI can't see a single
Download
link, though. The only way I can see is to download each file individually by clicking on theplain
link. -
ypnos about 9 yearsThat's because they changed to git. You can use the git command line tool though to download the whole tree at once.
-
apurkrt almost 9 years
makepkg -i
will install the package as well; it's also possible to usemakepkg -ei
to compile whatever is in src and install the ensuing package in one take -
CSJ over 8 yearsFYI, In my case, I tried to downalod
python
source, but I gotMissing dependencies
whenmakepkg -o
. Usemakepkg -o -i
to skip dependency checking. -
kay almost 7 yearsAs 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