Featured image of post Nvidia GPU (3): Gaming, CUDA, Deep Learning, Docker, etc. on Fedora

Nvidia GPU (3): Gaming, CUDA, Deep Learning, Docker, etc. on Fedora

Using Nvidia GPU on Fedora, including gaming, CUDA programming, deep learning, Docker containers, etc.

Motivation

This is the third article in the “Nvidia GPU” series, which mainly documents how to use Nvidia GPUs, especially on Linux systems. In the previous articles, I documented the relevant settings for using Nvidia GPUs on Ubuntu, including gaming, CUDA programming, deep learning, Docker containers, etc. Now I have migrated from Ubuntu to Fedora, and the settings for using Nvidia GPUs on Fedora are different from those on Ubuntu, so I am documenting them here.

Other articles in this series can be found at:

Fedora Installation of Nvidia GPU Drivers

Check GPU Information

First, we need to check our GPU information. Open the terminal and enter the following command:

1
lspci | grep VGA

If you have an Nvidia GPU installed on your computer, you will see output similar to the following:

1
01:00.0 VGA compatible controller: NVIDIA Corporation Device 2803 (rev a1)

For some reason, my computer shows NVIDIA Corporation Device 2803 instead of RTX 4060 Ti, but it doesn’t matter. We just need to know that it’s an Nvidia GPU.

Install Nvidia GPU Drivers

In Ubuntu, we used the graphics-drivers package from the apt repository to install Nvidia GPU drivers. In Fedora, we need to use the rpmfusion repository to install Nvidia GPU drivers.

Compared to downloading and installing the driver directly from the Nvidia official website, using the rpmfusion repository to install Nvidia GPU drivers is simpler and more convenient. Additionally, since the drivers in rpmfusion have been tested on Fedora, they are more stable. The main steps are as follows:

  1. Add the rpmfusion repository:

    1
    2
    
    sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
    sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
    

    You can also download the rpmfusion repository installation package corresponding to your Fedora version from the RPM Fusion official website. In the Fedora system, simply double-click the downloaded installation package, and Fedora will automatically open the Discover software center. Click the “Install” button in the title bar to proceed. Generally, we need to install two repositories: rpmfusion-free and rpmfusion-nonfree. The former contains open-source software, while the latter contains non-open-source software.

    After installation, you can update the software repository:

    1
    
    sudo dnf update
    
  2. Install Nvidia GPU drivers:

    You can refer to the instructions on the RPM Fusion official website and use the following commands to install Nvidia GPU drivers:

    1
    2
    
    sudo dnf install akmod-nvidia # rhel/centos users can use kmod-nvidia instead
    sudo dnf install xorg-x11-drv-nvidia-cuda #optional for cuda/nvdec/nvenc support
    

    Here, akmod-nvidia is the package name for Nvidia GPU drivers in Fedora. After installation, it will automatically compile the kernel module.

  3. (Optional) Secure Boot:

    What is Secure Boot

    Secure Boot is a security standard designed to ensure that a computer only loads verified operating systems and software during startup. It can prevent malicious software from loading during system startup, thereby enhancing system security. In simple terms, Secure Boot ensures that only trusted software can run when the system starts.

    How Secure Boot Works

    1. The UEFI firmware contains a Secure Boot database that stores all trusted public keys and certificates. Generally, trusted public keys include those from operating system vendors, hardware vendors, and user-generated keys.
    2. When the computer starts, the UEFI firmware verifies whether each loaded component (such as the operating system kernel, drivers, etc.) is trusted.
    3. Only components registered in the Secure Boot database can be loaded; unauthorized components will be blocked.

    Linux kernel modules (such as Nvidia GPU drivers) need to be signed to be loaded on systems with Secure Boot enabled. If the kernel module is not signed or the signature is not trusted, these modules will not load on systems with Secure Boot enabled, causing the GPU driver to fail. This is why, after installing Nvidia GPU drivers, you need to generate a signature for the Linux kernel module and register it in the Secure Boot database.

    Do You Need Secure Boot

    For ordinary users (i.e., users with limited knowledge of computers and who do not understand the computer startup process), my recommendation is to enable Secure Boot; for advanced users (who know what they are doing, especially those who understand what their system does during startup or know what they are making their system do during startup), my recommendation is that they can disable Secure Boot.

    If Your Computer Has Secure Boot Enabled

    If your computer has Secure Boot enabled, it may cause Nvidia GPU drivers to fail to load. You can disable Secure Boot in the BIOS.

    If you do not want to disable Secure Boot, you can refer to the instructions on the RPM Fusion official website to register a key and add it to your system to enable Secure Boot. The specific steps are as follows:

    • Install Related Tools

      1
      
      sudo dnf install kmodtool akmods mokutil openssl
      
    • Generate Key

      1
      
      sudo kmodgenca -a
      
    • Register Key

      1
      
      sudo mokutil --import /etc/pki/akmods/certs/public_key.der
      

      You will be prompted to set a password, which you will need to enter after rebooting.

    Note: Since the key is generated for the current kernel version, you may need to regenerate and register the key again after updating the kernel version (i.e., repeat the Generate Key and Register Key steps).

  4. Reboot the computer

    • If you set up Secure Boot in the previous step, after rebooting, enter the MOK management interface, select “Enroll MOK”, enter the password you set, and continue to start the system.
    • If you disabled Secure Boot in the previous step, simply reboot the computer.
  5. Confirm whether the GPU driver is installed successfully:

    1
    
    nvidia-smi
    

    If you see output similar to the following, congratulations, your Nvidia GPU driver has been successfully installed:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 470.57.02    Driver Version: 470.57.02    CUDA Version: 12.5     |
    |-------------------------------+----------------------+----------------------+
    | 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 RTX 4060 Ti  Off  | 00000000:01:00.0 Off |                  N/A |
    | N/A   41C    P8    10W /  N/A |      0MiB /  7611MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
    

