Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel

I have multiple version of gcc installed on my Linux based system as follows:

ls -l /usr/bin/gcc*
lrwxrwxrwx 1 root root 7 Jan 11 05:20 /usr/bin/gcc -> gcc-4.4
-rwxr-xr-x 1 root root 239528 Sep 21 2010 /usr/bin/gcc-4.3
-rwxr-xr-x 1 root root 255536 Nov 15 2010 /usr/bin/gcc-4.4

I need to build a nvidia device driver using the same version of GNU compiler as was used to compile the currently running kernel. How do I find out the version of my GNU gcc compiler that was used by upstream Linux distribution to compile and pack my binary Linux kernel?

You need to cat the /proc/version file. This file identifies the kernel version that is currently running and gcc version used to build the kernel.

Sample Outputs From Debian GNU/Linux 6.x

Open a command-line terminal (select Applications > Accessories > Terminal), and then type the cat command:
$ cat /proc/version
Sample outputs:

Linux version 2.6.32-5-amd64 (Debian 2.6.32-41) ( (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Mon Jan 16 16:22:28 UTC 2012

(Fig.01: This kernel was built using gcc version 4.3.5)

Sample Outputs From CentOS / RHEL 6.x Server

Type the following command:
$ cat /proc/version
Sample outputs:

Linux version 2.6.32-220.2.1.el6.x86_64 ( (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Dec 13 16:21:34 EST 2011

(Fig.02: This kernel was built using gcc version 4.4.6)

Sample outputs from an Ubuntu Linux laptop

$ cat /proc/version
Sample outputs:

Linux version 4.13.0-17-generic (buildd@lcy01-amd64-011) (gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)) #20-Ubuntu SMP Mon Nov 6 10:04:08 UTC 2017

How Do I Force make To Use Particular Compiler?

You need to set shell environment variable called CC to point to your C compiler. In this example set CC to gcc version 4.3.x:
$ export CC=/usr/bin/gcc-4.3
$ make

OR start building NVIDIA module using gcc-4.3:
$ export CC=/usr/bin/gcc-4.3
$ bash

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • dansao Mar 26, 2012 @ 9:28

    Just need to thank

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.