On Ubuntu 22.04, the default GNU C compiler version is gcc-11. However, it appears that the latest default kernel version (6.5.0-14-generic as of writing this question) is built using gcc-12. Why is this the case? It feels like it's likely to result in issues related to mixing compilers and has already caused me headaches with kernel modules and dkms.
2 Answers
NOTE: The 6.5 Kernel reports being built as x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04)
and this should be OK. This is because the kernel is not built on your system during install. See https://askubuntu.com/a/1171939/231142 for more info. During any builds it might give you a warning about not matching the installed version since they are not named the same. Installed version reports as gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04)
gcc-12
should already be installed, but if it isn't, you can install it or reinstall it by running:
sudo apt install --reinstall gcc-12
Then all you should have to do is update the link for gcc
to go to the gcc-12
binary:
sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc
You can set it back to 11 as well by doing the following:
sudo ln -s -f /usr/bin/gcc-11 /usr/bin/gcc
You can check it by running gcc --version
.
terrance@terrance-ubuntu:~$ gcc --version
gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

- 41,612
- 7
- 124
- 183
There are a lot of mismatches in Ubuntu 22.05 GNU compiler versions and the copmpiler used to build the kernel.
ls -l /usr/bin/gcc* ... ls -l /usr/bin/g++* ...

- 111
6.5.0-14-generic
as of today) is built with gcc-12. Are you saying gcc-11 is technically the same as gcc-12? – Adam Sperry Jan 15 '24 at 21:03gcc-12
should already be installed. It is just that the link to the/usr/bin/gcc
is not updated to point togcc-12
. They should both be in the path and if you type ingcc-12 --version
it should return to you the installed version. The same goes withgcc-11 --version
should return the version. If you runls -al /usr/bin/gcc
it should return similar tolrwxrwxrwx 1 root root 15 Jan 13 10:42 /usr/bin/gcc -> /usr/bin/gcc-11
– Terrance Jan 15 '24 at 21:06gcc-12
. I can't tell you as I have not experienced any issues in building at all. The only thing I have seen is where someone was trying to installVMWare
and it was requiringgcc 12.3.0
as it apparently looks at the/usr/bin/gcc
link. I updated my link a while ago togcc-12
and as a test I followed the same installation https://askubuntu.com/questions/1499824/ubuntu-22-04-3-vmware-kernel-module-updater#comment2627853_1499824 without any issues and no complaints of 12.3.0 not found. – Terrance Jan 15 '24 at 21:27