Update nvidia.sh
This commit is contained in:
parent
f846f8d6a3
commit
970c376ad6
1 changed files with 34 additions and 50 deletions
84
nvidia.sh
84
nvidia.sh
|
@ -1,67 +1,51 @@
|
|||
#!/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.
|
||||
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 "Starting NVIDIA tools installation..."
|
||||
|
||||
echo "✅ NVIDIA driver installation command issued."
|
||||
echo " A reboot will be required later for it to take effect."
|
||||
# Part 1: Install CUDA Toolkit and NVIDIA Drivers
|
||||
|
||||
# --- 2. CUDA Toolkit Installation ---
|
||||
echo "▶️ Section 2: Setting up and Installing CUDA Toolkit..."
|
||||
echo "Setting up CUDA repository pin..."
|
||||
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
|
||||
rm -f cuda-keyring_*.deb
|
||||
echo "Downloading and installing CUDA repository..."
|
||||
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
|
||||
# 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
|
||||
echo "Copying CUDA keyring..."
|
||||
sudo cp /var/cuda-repo-ubuntu2204-12-9-local/cuda-*-keyring.gpg /usr/share/keyrings/
|
||||
|
||||
echo "Updating package list..."
|
||||
sudo apt-get update
|
||||
|
||||
# Clean up the downloaded deb file
|
||||
rm -f cuda-keyring_1.1-1_all.deb
|
||||
echo "Installing CUDA Toolkit 12.9..."
|
||||
sudo apt-get -y install cuda-toolkit-12-9
|
||||
|
||||
echo "▶️ Installing the CUDA Toolkit (this includes cuBLAS)..."
|
||||
# The 'cuda' package installs the latest stable version.
|
||||
sudo apt-get install -y cuda
|
||||
echo "Installing NVIDIA open drivers..."
|
||||
sudo apt-get install -y nvidia-open
|
||||
|
||||
# --- 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
|
||||
# Part 2: Install cuDNN
|
||||
|
||||
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 "▶️ Section 4: Configuring environment variables in ~/.bashrc..."
|
||||
echo "Copying cuDNN keyring..."
|
||||
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
|
||||
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
|
||||
echo "Updating package list again..."
|
||||
sudo apt-get update
|
||||
|
||||
# --- 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 "------------------------------------------------------------------"
|
||||
echo "Installing cuDNN..."
|
||||
sudo apt-get -y install cudnn
|
||||
sudo apt-get -y install cudnn-cuda-12
|
||||
|
||||
echo "NVIDIA tools installation completed successfully!"
|
||||
echo "It is recommended to reboot your system to ensure all changes take effect."
|
Loading…
Add table
Add a link
Reference in a new issue