224

uname -m gives i686 and uname -m gives i686 i386 output in Red Hat Enterprise Linux Server release 5.4 (Tikanga) machine. I need to install Oracle Database 10g Release 2 on that machine. So, how can I decide whether kernel architecture is 32bit or 64bit?

user2914
  • 2,661

14 Answers14

193

i386 and i686 are both 32-bit.
x86_64 is 64-bit

example for 64 bit:

behrooz@behrooz:~$ uname -a  
Linux behrooz 2.6.32-5-amd64 #1 SMP Mon Mar 7 21:35:22 UTC 2011 **x86_64** GNU/Linux

EDIT:
See is my linux ARM 32 or 64 bit? for ARM

Behrooz
  • 2,368
  • 2
  • 15
  • 13
113

It's simple! Use the arch command from coreutils package.

Pablo A
  • 2,712
Real Dreams
  • 2,365
53

For Debian:

On my PC

    ~ > dpkg --print-architecture
    amd64
    ~ > dpkg --print-foreign-architectures
    i386

My Raspberry Pi 2

    ~ > dpkg --print-architecture
    armhf
  • 2
    this works best when determining package architecture to use with checkinstall, thx! – Aquarius Power Feb 11 '16 at 01:59
  • 2
    Thank you. I've been looking for something that would drop the 'standard' "amd64"/"i386" architecture names rather than just "x86_64". No one uses that terminology when naming precompiled releases. – Cliff Jul 11 '19 at 19:25
  • Does CentOS/RedHat have an equivalent command? Or is this a problem on RH-based OSes? Trying to add support to an ansible role for the RH family to expand OS options for future servers. – Zack Dec 20 '20 at 20:48
  • Much better for me, thanks! – Olivier Pons May 27 '22 at 10:46
35

@behrooz is correct. Unfortunately uname requires you to know architectures. Actually, I was looking for a list of architectures and I found this article that answers your question. In regards to uname -m:

x86_64 GNU/Linux indicates that you've a 64bit Linux kernel running. If you use see i386/i486/i586/i686 it is a 32 bit kernel.

To determine if the hardware is capable of running a 64-bit kernel

grep flags /proc/cpuinfo

Look for the following in the output (all flags retrieved from this stackoverflow answer for the same question )

  • lm flag means Long mode cpu - 64 bit CPU
  • tm flag means Protected mode - 32-bit CPU
  • rm flag means Real Mode - 16 bit CPU
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
  • Does the lm flag simply mean the CPU supports 64-bit or does it mean that it's running in 64-bit. I recommend relying on the arch knowing that it will be x86_64 for 64-bit or i?86 for 32-bit. – penguin359 May 02 '11 at 21:45
  • 1
    @penguin359 it means that the cpu supports 64-bit. – xenoterracide May 02 '11 at 22:57
  • @xeno so then is can't be used to determine the kernel architecture. – penguin359 May 02 '11 at 23:58
  • @penguin359 no, was that unclear in the answer? – xenoterracide May 03 '11 at 08:55
  • @xeno When I first read your answer, I took it as implying an alternative to looking at the kernel architecture. On a re-read, I do notice you were specifying the CPU architecture, but I wanted to clarify that that does not help with the user's question which is specifically whether the kernel is 64-bit. – penguin359 May 03 '11 at 11:01
  • 2
    @penguin359, no but it's often useful to find out if your OS is running 64-bit and if not if the hardware is capable, imo – xenoterracide May 03 '11 at 20:09
  • +1, much more accurate than my answer. – Behrooz May 04 '11 at 17:56
14

The simplest way is to run:

getconf LONG_BIT

which will output 64 or 32 depending on whether it is 32 or 64 bits.

eg:

dannyw@dannyw-redhat:~$ getconf LONG_BIT
64
dannyw
  • 241
  • 4
    This answer is misleading. If you enable multiarch support and install 64 bit kernel over 32 bit installation getconf LONG_BIT will print 32 though you are running 64 bit kernel. – kenn Jul 23 '18 at 07:42
5

There is also lscpu: display information about the CPU architecture

lscpu
Architektura:                    x86_64
Tryb(y) pracy CPU:               32-bit, 64-bit
Kolejność bajtów:                Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU:                             8
Lista aktywnych CPU:             0-7
Wątków na rdzeń:                 2
Rdzeni na gniazdo:               4
Gniazd:                          1
Węzłów NUMA:                     1
ID producenta:                   GenuineIntel
Rodzina CPU:                     6
Model:                           60
Nazwa modelu:                    Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Wersja:                          3
CPU MHz:                         3392.293
CPU max MHz:                     3900,0000
CPU min MHz:                     800,0000
BogoMIPS:                        6784.24
Wirtualizacja:                   VT-x
Cache L1d:                       128 KiB
Cache L1i:                       128 KiB
Cache L2:                        1 MiB
Cache L3:                        8 MiB
Procesory węzła NUMA 0:          0-7
Adam
  • 989
3

Here's another method using uname.

From uname(1):

...

    -i, --hardware-platform
      print the hardware platform or "unknown"
...
# uname -i
x86_64

2

use syscap from Formake project

syscap allows to probe many system properties and test dependencies. It is a portable shell script.

Get CPU architecture:

syscap info -arch

Get kernel name and version:

syscap info -kernel -kernver
Alex
  • 21
1

Another way is to check the architecture some system file was compiled for, like

$ file /usr/bin/ld
/usr/bin/ld: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
minaev
  • 721
1

Or you can use the way of what the uname command internally does if you want to implement some stuff on your own:

#include <sys/utsname.h>
#include <stdio.h>

int main() {
    struct utsname name;
    uname(&name);
    printf("%s\n",name.machine);
    return 0;
}
Meow
  • 302
1

If you're looking for a simple one-liner, this is the most reliable solution that I've found that returns 64 or 32. It doesn't care if you're running ARM or not, and it should work on any system using bash or sh.

Beware, this will assume the system is either 32-bit or 64-bit. See my explanation below if you need to detect 8- 16- or some-other-bit architecture.

[ $((0xffffffff)) -eq -1 ] && echo 32 || echo 64

What's happing here?
The logic is very simple and it all boils down to how computers store signed integers. A 32-bit architecture only has 32 bits that it can use for storing signed integers while a 64-bit architecture has 64 bits! In other words the set of integers that can be stored is finite. Half of this set represents negative numbers and half represents positive numbers. The signed integer equalling -1 is represented as the largest number that can be stored in a given number of bits for that architecture. On a 32-bit system, -1 can be represented by the hex value 0xFFFFFFFF (which is 32 binary bits, all equalling 1). On a 64-bit system, 0xFFFFFFFF translates to 4,294,967,295, base 10 while 0xFFFFFFFFFFFFFFFF is the representation for -1). You can see how this would easily scale for systems that are 8- or 16-bit as well which would equal -1 at 0xFF and 0xFFFF, respectively.

b_laoshi
  • 131
  • 4
1

For debian Linux derived systems.

On 64bits systems :

$ dpkg-architecture -q DEB_BUILD_ARCH
amd64

On 32bits systems :

$ dpkg-architecture -q DEB_BUILD_ARCH
i386
SebMa
  • 2,149
1

This is a small bash function that helped my a lot:

initArch() {
  ARCH=$(uname -m)
  case $ARCH in
    armv5*) ARCH="armv5";;
    armv6*) ARCH="armv6";;
    armv7*) ARCH="arm";;
    aarch64) ARCH="arm64";;
    x86) ARCH="386";;
    x86_64) ARCH="amd64";;
    i686) ARCH="386";;
    i386) ARCH="386";;
  esac
}

In my case, uname -m gives me x86_64, but the binary I am trying to dowload refers to it as amd64.

This code is part of the get_helm.sh script to install helm binary.

0

Not sure how useful this is, but I crafted this for Arch:

grep "model name" /proc/cpuinfo | sed "s/model name   : //" | head -n 1

(Only answered because I searched for Arch and found this; I know the OP asked about Red Hat.)

张馆长
  • 131
Jesse
  • 351