Installing CUDA Library in Ubuntu 18.04

Nvidia CUDA (Source)

Note: The process mentioned here should work for other versions of the CUDA library and should also work for other versions of the Ubuntu Operating System

$ sudo add-apt-repository ppa:graphics-drivers
$ sudo apt-get update
$ sudo apt-get install nvidia-driver-450
$ nvidia-smi

Note: Don’t panic by seeing CUDA 11.0 (or other CUDA version) at the top right corner in the above output. It does not represent CUDA installed in the system, there is another command to check the CUDA version installed in the system I will show it later

$ sudo sh cuda_10.0.130_410.48_linux.run
Do you accept the previously read EULA?
accept/decline/quit: accept
You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: y
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n
Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-10.0 ]: ENTER
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: n

Note: We are not installing the Nvidia driver provided by Installer because generally in Installer older GPU drivers are present and we should always use the latest drivers

$ sudo sh cuda_10.0.130.1_linux.runDo you accept the previously read EULA?
accept/decline/quit: accept
Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-10.0 ]: ENTER
$ tar -zxvf cudnn-10.0-linux-x64-v7.6.5.32.tgz
$ sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64/
$ sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include/
$ sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Note: Here I am Installing cuDNN 7.6.5 but you can install other versions of your choice

export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
$ source ~/.bashrc
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright © 2005–2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
$ sudo /usr/local/cuda-10.0/bin/uninstall_cuda_10.0.pl
$ sudo rm -r /usr/local/cuda-10.0

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store