Finding the architecture that apt uses

Asked by Kiwinote

At the moment I am writing a program that needs to be able to detect the architecture of the installation. I know that there are many ways to do this, but because it is an apt-related program I would like to detect the architecture that apt uses. So far I have only found the file in /usr/share/doc/apt/examples/configure-index.gz that contains the line "Architecture "i386";". My question is: is this the official place where apt keeps its architecture configuration (in an example folder?) or is there a different place? Also it would be good to know whether this file has been in all releases since dapper, and whether it is still in gutsy.

Thanks,
Kiwinote

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu apt Edit question
Assignee:
No assignee Edit question
Solved by:
Dennis Dirdjaja
Solved:
Last query:
Last reply:
Revision history for this message
Markus Thielmann (thielmann) said :
#1

In my opinion parsing "uname -a" would be the easiest method. It will work on all linux distributions. I'm unsure if it would work on BSD.

Revision history for this message
Kiwinote (kiwinote) said :
#2

I had seen that one, but it's not quite what I'm looking for. The thing is, is that "uname -m" gives a more complicated answer, ie i686 instead of i386. (I would also need a list of all possible replies, which I haven't yet found.) When apt downloads a program it downloads a i386 version, rather than a i686 one. What I'm looking for is the file/command/code that apt (so specifically apt) uses to decide which architecture of package to download. (It only needs to work on systems running apt)

Thanks,
Kiwinote

Revision history for this message
Best Dennis Dirdjaja (dcd-ditsch) said :
#3

Hi Kiwinote,

the default architecture is the architecture apt was compiled for. You can force another architecture by adding the parameter APT::Architecture in /etc/apt/apt.conf. In almost all cases, this would not be a good idea, though.

Revision history for this message
Kiwinote (kiwinote) said :
#4

Thanks, precisely what I was looking for. Hadn't yet made the connection between configure-index.gz and the man page of apt.conf. For anyone who visits this page via google, you can parse the result of "apt-cache -v" to find the installed architecture. (Ignore the status changes, I just wanted to post a custom thank-you message rather than a machine generated one)

Revision history for this message
Kiwinote (kiwinote) said :
#5

Thanks Dennis Dirdjaja, that solved my question.

Revision history for this message
Benoit Pierre (benoit.pierre) said :
#6

Simpler alternative: dpkg --print-architecture