Skip to content

Instantly share code, notes, and snippets.

@DaneGardner
Last active February 7, 2024 23:15
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save DaneGardner/accd6fd330348543167719002a661bd5 to your computer and use it in GitHub Desktop.
Save DaneGardner/accd6fd330348543167719002a661bd5 to your computer and use it in GitHub Desktop.
Installing CUDA 9.1 on Ubuntu 18.04 (circ. 5/18)

Install CUDA 9.1 on Ubuntu 18.04

Prep system

sudo apt install build-essential gcc-6 g++-6

sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 20
sudo update-alternatives --set gcc /usr/bin/gcc-6

sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 20
sudo update-alternatives --set g++ /usr/bin/g++-6

Install Nvidia driver

sudo modprobe -r nouveau
sudo apt install nvidia-driver-390 nvidia-headless-390 nvidia-utils-390
sudo modprobe -i nvidia

Install CUDA toolkit

pushd /tmp/

curl -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux
curl -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/1/cuda_9.1.85.1_linux
curl -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/2/cuda_9.1.85.2_linux
curl -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/3/cuda_9.1.85.3_linux

# do not install driver or samples
sudo sh cuda_9.1.85_387.26_linux --silent --override --toolkit

# install the patches
sudo sh cuda_9.1.85.1_linux --silent --accept-eula
sudo sh cuda_9.1.85.2_linux --silent --accept-eula
sudo sh cuda_9.1.85.3_linux --silent --accept-eula

# set system wide paths
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda/bin"' | sudo tee /etc/environment
echo /usr/local/cuda-9.1/lib64 | sudo tee /etc/ld.so.conf.d/cuda-9.1.conf
sudo ldconfig

rm /tmp/cuda_9.1.85*_linux
popd

Check that it's working

# reboot system for changes to take effect
sudo reboot

lsmod | grep nouv && echo FAIL || echo OKAY
lsmod | grep nvid && echo OKAY || echo FAIL

grep -E 'NVIDIA.*390.[0-9]+' /proc/driver/nvidia/version &>/dev/null && echo OKAY || echo FAIL
nvcc -V | grep -E "V9.1.[0-9]+" &>/dev/null && echo OKAY || echo FAIL

# this should return stats for all installed cards
nvidia-smi

Optional Fans Speed Settings

sudo apt install xorg lightdm

# reconfigure Xorg server for installed devices
/usr/sbin/service lightdm stop
/usr/bin/nvidia-xconfig -a --cool-bits=12 --allow-empty-initial-configuration --preserve-busid --no-allow-glx-with-composite --no-add-argb-glx-visuals
/usr/sbin/service lightdm start
/usr/sbin/service lightdm status

export DISPLAY=:0
export XAUTHORITY=/var/run/lightdm/root/${DISPLAY}
/usr/bin/nvidia-settings -a GPUFanControlState=1 -a GPUTargetFanSpeed=75
@pacman-admin
Copy link

pacman-admin commented Feb 4, 2024

This is probably the best:

curl -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux & curl -LO -LO -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/1/cuda_9.1.85.1_linux https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/2/cuda_9.1.85.2_linux https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/3/cuda_9.1.85.3_linux && fg

@pacman-admin
Copy link

Gcc 6 is not installable anymore.
brew install gcc@7 is the only choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment