Error installing in WSL2

This is my version of Ubuntu:

PS C:\WINDOWS\system32> wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2

This is my gcc version:

zhao@ZhaoYH:~$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

This is the result after entering nvidia-smi

zhao@DESKTOP-CBA46OT:~$ nvidia-smi
Sat Sep 16 08:57:03 2023
| NVIDIA-SMI 530.50                 Driver Version: 531.79       CUDA Version: 12.1     |
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|   0  NVIDIA GeForce RTX 4060 L...    On | 00000000:01:00.0 Off |                  N/A |
| N/A   34C    P8                1W /  N/A|     10MiB /  8188MiB |      0%      Default |
|                                         |                      |                  N/A |

| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|    0   N/A  N/A        23      G   /Xwayland                                 N/A      |

When I followed Nvidia installation tutorial1 or Nvidia Tutorial 2 The same error below appears, an error occurred when I reached the second line of the command:

sudo sh
zhao@DESKTOP-CBA46OT:~$ sudo sh
[sudo] password for zhao:
sh: 1: dkms: not found
 Installation failed. See log at /var/log/cuda-installer.log for details.
zhao@DESKTOP-CBA46OT:~$ cat /var/log/cuda-installer.log
[INFO]: Driver not installed.
[INFO]: Checking compiler version...
[INFO]: gcc location: /usr/bin/gcc

[INFO]: gcc version: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

[INFO]: Initializing menu
[INFO]: Disabling driver option for WSL install
[INFO]: nvidia-fs.setKOVersion(2.17.5)
[INFO]: Setup complete
[INFO]: Installing: CUDA Demo Suite 12.2
[WARNING]: Unable to create .pc files, permission denied at /usr/lib/pkgconfig/!
[WARNING]: Cannot find manpages to install.
[INFO]: Installing: CUDA Documentation 12.2
[WARNING]: Unable to create .pc files, permission denied at /usr/lib/pkgconfig/!
[WARNING]: Cannot find manpages to install.
[INFO]: Installing: Kernel Objects
[INFO]: cudaItem::install - kernelobjects
[INFO]: Able to write to /usr/local/kernelobjects/
[INFO]: Installing: nvidia-fs
[INFO]: cudaItem::install - kernelobjects
[INFO]: dkms not found
[INFO]: DKMS is not installed,skip to static kernel module install
[INFO]: previous version of nvidia-fs is not installed, nvidia-fs version: 2.17.5 will be installed.
[INFO]: getting mofed Status
[INFO]: installation status shows that mofed is not installed,please install mofed before continuing nvidia_fs install.
[ERROR]: Install of nvidia-fs failed, quitting

My first installation was successful, but then the ~/.bashrc file was damaged. So I reinstalled Ubuntu. I tried various methods on the Internet to completely clear the remaining CUDA and Nvidia files, but I still got the same error. I even reinstalled Windows 11, but the error still did not disappear.

I followed other methods and tried looking at /var/log/nvidia-installer.log but the file did not exist at all and /var/log/nvidia/ was an empty folder

There is no driver install needed when installing on WSL. You should not attempt to install any driver components.

WSL has its own specific install instructions which are separate from an ordinary linux install. Please follow the instructions here. You may need to clean up or replace your WSL environment first, if it is already damaged.