EDIT: I have added a new answer below for Ubuntu 20.04 LTS and CUDA 11.1.1. See below.
I have a system with a NVIDIA card that has a compute support of 3.5+ compared on https://developer.nvidia.com/cuda-gpus. How do I install CUDA and the NVIDIA drivers in Ubuntu without downloading the .deb files from NVIDIA?
Ubuntu 18.04, CUDA 10.1, libcudnn 7.5.1 and NVIDIA 418.67 drivers
Notes
2021-01-07: Please use the 20.04 installation below moving forward as the steps are the same for both 18.04 and 20.04.
2019-06-23: Recent updates with either the CUDA 10.0 or 10.1 versions the NVIDIA 418.67 driver, that installs with it, no longer has the 32bit libraries included and this will cause Steam and most games to no longer work. The version of
libnvidia-gl-418:i386
only installs the 418.56 version which will not work with the 418.67 driver. Hopefully NVIDIA will release an update for that soon. I have added the info at the bottom of this answer in the.run file install
part of how to download just the run file for the CUDA installer then you can use whatever driver you want. The run file is 2.3GB in size, so it might take a bit to download.CUDA 9.x is not available through NVIDIA's ubuntu1804 repo. I did however write an answer for CUDA 9.2 at https://askubuntu.com/a/1086993/231142
Installing CUDA through the repository (instead of the
.deb
installation)The following lines you can copy and paste to a terminal window. Press Ctrl+Alt+T to open a terminal window.
Remove and update
Remove any CUDA PPAs that may be setup and also remove the
nvidia-cuda-toolkit
if installed:Recommended to also remove all NVIDIA drivers before installing new drivers:
Then update the system:
Add and install
Recently, I just found out that the CUDA installation works with the
graphics-drivers ppa
so if you don't have it added, add it now:The install the NVIDIA driver. For this we are going to use the 440 driver
Now, install the key:
Add the repos:
Update the system again:
Install CUDA 10.1:
It should be installing the NVIDIA 418.40 drivers with it as those are what are listed in the repo. See: http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/
Install libcudnn7 7.5.1:
Tune environment and reboot
Add the following lines to your
~/.profile
file for CUDA 10.1Reboot your computer.
Check your settings
Check NVIDIA Cuda Compiler with
nvcc --version
:Check libcudnn version
/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
:Check NVIDIA driver with
nvidia-smi
:.run
file installInstall driver
By using the
sudo add-apt-repository ppa:graphics-drivers/ppa
you can install the430.26
newest driver or any that suit your fancy.Install libcudnn7
Add the Repo:
Install the key:
Update the system:
Install libcudnn7.5.1:
Download the
.run
fileNow download the
cuda_10.1.105_418.39_linux.run
from https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocalIf you want CUDA 10.2 the download instructions are here: https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal Then follow through with the same steps as below but make sure to update to 10.2 instead of 10.1.
Then run the installer:
Type in accept and press enter on this screen:
Unselect the driver and then choose Install by using the arrow keys and space bar to move and select or unselect:
Wait for the install to finish, it might say errors during, but not to worry.
Tune environment and reboot
Add the following lines to your
~/.profile
file for CUDA 10.1Reboot the system for the changes to take effect.
Ubuntu 20.04 LTS, CUDA 11.5.0, NVIDIA 495 and libcudnn 8.0.4
I don't recommend installing the NVIDIA drivers that come with CUDA as they do not contain the dkms drivers that carry over into new kernel upgrades.
The Ubuntu repositories now contain the same drivers as the
graphics-drivers
PPA. So feel free to install the495.44
drivers.Reboot the system so the new driver takes effect.
Now, download the CUDA 11.5.0 .run file from NVIDIA:
Run the
.run
file assudo
:If you get the following, just choose
Continue
:Accept the EULA:
Unselect the video driver by pressing the spacebar while
[X] Driver
is highlighted:Then press the down arrow to
Install
. Press Enter then wait for installation to complete.After the installation is complete add the following to the bottom of your
~/.profile
or add it to the/etc/profile.d/cuda.sh
file which you might have to create for all users (global):Install libcudnn8
Add the Repo:
NOTE: The 20.04 repo from NVIDIA does not supply libcudnn but the 18.04 repo does and installs just fine into 20.04.
Install the key:
Update the system:
Install libcudnn 8.0.4:
I recommend now to reboot the system for the changes to take effect.
After it reboots check the installations:
and check CUDA install:
and check libcudnn install:
I just want to add an alternative solution that ends up being much easier and modular, IMHO: use Nvidia's CUDA docker images!
This does require a working (proprietary) driver on the host machine, which can be installed from Ubuntu repos (
nvidia-driver-470
is the final supported driver version for CUDA compute 3.5).sudo apt install nvidia-driver-470
nvidia-docker2
. See this guide from Nvidia; if you're running Ubuntu 21+ you'll want to replace$distribution
withubuntu2004
in this step.nvidia-smi
, which will show the same output you get from runningnvidia-smi
NOT inside of Docker.For anyone working with AWS deep learning base AMI:
The image comes with several NVIDIA CUDA environments built-in and by default works with one of them (in my case 10), but you can switch to any other, simply by changing the symlink:
More info:
https://docs.aws.amazon.com/dlami/latest/devguide/tutorial-base.html
Don't make a mistake.
Download the .deb file once and for ever.
I downloaded the .run file and installed it. But, once I tried installing tensorrt, it turned out that it could not be installed with it.
I could only install it after a .deb nvidia driver have been installed.