The Ubuntu Kernel team has started compiling the mainline kernel with gcc-13 as of versions 6.4.4 and 6.5-rc3. I don’t know what’s driving this change—i.e. if it’s coming from upstream or if it was an internal decision—or if they plan to revisit it. If I have time tomorrow I’ll go bug them on IRC. At any rate, if you install a newer mainline kernel on Ubuntu 22.04 you can potentially run into some snags when the dpkg post-install scripts kick off dkms. Ubuntu 22.04 uses gcc-11 by default—i.e. if you install the build-essential, dkms, or gcc package(s)—so it may not be able to compile modules against a kernel compiled with gcc-13. (Earlier versions of Ubuntu are probably impacted as well, but at this point it’s safe and recommended to upgrade to 22.04.2 LTS.)
I was able to resolve most of my issues by setting up alternatives for gcc-11 and gcc-12 and giving gcc-12 priority over gcc-11. Of course, this may break other things that will compile with gcc-11 but won’t compile with gcc-12, so caveat emptor. I wasn’t able to find a quick and easy solution for getting gcc-13 installed and working but that would be the logical next step.
Here are the steps to perform these actions on your machine:
# install gcc-12
sudo apt install gcc-12 g++-12
# create a low-priority alternative for /usr/bin/gcc, /usr/bin/g++, and /usr/bin/gcov using gcc-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
# create a high-priority alternative for /usr/bin/gcc, /usr/bin/g++, and /usr/bin/gcov using gcc-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 120 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12
# make sure you didn't goof anything up, should say version 12.1.0
gcc --version
# recompile any broken/missing dkms modules with gcc-12
ls -1 /boot/initrd.img-* | cut -d- -f2- | sudo xargs -n1 /usr/lib/dkms/dkms_autoinstaller start
Mixing compilers have never been supported “anywhere” and usually you should stick with whatever upstream uses (indirectly supports). If you looking for bleeding edge you’re likely better off looking at Arch or Alpine.
I’m not mixing compilers, I’m installing a mainline kernel in Ubuntu LTS. This is a fairly common practice and the kernels come from an “official” repository maintained by the Ubuntu kernel developers. The ability to easily run a newer kernel in an older distribution is a feature, not a bug.
The Ubuntu kernel developers have switched compilers, causing issues, and I have documented a resolution. If you’d like to chastise someone for mixing compilers, you can start here.
I was running the 6.5-rc2 kernel previously for a couple of weeks but I made a big mistake and accidentally deleted it when I was cleaning out older kernels.
Then when I went back to reinstall the 6.5-rc kernel I had installed before, I discovered that between the time I first installed that kernel and my attempt to reinstall it, the kernel devs had gone back and recompiled the 6.5-rc2 kernel branch with the gcc-13 compiler. Now all kernels past 6.4.3 have been recompiled with gcc-13.
Now I am stuck with the default HWE Ubuntu 22.04.3 LTS 6.2 kernel.
I don’t know why you went and found other instructions to follow when I included them in my original post above, but regardless I’m glad it’s working for you.