Ubuntu 22.04 に nvidia-driver のインストールで `kernel package linux-headers-6. ~~~ is not supported`

## 出会ったエラー

新しくノートPCに Ubuntu 22.04 を入れて、nvidia-driver 入れようと思って、最近よくお世話になっている⇩のページなどを参考に入れていたら、

https://www.kkaneko.jp/tools/ubuntu/ubuntu_cudnn.html

```console
$ ubuntu-drivers devices
$ sudo apt install nvidia-driver-560
```

以下のようなエラー (全文は残してなかったので一部)

```console
nm@razerblade:~$ sudo apt install nvidia-driver-560
~~~
~~~
Setting up nvidia-dkms-560 (560.35.03-0ubuntu0~gpu22.04.4) ...
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
Loading new nvidia-560.35.03 DKMS files...
Building for 6.8.0-50-generic
Building for architecture x86_64
Building initial module for 6.8.0-50-generic
ERROR (dkms apport): kernel package linux-headers-6.8.0-50-generic is not supported
Error! Bad return status for module build on kernel: 6.8.0-50-generic (x86_64)
Consult /var/lib/dkms/nvidia/560.35.03/build/make.log for more information.
dpkg: error processing package nvidia-dkms-560 (--configure):
 installed nvidia-dkms-560 package post-installation script subprocess returned error exit status 10
Setting up libnvidia-encode-560:amd64 (560.35.03-0ubuntu0~gpu22.04.4) ...
Setting up libnvidia-encode-560:i386 (560.35.03-0ubuntu0~gpu22.04.4) ...
dpkg: dependency problems prevent configuration of nvidia-driver-560:
 nvidia-driver-560 depends on nvidia-dkms-560 (<= 560.35.03-1); however:
  Package nvidia-dkms-560 is not configured yet.
 nvidia-driver-560 depends on nvidia-dkms-560 (>= 560.35.03); however:
  Package nvidia-dkms-560 is not configured yet.

dpkg: error processing package nvidia-driver-560 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Processing triggers for man-db (2.10.2-1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: Generating /boot/initrd.img-6.8.0-50-generic
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
Errors were encountered while processing:
 nvidia-dkms-560
 nvidia-driver-560
E: Sub-process /usr/bin/dpkg returned an error code (1)
nm@razerblade:~$
```

## 環境

- Ubuntu 22.04.5 LTS
- 11th Gen Intel® Core™ i7-11800H @ 2.30GHz × 16
- GeForce RTX 3060 Mobile
- など


## 結論

この御記事に助けられました

https://qiita.com/fpdmt2/items/c52ae81c752bf5e4992a

https://students-tech.blog/post/change-gcc.html

gcc をアップグレードすればらしい。が、**適当に変えるのはデンジャラスで**、丁寧な切り替え方まで書いてくださってる。

自分の場合、とどのつまり、

```console
$ gcc --version  # -> 11
$ sudo apt install gcc-12
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
$ gcc --version  # -> 12

# あとは今まで通り
$ sudo ubuntu-drivers autoinstall
$ sudo update-initramfs -u  # (←これよくわかってないけど一応)
```


## で GPT (o1 pro) はなんて言ってたの？

https://chatgpt.com/share/676fd690-e360-8001-b2b0-5cb8b4d7ee73

kenrel をダウングレードしろと言ってきた、うーんカス
「動けばよし」の模範解答、どうもありがとう。


## 以上！