Add nvidia.sh

This commit is contained in:
aadit 2025-06-10 13:42:15 +05:30
parent 7bdbe85913
commit 62b4efebd9

67
nvidia.sh Normal file
View file

@ -0,0 +1,67 @@
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- 1. NVIDIA Graphics Driver Installation ---
echo "▶️ Section 1: Installing NVIDIA Graphics Driver..."
echo " This will automatically detect and install the recommended driver."
sudo apt update
sudo ubuntu-drivers autoinstall
echo "✅ NVIDIA driver installation command issued."
echo " A reboot will be required later for it to take effect."
# --- 2. CUDA Toolkit Installation ---
echo "▶️ Section 2: Setting up and Installing CUDA Toolkit..."
# Clean up any previous attempts to avoid conflicts
rm -f cuda-keyring_*.deb
# Set up the NVIDIA CUDA repository
# These commands are for x86_64 architecture on Ubuntu 22.04 (which ZorinOS 17 is based on)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
# Clean up the downloaded deb file
rm -f cuda-keyring_1.1-1_all.deb
echo "▶️ Installing the CUDA Toolkit (this includes cuBLAS)..."
# The 'cuda' package installs the latest stable version.
sudo apt-get install -y cuda
# --- 3. cuDNN Library Installation ---
echo "▶️ Section 3: Installing cuDNN Library..."
# These packages provide the runtime and developer libraries for cuDNN
sudo apt-get install -y libcudnn8 libcudnn8-dev
echo "✅ CUDA and cuDNN have been installed."
# --- 4. Environment Configuration ---
echo "▶️ Section 4: Configuring environment variables in ~/.bashrc..."
# Check if the CUDA paths are already in .bashrc to avoid duplicates
if ! grep -q 'export PATH=/usr/local/cuda/bin' ~/.bashrc; then
echo '' >>~/.bashrc
echo '# Add NVIDIA CUDA Toolkit to PATH' >>~/.bashrc
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
echo "✅ CUDA environment variables added to ~/.bashrc."
else
echo "✅ CUDA environment variables already configured in ~/.bashrc."
fi
# --- 5. Final Instructions ---
echo ""
echo "------------------------------------------------------------------"
echo "🎉 NVIDIA Stack Installation Complete!"
echo ""
echo " IMPORTANT: You MUST reboot your system for the new NVIDIA"
echo " driver to be loaded correctly."
echo ""
echo " After rebooting, open a new terminal for all changes to take"
echo " effect. You can verify the installation by running:"
echo " nvidia-smi"
echo " nvcc --version"
echo "------------------------------------------------------------------"