In this guide we setup Nvidia CUDA in a toolbox container. This guide is applicable for:
Red Hat Enterprise Linux >= 8., 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.Before proceeding, it is advisable to check if NVIDIA has updated their CUDA repositories for your Fedora version. NVIDIA's repositories can be found at:
As of the latest update, these repositories do not contain the cuda meta-package or are missing essential components.
Since the newer repositories are incomplete, we'll use the Fedora 39 repository:
Note: Fedora 39 is no longer maintained, so 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 a Fedora 39 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.
We do not recommend installing on the host system, as Fedora 39 is out-of-maintenance, and instead you should upgrade to a maintained version of Fedora for your host.
Create a Fedora 39 Toolbox:
toolbox create --image registry.fedoraproject.org/fedora-toolbox:39 --container fedora-toolbox-39-cuda
Enter the Toolbox:
toolbox enter --container fedora-toolbox-39-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 resolves any package conflicts.
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 --add-repo https://developer.download.nvidia.com/compute/cuda/repos/fedora39/x86_64/cuda-fedora39.repo
After adding the repository, synchronize the package manager again:
sudo dnf distro-sync
nvidia-driver-libsAttempt to install nvidia-driver-libs:
sudo dnf install nvidia-driver-libs
Explanation:
nvidia-driver-libs contains necessary NVIDIA driver libraries required by CUDA.If the installation fails due to conflicts, we'll manually download and install the required packages, excluding conflicting files.
nvidia-driver-libs RPMsudo dnf download --arch x86_64 nvidia-driver-libs
You should see a file similar to:
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
sudo dnf install nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
Expected Error:
Installation may fail with errors pointing to conflicts with egl-gbm and egl-wayland.
Note: It is important to carefully read the error messages to identify the exact paths that need to be excluded.
sudo dnf download --arch x86_64 egl-gbm egl-wayland
egl-gbm with Excluded PathsExclude conflicting files during installation:
sudo rpm --install --verbose --hash \
--excludepath=/usr/lib64/libnvidia-egl-gbm.so.1.1.2 \
--excludepath=/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json \
egl-gbm-1.1.2^20240919gitb24587d-3.fc39.x86_64.rpm
Explanation:
--excludepath option skips installing files that conflict with existing files.egl-wayland with Excluded Pathssudo rpm --install --verbose --hash \
--excludepath=/usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json \
egl-wayland-1.1.17^20241118giteeb29e1-5.fc39.x86_64.rpm
nvidia-driver-libs with Excluded Pathssudo rpm --install --verbose --hash \
--excludepath=/usr/share/glvnd/egl_vendor.d/10_nvidia.json \
--excludepath=/usr/share/nvidia/nvoptix.bin \
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
Note:
--verbose and --hash options provide detailed output during installation.nvidia-driver-libsAfter manually installing the dependencies, run:
sudo dnf install nvidia-driver-libs
You should receive a message indicating the package is already installed:
Package nvidia-driver-libs-3:560.35.05-1.fc39.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
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-2024 NVIDIA Corporation
Built on Tue_Oct_29_23:50:19_PDT_2024
Cuda compilation tools, release 12.6, V12.6.85
Build cuda_12.6.r12.6/compiler.35059454_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 39 CUDA repository. By manually resolving package conflicts 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 installations.Driver Conflicts:
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.