Test the GPU

We can use glmark2 to test the GPU performance.

  1. Install glmark2:
1
sudo dnf install glmark2
  1. Run glmark2:
1
glmark2

If you see output similar to the following in the terminal, it means the GPU performance test was successful:

1
2
3
4
5
6
7
8
=======================================================
    glmark2 2021.02
=======================================================
    OpenGL Information
    GL_VENDOR:     NVIDIA Corporation
    GL_RENDERER:   NVIDIA GeForce RTX 4060 Ti/PCIe/SSE2
    GL_VERSION:    4.6.0 NVIDIA 555.58.02
=======================================================

And there will be a window popping up, showing the content being tested. After the test is completed, the terminal will display the test score.

glmark2

Gaming

Linux systems are not originally very suitable for gaming, but with the promotion of Steam, more and more games can run on Linux through Proton. Proton is a tool developed by Valve based on Wine that allows Windows games to run on Linux.

In Ubuntu, installing Steam requires installing some additional dependencies and manually installing Proton. In Fedora, installing Steam is very simple, and it includes Proton by default.

Install Steam

  1. Install Steam:
1
sudo dnf install steam
  1. Log in to your Steam account

In the start menu, find Steam and click to open it, then log in to your Steam account.

Steam

Install Games

If this is your first time using Steam and you haven’t purchased any games yet, you can choose some free games to test, such as “Dota 2”, “Counter-Strike: Global Offensive”, etc.

Dota 2

Launch Games

After installation, you can click “Launch” to start the game, but it often won’t succeed the first time and may require three attempts.

Steam组件

  • The first launch may get stuck downloading a component. Opening the download manager shows it’s trying to download Steam Linux Runtime 2.0. However, for some reason, it cannot start the download, even though Steam Linux Runtime 3.0 is already available. I had to cancel the launch.
  • After canceling the first launch, trying to launch the game again allows Steam Linux Runtime 2.0 to be successfully downloaded, and the game enters the loading screen. However, it gets stuck on a full-screen black screen. I could only click to stop the game.
  • On the third attempt to launch the game, it successfully loads and enters the shader compilation phase. After waiting for the shaders to compile, the game starts normally.

Game Controllers

If you are using a game controller, some additional configuration is needed. If you connect it using a USB cable, it should work directly.

If you are using an Xbox controller, you can connect it via Bluetooth. However, even if it connects, you may find that the controller still cannot control the game. This is because the relevant drivers are missing. We can install the xpadneo package to solve this problem:

1
sudo dnf install xpadneo

Then reconnect via Bluetooth. When connected, the controller will vibrate slightly, whereas previously it did not vibrate when connected. This indicates that the controller has been successfully recognized and can be used to play games.

CUDA Programming

CUDA is a parallel computing platform and programming model developed by Nvidia that leverages the parallel computing power of GPUs to accelerate compute-intensive applications. CUDA programming requires installing Nvidia GPU drivers and the CUDA toolkit. Additionally, there is a certain compatibility relationship between CUDA versions and Nvidia GPU driver versions, so you need to choose the appropriate CUDA version based on your GPU driver version.

Update in August 2025: After installation, I found that this method still doesn’t work, mainly due to compatibility issues between Fedora 42 and CUDA 12.9. Please refer to the “Issues” section at the end for details.

Install CUDA

  1. Check the required CUDA version for your Nvidia GPU driver:
1
nvidia-smi

