Skip to content

Instantly share code, notes, and snippets.

@DaneGardner
Last active February 25, 2025 14:22
Show Gist options
  • 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
@leeivan
Copy link

leeivan commented Jul 26, 2019

sudo update-alternatives --set g++ /usr/bin/g++-6

@DaneGardner
Copy link
Author

@leeivan fixed. Thank you!

@yashkatta
Copy link

@DaneGardner Nicely explained! Thanks.

@DavidTorresOcana
Copy link

Thank you!

@rxgraham
Copy link

@DaneGardner, thank you for this distillation!

@Kritias
Copy link

Kritias commented Feb 10, 2020

How to fix this error?
CUDA error: no kernel image is available for execution on the device

@chutch3
Copy link

chutch3 commented Apr 19, 2020

This was super helpful. Thanks!

@nyierr
Copy link

nyierr commented Jun 2, 2020

Thank you very much! Super helpful and easy to follow!

@ily-R
Copy link

ily-R commented Dec 9, 2020

Not related to this steps specifically, but maybe somone has an idea. I have already everything install before, but I think there are conflicts. I tried to build the apex repo from nvidia for example but I get the error error: command '/usr/bin/nvcc' failed with exit status 1

Here's my setting:

cudatoolkit: 10.0.130
Pytorch: 1.4.0
Python: 3.6.9
GCC: 7.3.0
$which gcc
/usr/bin/gcc
$which nvcc
/usr/bin/nvcc
$nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
$which g++
/usr/bin/g++
$which make
/usr/bin/make
vendor   : NVIDIA Corporation
model    : GP107M [GeForce GTX 1050 Mobile]
driver   : nvidia-driver-450
$nvidia-smi
 NVIDIA-SMI 450.80.02    Driver Version: 450.80.02    CUDA Version: 11.0  

nvidia-smi shows cuda version of 11.0, nvcc -V gives 9.1 and I am using 10.0 from PyTorch. Maybe I got the wrong driver ?
Also I see that the path of nvcc is /usr/bin/nvcc souldnt it be something like this /usr/cuda/bin/nvcc

Any ideas on the source of this error error: command '/usr/bin/nvcc' failed with exit status 1 ?

Thank you

@MarioCiranni
Copy link

Installation on Ubuntu 20.04 worked just fine as well!

@DaneGardner
Copy link
Author

Installation on Ubuntu 20.04 worked just fine as well!

@MarioCiranni, great to hear! Glad this is still helping folks all these years later.

@AdrienPoupa
Copy link

Still working with Nvidia 390 on Ubuntu 22.04, thanks!

@michailtam
Copy link

michailtam commented Jul 15, 2023

I can also confirm that this solution works on Ubuntu LTS 20.04. Awesome work!!

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

And the Nvidia GPU driver output:

$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.157 Driver Version: 390.157 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 860M Off | 00000000:01:00.0 Off | N/A |
| N/A 52C P8 N/A / N/A | 334MiB / 2004MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1472 G /usr/lib/xorg/Xorg 37MiB |
| 0 2532 G /usr/lib/xorg/Xorg 85MiB |
| 0 2702 G /usr/bin/gnome-shell 94MiB |
| 0 5456 G ...81293700609,17841800481584127892,131072 105MiB |
+-----------------------------------------------------------------------------+

@pacman-admin
Copy link

pacman-admin commented Feb 4, 2024

pushd /tmp/

curl -LO -LO -LO -LO https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux 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

# 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

This downloads all files in one line.
cURL might be faster like this.

@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.

@pcamp96
Copy link

pcamp96 commented Feb 25, 2025

Any chance of this working on 24.04? Trying to get my Quadro P4000 working in Ubuntu 24.04 to use for Plex transcoding and, well, it's not too happy without CUDA.

@DaneGardner
Copy link
Author

Any chance of this working on 24.04? Trying to get my Quadro P4000 working in Ubuntu 24.04 to use for Plex transcoding and, well, it's not too happy without CUDA.

If Plex will work with such an old version of CUDA, it might be worth trying if you can't get newer versions working. Let us know how it goes if you give it a try!

@pcamp96
Copy link

pcamp96 commented Feb 25, 2025

Any chance of this working on 24.04? Trying to get my Quadro P4000 working in Ubuntu 24.04 to use for Plex transcoding and, well, it's not too happy without CUDA.

If Plex will work with such an old version of CUDA, it might be worth trying if you can't get newer versions working. Let us know how it goes if you give it a try!

I spent the better part of 6+ hours yesterday trying to get it to work and I couldn't get CUDA to properly install on the system. I was able to get the 390 drivers working, and nvidia-smi showed the card, but without CUDA or the toolkit installed it was all but useless on the system.

I'm gonna end up selling the P4000 and going with the GTX 1650 that I have in another system instead. It has more modern drivers and should more easily work.

Thanks for the reply though! I wished I could have got the P4000 working, it would have been killer for Plex transcoding lol.

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