Skip to content

2025

Installing NVIDIA Driver CUDA Toolkit on Ubuntu for Newer GPUs (e.g. 5060 Ti)

Hello everyone! If you've recently upgraded to a newer NVIDIA GPU, like the powerful 5060 Ti, and are running Ubuntu 24.04 or later, you might have run into issues installing the latest drivers and CUDA Toolkit directly from the standard Ubuntu repositories. This is often because newer hardware requires more up-to-date drivers than what's typically available in the default package sources.

This blog post will guide you through the process of installing the NVIDIA driver (specifically version 575 or newer) and CUDA Toolkit (version 12.8 or newer) by utilizing the official NVIDIA-maintained repositories. This method ensures you get the latest compatible software and allows for easier future updates.


1. Prerequisites and System Preparation

Before we begin, ensure your system is up to date and you have the necessary tools.

  • Operating System: Ubuntu 24.04 LTS (or newer)
  • GPU: NVIDIA 5060 Ti (or similar recently released NVIDIA GPU requiring newer drivers)
  • Internet Connection: Required for downloading packages.

It's highly recommended to back up your system before proceeding with major driver installations.

First, update your package lists and upgrade any existing packages:

sudo apt update
sudo apt upgrade -y

You might also want to ensure you have the necessary kernel headers and necessary packages for build is installed, as they are crucial for driver compilation:

sudo apt update
sudo apt install gcc
sudo apt install make
sudo apt install linux-headers-$(uname -r) -y

2. Adding the Official NVIDIA Repository

The key to installing newer drivers is to add the official NVIDIA repository to your system's APT sources. This repository provides the latest drivers and CUDA Toolkit versions directly from NVIDIA.

Just follow this nvidia official link CUDA Toolkit for ubuntu https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=24.04&target_type=deb_network

After adding the repository, update your package list again to fetch the new package information:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update

3. Installing the NVIDIA Driver and cuda toolkit

Now that the NVIDIA repository is configured, you can install the recommended driver. For your 655060 Ti, a driver version of at least 575 is required.

Installing the cuda-toolkit

sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-9

May you don't want so recent version of cuda-toolkit. The least cuda-tookit version supporting 50 series gpu is 12.8.

Installing the driver

sudo apt-get update
sudo apt-get install -y nvidia-open

The cuda-drivers is also OK. But the the open source one nvidia-open is recommended.

During the installation, you may noticed here is something like

Building initial module nvidia/575.57.08 for 6.8.0-62-generic
Sign command: /usr/bin/kmodsign
Signing key: /var/lib/shim-signed/mok/MOK.priv
Public certificate (MOK): /var/lib/shim-signed/mok/MOK.der

If you enable secure boot, you should enroll the public certificate. If secure boot is disabled on your host, you can ignore the output while installation and skip the 4th section.


4. Addressing Secure Boot and MOK Management

If Secure Boot is enabled on your system, the NVIDIA kernel modules, which are signed with NVIDIA's public key, will not be loaded automatically by default. You will need to enroll this public key into your system's Machine Owner Key (MOK) list.

  1. Use command to import the nvidia public certificate
    sudo mokutil --import /var/lib/shim-signed/mok/MOK.der
    

You will be prompted to enter password 2 or 3 times. Decided by if you are prompted to enter the password for sudo at first. The last two password is for secure-boot and the ensurement the password(prompted to enter the same password again).

  1. MOK Management Screen: Upon rebooting, your system will likely boot into a "MOK management" or "Secure Boot Key Management" screen (this is part of your UEFI/BIOS, not Ubuntu itself).

  2. Enroll MOK: Navigate through the options to "Enroll MOK", then "continue". You will then be prompted to enter the password you set just now. This step officially registers NVIDIA's public key with your Secure Boot system.

  3. Continue Boot: After successfully enrolling the key, choose to continue booting your system.


5. Add the CUDA Toolkit Binary to Path

We've install the cuda toolkit in the 3rd step. But the some executable binaries are not in the path. So, you can only access them by the absolute path.

After installation, it's good practice to add CUDA to your system's PATH and LD_LIBRARY_PATH. You can do this by adding the following lines to your ~/.bashrc (or ~/.zshrc if you use Zsh) and then sourcing the file:

echo 'export PATH=/usr/local/cuda-12/bin$:$PATH' >> ~/.bashrc 
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc

Verify your installation by checking nvcc --version:

You should see something like:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Tue_May_27_02:21:03_PDT_2025
Cuda compilation tools, release 12.9, V12.9.86
Build cuda_12.9.r12.9/compiler.36037853_0


6. Setting Up Docker with GPU Support (NVIDIA Container Toolkit)

