In this guide we setup Nvidia CUDA in a toolbox container. This guide is applicable for:
Red Hat Enterprise Linux >= 8.5, Arch Linux, and Ubuntu.nvidia-driver-libsnvidia-driver-libsFedora Silverblue and Fedora Workstation both have toolbox by default, other distributions may need to install the toolbox package.llama.cpp, the host should be setup to access your NVIDIA hardware. Fedora Hosts can use the RPM Fusion Repository.The latest release is 41.
Note: We recommend using a toolbox environment to prevent system conflicts.
This guide focuses on Fedora hosts, but with small adjustments, it can work for other hosts. Using the Fedora Toolbox allows us to install the necessary packages without affecting the host system.
Note: Toolbox is available for other systems, and even without Toolbox, it is possible to use Podman or Docker.
Create a Fedora 41 Toolbox:
toolbox create --image registry.fedoraproject.org/fedora-toolbox:41 --container fedora-toolbox-41-cuda
Enter the Toolbox:
toolbox enter --container fedora-toolbox-41-cuda
Inside the toolbox, you have root privileges and can install packages without affecting the host system.
Synchronize the DNF Package Manager:
sudo dnf distro-sync
Install the Default Text Editor (Optional):
sudo dnf install vim-default-editor --allowerasing
The --allowerasing flag will allow the removal of the conflicting nano-default-editor package.
Install Development Tools and Libraries:
sudo dnf install @c-development @development-tools cmake
This installs essential packages for compiling software, including gcc, make, and other development headers.
Add the NVIDIA CUDA repository to your DNF configuration:
sudo dnf config-manager addrepo --from-repofile=https://developer.download.nvidia.com/compute/cuda/repos/fedora41/x86_64/cuda-fedora41.repo
After adding the repository, synchronize the package manager again:
sudo dnf distro-sync
nvidia-driver-libs and nvidia-driver-cuda-libsWe need to detect if the host is supplying the NVIDIA driver libraries into the toolbox.
ls -la /usr/lib64/libcuda.so.1
Explanation:
nvidia-driver-libs and nvidia-driver-cuda-libs contains necessary NVIDIA driver libraries required by CUDA,
on hosts with NVIDIA drivers installed the Fedora Container will supply the host libraries.libcuda.so.1 was NOT found).sudo dnf install nvidia-driver-libs nvidia-driver-cuda-libs
libcuda.so.1 was found).If the installation fails due to conflicts, we'll manually download and install the required packages, excluding conflicting files.
nvidia-driver-libs and nvidia-driver-cuda-libs RPM's (with dependencies)sudo dnf download --destdir=/tmp/nvidia-driver-libs --resolve --arch x86_64 nvidia-driver-libs nvidia-driver-cuda-libs
sudo rpm --install --verbose --hash --justdb /tmp/nvidia-driver-libs/*
Note:
--justdb option only updates the RPM database, without touching the filesystem.nvidia-driver-libs and nvidia-driver-cuda-libsAfter manually installing the dependencies, run:
sudo dnf install nvidia-driver-libs nvidia-driver-cuda-libs
You should receive a message indicating the package is already installed:
Updating and loading repositories:
Repositories loaded.
Package "nvidia-driver-libs-3:570.86.10-1.fc41.x86_64" is already installed.
Package "nvidia-driver-cuda-libs-3:570.86.10-1.fc41.x86_64" is already installed.
Nothing to do.
Now that the driver libraries are installed, proceed to install CUDA:
sudo dnf install cuda
This installs the CUDA toolkit and associated packages.
To use CUDA, add its binary directory to your system's PATH.
Create a Profile Script:
sudo sh -c 'echo "export PATH=\$PATH:/usr/local/cuda/bin" >> /etc/profile.d/cuda.sh'
Explanation:
/etc/profile.d/ as the /etc/ folder is unique to this particular container, and is not shared with other containers or the host system.\ before $PATH ensures the variable is correctly written into the script.Make the Script Executable:
sudo chmod +x /etc/profile.d/cuda.sh
Source the Script to Update Your Environment:
source /etc/profile.d/cuda.sh
Note: This command updates your current shell session with the new PATH. The /etc/profile.d/cuda.sh script ensures that the CUDA binaries are available in your PATH for all future sessions.
To confirm that CUDA is correctly installed and configured, check the version of the NVIDIA CUDA Compiler (nvcc):
nvcc --version
You should see output similar to:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Jan_15_19:20:09_PST_2025
Cuda compilation tools, release 12.8, V12.8.61
Build cuda_12.8.r12.8/compiler.35404655_0
This output confirms that the CUDA compiler is accessible and indicates the installed version.
You have successfully set up CUDA on Fedora within a toolbox environment using the Fedora 41 CUDA repository. By manually updating the RPM db and configuring the environment, you can develop CUDA applications without affecting your host system.
Installation Failures:
--excludepath option with rpm to exclude conflicting files during manual RPM installations.Rebooting the Container:
Sometimes there may be a bug in the NVIDIA driver host passthrough (such as missing a shared library). Rebooting the container may solve this issue:
# on the host system
podman container restart --all
Environment Variables Not Set:
nvcc is not found after installation, ensure that /usr/local/cuda/bin is in your PATH.echo $PATH to check if the path is included.Updating CUDA in the Future:
dnf configuration accordingly.Building llama.cpp:
llama.cpp to compile it with CUDA support.Using the Toolbox Environment:
Disclaimer: Manually installing and modifying system packages can lead to instability of the container. The above steps are provided as a guideline and may need adjustments based on your specific system configuration. Always back up important data before making significant system changes, especially as your home folder is writable and shared with he toolbox.
Acknowledgments: Special thanks to the Fedora community and NVIDIA documentation for providing resources that assisted in creating this guide.