Update nvidia.sh

This commit is contained in:
aadit 2025-06-11 09:41:49 +05:30
parent f846f8d6a3
commit 970c376ad6

View file

@ -1,67 +1,51 @@
#!/bin/bash #!/bin/bash
# This script installs NVIDIA CUDA Toolkit, NVIDIA drivers, and cuDNN.
# It is intended for Ubuntu 22.04.
# Run this script with sudo privileges: sudo ./nvidia.sh
# Exit immediately if a command exits with a non-zero status. # Exit immediately if a command exits with a non-zero status.
set -e set -e
# --- 1. NVIDIA Graphics Driver Installation --- echo "Starting NVIDIA tools 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." # Part 1: Install CUDA Toolkit and NVIDIA Drivers
echo " A reboot will be required later for it to take effect."
# --- 2. CUDA Toolkit Installation --- echo "Setting up CUDA repository pin..."
echo "▶️ Section 2: Setting up and Installing CUDA Toolkit..." wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
# Clean up any previous attempts to avoid conflicts echo "Downloading and installing CUDA repository..."
rm -f cuda-keyring_*.deb wget https://developer.download.nvidia.com/compute/cuda/12.9.1/local_installers/cuda-repo-ubuntu2204-12-9-local_12.9.1-575.57.08-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-9-local_12.9.1-575.57.08-1_amd64.deb
# Set up the NVIDIA CUDA repository echo "Copying CUDA keyring..."
# These commands are for x86_64 architecture on Ubuntu 22.04 (which ZorinOS 17 is based on) sudo cp /var/cuda-repo-ubuntu2204-12-9-local/cuda-*-keyring.gpg /usr/share/keyrings/
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 echo "Updating package list..."
sudo apt-get update sudo apt-get update
# Clean up the downloaded deb file echo "Installing CUDA Toolkit 12.9..."
rm -f cuda-keyring_1.1-1_all.deb sudo apt-get -y install cuda-toolkit-12-9
echo "▶️ Installing the CUDA Toolkit (this includes cuBLAS)..." echo "Installing NVIDIA open drivers..."
# The 'cuda' package installs the latest stable version. sudo apt-get install -y nvidia-open
sudo apt-get install -y cuda
# --- 3. cuDNN Library Installation --- # Part 2: Install cuDNN
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." echo "Downloading and installing cuDNN repository..."
wget https://developer.download.nvidia.com/compute/cudnn/9.10.2/local_installers/cudnn-local-repo-ubuntu2204-9.10.2_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2204-9.10.2_1.0-1_amd64.deb
# --- 4. Environment Configuration --- echo "Copying cuDNN keyring..."
echo "▶️ Section 4: Configuring environment variables in ~/.bashrc..." sudo cp /var/cudnn-local-repo-ubuntu2204-9.10.2/cudnn-*-keyring.gpg /usr/share/keyrings/
# Check if the CUDA paths are already in .bashrc to avoid duplicates echo "Updating package list again..."
if ! grep -q 'export PATH=/usr/local/cuda/bin' ~/.bashrc; then sudo apt-get update
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 "Installing cuDNN..."
echo "" sudo apt-get -y install cudnn
echo "------------------------------------------------------------------" sudo apt-get -y install cudnn-cuda-12
echo "🎉 NVIDIA Stack Installation Complete!"
echo "" echo "NVIDIA tools installation completed successfully!"
echo " IMPORTANT: You MUST reboot your system for the new NVIDIA" echo "It is recommended to reboot your system to ensure all changes take effect."
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 "------------------------------------------------------------------"