For developers using Docker, you'll want to enable your containers to access the GPU. This requires the NVIDIA Container Toolkit. Fortunately, since you've already added the NVIDIA repository, installing it is straightforward.

  1. Install the NVIDIA Container Toolkit:

    sudo apt install nvidia-container-toolkit
    

  2. Configure Docker to Use NVIDIA Runtime: You need to tell Docker to use nvidia as its default runtime for GPU-enabled containers. And restart docker to make it work. This involves modifying Docker's daemon configuration.

    sudo nvidia-ctk runtime configure --runtime=docker
    sudo systemctl restart docker
    

You will say something like this in your /etc/docker/daemon.json

{    
 "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}
  1. Test Your Docker GPU Setup: You can test your setup by running a simple CUDA-enabled Docker image:
    sudo docker run --rm --gpus all nvidia/cuda:12.8.0-base-ubuntu24.04 nvidia-smi
    

You should see the output of nvidia-smi from inside the Docker container, indicating successful GPU access.

image-20250629113600207


7. Conclusion

By following these steps, you should have successfully installed the latest NVIDIA driver and CUDA Toolkit on your Ubuntu system, enabling your newer GPU for development and computation. You've also set up Docker to seamlessly leverage your GPU within containers.

References

  • https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=24.04&target_type=deb_network
  • https://forums.developer.nvidia.com/t/we-would-like-to-know-when-the-nvidia-drivers-for-5060ti-on-ubuntu-will-be-released/331207
  • https://forums.developer.nvidia.com/t/nvidia-drivers-not-working-while-secure-boot-is-enabled-after-updating-to-ubuntu-24-04/305351/6?u=kiceyscream
  • https://forums.developer.nvidia.com/t/could-not-select-device-driver-with-capabilities-gpu/80200
  • https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

在 Ubuntu 上为新一代显卡(如 5060 Ti)安装 NVIDIA 驱动和 CUDA Toolkit

大家好!如果你最近升级到了新一代 NVIDIA 显卡(如强大的 5060 Ti),并且正在运行 Ubuntu 24.04 或更高版本,你可能会发现直接从标准 Ubuntu 软件源安装最新驱动和 CUDA Toolkit 时遇到问题。这通常是因为新硬件需要比默认软件源中更为新颖的驱动程序。

本文将指导你如何通过添加 NVIDIA 官方维护的软件源,安装 NVIDIA 驱动(建议 575 及以上版本)和 CUDA Toolkit(建议 12.8 及以上版本)。这种方式可以确保你获得最新兼容的软件,并便于后续升级。


1. 前置条件与系统准备

在开始之前,请确保你的系统已更新,并具备必要的工具。

  • 操作系统:Ubuntu 24.04 LTS(或更高)
  • 显卡:NVIDIA 5060 Ti(或类似新发布的 NVIDIA 显卡)
  • 网络连接:需要联网下载软件包

强烈建议在进行重大驱动安装前备份系统。

首先,更新你的软件包列表并升级现有软件包:

sudo apt update
sudo apt upgrade -y

你还需要确保已安装内核头文件和必要的构建工具,这对于驱动编译至关重要:

sudo apt update
sudo apt install gcc
sudo apt install make
sudo apt install linux-headers-$(uname -r) -y

2. 添加 NVIDIA 官方软件源

安装新驱动的关键在于将 NVIDIA 官方软件源添加到系统的 APT 源中。该源提供了最新的驱动和 CUDA Toolkit。

请参考 NVIDIA 官方链接 CUDA Toolkit for ubuntu https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=24.04&target_type=deb_network

添加软件源后,再次更新软件包列表以获取新信息:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update

3. 安装 NVIDIA 驱动和 CUDA Toolkit

现在已经配置好 NVIDIA 软件源,可以安装推荐的驱动了。对于 5060 Ti,建议驱动版本至少为 575。

安装 CUDA Toolkit

sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-9

如果你不需要这么新的 CUDA Toolkit,支持 50 系列显卡的最低版本是 12.8。

安装驱动

sudo apt-get update
sudo apt-get install -y nvidia-open

cuda-drivers 也是可以的,但推荐使用开源的 nvidia-open

安装过程中,你可能会看到如下信息:

Building initial module nvidia/575.57.08 for 6.8.0-62-generic
Sign command: /usr/bin/kmodsign
Signing key: /var/lib/shim-signed/mok/MOK.priv
Public certificate (MOK): /var/lib/shim-signed/mok/MOK.der

如果你启用了安全启动(Secure Boot),需要注册公钥。如果主机未启用安全启动,可以忽略此输出并跳过第 4 节。


4. 处理安全启动与 MOK 管理

如果系统启用了 Secure Boot,NVIDIA 内核模块默认不会被自动加载。你需要将 NVIDIA 的公钥注册到系统的 MOK(Machine Owner Key)列表。

  1. 使用命令导入 NVIDIA 公钥:
    sudo mokutil --import /var/lib/shim-signed/mok/MOK.der
    

你会被要求输入密码 2~3 次,最后两次是为 Secure Boot 设置和确认密码。

  1. 重启后,系统会进入 "MOK 管理" 或 "安全启动密钥管理" 界面(属于 UEFI/BIOS)。

  2. 选择 "Enroll MOK",然后 "continue",输入刚才设置的密码,完成公钥注册。

  3. 注册完成后,选择继续启动系统。


5. 添加 CUDA Toolkit 可执行文件到 PATH

我们在第 3 步已经安装了 CUDA Toolkit,但有些可执行文件默认不在 PATH 中,需要手动添加。

安装后,建议将 CUDA 路径加入系统的 PATHLD_LIBRARY_PATH。可以将以下内容添加到 ~/.bashrc(或 Zsh 用户的 ~/.zshrc),然后执行 source:

echo 'export PATH=/usr/local/cuda-12/bin:$PATH' >> ~/.bashrc 
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc 
source ~/.bashrc

通过 nvcc --version 验证安装:

你应该能看到类似如下输出:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Tue_May_27_02:21:03_PDT_2025
Cuda compilation tools, release 12.9, V12.9.86
Build cuda_12.9.r12.9/compiler.36037853_0


6. 配置支持 GPU 的 Docker(NVIDIA Container Toolkit)

如果你使用 Docker 进行开发,需要让容器访问 GPU。这需要安装 NVIDIA Container Toolkit。由于我们已经添加了 NVIDIA 软件源,安装非常简单。

  1. 安装 NVIDIA Container Toolkit:

    sudo apt install nvidia-container-toolkit
    

  2. 配置 Docker 使用 NVIDIA 运行时,并重启 Docker 服务:

    sudo nvidia-ctk runtime configure --runtime=docker
    sudo systemctl restart docker
    

你会在 /etc/docker/daemon.json 看到类似如下内容:

{ 
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}
  1. 测试 Docker GPU 支持:
    sudo docker run --rm --gpus all nvidia/cuda:12.8.0-base-ubuntu24.04 nvidia-smi
    

你应该能看到容器内 nvidia-smi 的输出,说明 GPU 可用。

image-20250629113600207


7. 总结

通过以上步骤,你应该已经在 Ubuntu 系统上成功安装了最新的 NVIDIA 驱动和 CUDA Toolkit,并让新一代显卡可以用于开发和计算。同时也配置好了 Docker 支持 GPU。

参考资料

  • https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=24.04&target_type=deb_network
  • https://forums.developer.nvidia.com/t/we-would-like-to-know-when-the-nvidia-drivers-for-5060ti-on-ubuntu-will-be-released/331207
  • https://forums.developer.nvidia.com/t/nvidia-drivers-not-working-while-secure-boot-is-enabled-after-updating-to-ubuntu-24-04/305351/6?u=kiceyscream
  • https://forums.developer.nvidia.com/t/could-not-select-device-driver-with-capabilities-gpu/80200
  • https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

Fix the Electron Fiddle issue about user namespace privileges on ubuntu 24.04

If you install Electron Fiddle on Ubuntu 24.04. Then want to run a Fiddle, you will get errors like

The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /home/aadcg/.config/Electron Fiddle/electron-bin/current/chrome-sandbox is owned by root and has mode 4755.
or

LaunchProcess: failed to execvp:
/home/kicey/.config/Electron
[62772:0524/190051.235193:FATAL:zygote_host_impl_linux.cc(211)] Check failed: . : Invalid argument (22) 

This is because Ubuntu has changed the Ubuntu 24.04 kernel so that programs like electron are not allowed to create a new user namespace unless they are given an AppArmor profile that contains the userns permission.

To fix this, you need to grant the privilege to the executable by create an apparmor profile. Execute the following commands (maybe sudo needed):

echo 'abi <abi/4.0>,
include <tunables/global>
profile fiddle-electron /home/'$USER'/.config/Electron\ Fiddle/electron-bin/current/electron flags=(unconfined) {
    userns,
}' > /etc/apparmor.d/fiddle-electron
apparmor_parser -r /etc/apparmor.d/fiddle-electron
systemctl reload apparmor

For mote information, you can refer to the electron/fiddle SIGTRAP error on Ubuntu #1598