-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_cuda.sh
More file actions
executable file
·60 lines (47 loc) · 1.76 KB
/
install_cuda.sh
File metadata and controls
executable file
·60 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Install CUDA 12.x on Pop!_OS 22.04 / Ubuntu 22.04
set -e
echo "Setting up NVIDIA CUDA repository..."
# Wait for PackageKit to release the lock
echo "Waiting for package management to become available..."
while fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
echo "Another package manager is running. Waiting..."
sleep 5
done
# Stop PackageKit temporarily to prevent interference
if systemctl is-active --quiet packagekit 2>/dev/null; then
echo "Stopping PackageKit service temporarily..."
sudo systemctl stop packagekit || true
fi
# Install dependencies
sudo apt update
sudo apt install -y software-properties-common wget
# Add NVIDIA package repository
KEYRING_DEB="cuda-keyring_1.1-1_all.deb"
if [ -f "$KEYRING_DEB" ]; then
rm -f "$KEYRING_DEB"
fi
wget -q https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
# Wait for lock again before dpkg
while fuser /var/lib/dpkg/lock-frontend > /dev/null 2>&1; do
echo "Waiting for dpkg lock..."
sleep 2
done
sudo dpkg -i cuda-keyring_1.1-1_all.deb
rm -f cuda-keyring_1.1-1_all.deb
# Update package lists
sudo apt update
# Install CUDA toolkit (latest version)
echo "Installing CUDA toolkit..."
sudo apt install -y cuda-toolkit
# Add CUDA to PATH
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
echo "CUDA installation complete!"
echo "Please log out and log back in, or run: source ~/.bashrc"
echo "Verify with: nvcc --version"
# Restart PackageKit service
if systemctl is-enabled --quiet packagekit 2>/dev/null; then
echo "Restarting PackageKit service..."
sudo systemctl start packagekit || true
fi