Nvidia and cuda on fedora


i am trying to install nvidia driver with cuda
and I was a little confused which one is better way

i found a way here

and when i run this command sudo dnf -y module install nvidia-driver:latest-dkms
the nvidia driver was installed and after reboot it
i figure out from nvidia-smi output that the whole gnome shell and xorg and all app is running on nvidia

but there is an another way to install it with

and when i installed akmod-nvidia and xorg-x11-drv-nvidia-cuda only apps are rununing on Nvidia when I run these commands __GLX_VENDOR_LIBRARY_NAME=nvidia __NV_PRIME_RENDER_OFFLOAD=1

Which way is more optimal?
please give me an explanation about these two ways
and how can i install cuda for the second way

and i use wayland btw


That is not the recommended way to install nvidia drivers and cuda on fedora.
If one looks into the gnome-software app there is an option to enable 3rd party repos, one of which is the rpmfusion-nonfree-nvidia-driver repo.

The rpmfusion repo contains all the nvidia and cuda packages needed for fedora and they are specifically tweaked and packaged to work with fedora.

My suggestion is simple:

  1. remove everything you may have installed with the instructions from nvidia.
  2. disable the module that was installed in that process with
    sudo dnf module disable nvidia-driver
  3. install the packages from rpmfusion only with
    sudo dnf install akmod-nvidia xorg-x11-drv-nvidia-cuda

Following the completion of step 3 wait at least 5 minutes while the system compiles and installs the nvidia modules in the background, then reboot.

Confirm the nvidia drivers were properly loaded with lsmod | grep nvidia which should show several lines of output.
Now it all should just work for you.

BTW, the cuda driver installed in this way is at version 12.2 as we speak.

$ nvidia-smi
Tue Aug  8 15:55:52 2023       
| NVIDIA-SMI 535.86.05              Driver Version: 535.86.05    CUDA Version: 12.2     |
| 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 3050        Off | 00000000:06:00.0  On |                  N/A |
| 30%   59C    P2             104W / 130W |   1097MiB /  8192MiB |    100%      Default |
|                                         |                      |                  N/A |