In the CUDA Version line, you can see the required CUDA version for your Nvidia GPU driver, for example, CUDA Version: 12.9. This means we need to install CUDA 12.9.

  1. Install CUDA:

When installing CUDA in Ubuntu, we directly followed the installation guide on the Nvidia official website.

In Fedora, since we used the RPM Fusion repository to install the drivers earlier, directly following the Nvidia official website may lead to version mismatch issues. For example, in the previous step, we found that we needed to install CUDA 12.9, but the Nvidia official website may only provide installation packages for CUDA 13.0. If you follow the instructions on the Nvidia official website directly, it will cause version mismatch issues. This is because RPM Fusion tests the drivers after they are released by Nvidia and only pushes them to the RPM repository after they are stable. Therefore, we still need to follow the instructions on RPM Fusion to install CUDA.

The commands are as follows:

1
2
3
4
5
sudo dnf config-manager addrepo --from-repofile=https://developer.download.nvidia.com/compute/cuda/repos/fedora41/$(uname -m)/cuda-fedora41.repo
sudo dnf clean all
sudo dnf module disable nvidia-driver
sudo dnf config-manager setopt cuda-fedora41-$(uname -m).exclude=nvidia-driver,nvidia-modprobe,nvidia-persistenced,nvidia-settings,nvidia-libXNVCtrl,nvidia-xconfig
sudo dnf -y install cuda-toolkit

Note that in the above commands, the installed CUDA version is for Fedora 41, while our Fedora version is 42. However, don’t worry. As mentioned in the RPM Fusion instructions, the above commands are applicable to versions after Fedora 41.

  1. Configure environment variables:

If the installation is successful, you will see the CUDA installation files in the /usr/local/cuda-12.9 directory. At the same time, you will see a symbolic link pointing to /usr/local/cuda-12.9 in the /usr/local/cuda directory. If you upgrade the CUDA version later, /usr/local/cuda will point to the new CUDA version directory.

We need to configure environment variables so that CUDA can be found. When adding the CUDA bin directory and lib64 directory to the PATH and LD_LIBRARY_PATH environment variables, we use the /usr/local/cuda directory instead of the /usr/local/cuda-12.9 directory, because this way, we don’t need to modify the environment variables when upgrading the CUDA version in the future.

If you are using bash, you can add the following content to the ~/.bashrc file:

1
2
3
echo 'export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc

If you are using another shell, you can add the above content to the corresponding configuration file of that shell.

  1. Test CUDA:
1
nvcc --version

If you see output similar to the following, it means CUDA has been successfully installed:

1
2
3
4
5
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Jun__6_02:18:23_PDT_2024
Cuda compilation tools, release 12.9, V12.9.82
Build cuda_12.9.r12.9/compiler.34385749_0

Issues

After going through the above steps, it seems that we have successfully installed CUDA, but in fact, the compiler above cannot be used in Fedora 42. If you use it directly for compilation, it will report a GCC version mismatch error. This is because the installed CUDA version is 12.9, which only matches GCC 14 and below, while Fedora 42 has GCC 15 installed by default.

Besides, this issue cannot be resolved by installing GCC 14, because even if GCC 14 is installed, the libraries, header files, and other components in Fedora 42 are still of GCC 15 version, so compilation will still report errors.

This issue is difficult to resolve. One solution is to stop using RPM Fusion to install Nvidia drivers and CUDA, and instead download and install CUDA 13.0 and the corresponding drivers directly from the Nvidia official website. CUDA 13.0 supports GCC 15, but there are still two problems:

  1. You cannot use Fedora’s package management system to manage the installation and upgrade of Nvidia drivers and CUDA. If there are dependencies related to them managed by Fedora, then any update may fail. In severe cases, it may even affect system stability.
  2. As of August 2025, PyTorch, commonly used in deep learning, has not yet adapted to CUDA 13.0, so installing CUDA 13.0 still cannot support many deep learning tasks.

If you insist on using the Fedora system, I currently (as of August 2025) have two solutions:

  • One is to give up Fedora 42 and switch to Fedora 41. But this probably cannot be achieved through a simple system version downgrade, as it involves too many components. A system reinstallation is likely required.
  • The other is to use a virtualized container for configuration. Perhaps when RPM Fusion and PyTorch both support CUDA 13.0 in the future, the container can be discarded.

I have thought it over and chosen the second option. I decided to keep the installed Nvidia drivers and CUDA here, and set up a separate Docker/Podman container for the CUDA programming and deep learning development environment. The main idea is to run Ubuntu 24.04 in the container and install compatible CUDA and Nvidia drivers. Since PyTorch does not yet support CUDA 13.0, I will use CUDA 12.9 in the container. The specific configuration process will be documented in a separate article, please refer to:

comments powered by Disqus