Installing CUDA Library in Ubuntu 18.04

Atinesh
3 min readJan 25, 2021

--

Nvidia CUDA (Source)

In this blog, I will demonstrate how to install CUDA 10.0 library in Ubuntu 18.04

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

Step 1: Install Nvidia GPU driver
Make sure to install the latest Nvidia driver or compatible Nvidia driver for CUDA 10.0. You can check which Nvidia driver is compatible with CUDA 10.0 from here

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

Restart the machine and check if Nvidia drivers are successfully installed by issuing the following command

$ 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

Step 2: Download CUDA 10.0 library and Patch runfile installer from here by selecting the following options

Step 3: Install CUDA library by running the following command

$ sudo sh cuda_10.0.130_410.48_linux.run

Press and hold ENTER to read the license until 100% and choose the following options

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

If the installation is successful then CUDA will be installed at this path /usr/local/cuda-10.0

Step 4: Install Patches by running the following command

$ 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

Step 5: Download cuDNN for cuda CUDA 10.0 from here, you will have to create an Nvidia developer account to download the files

Step 6: Install cuDNN
Unpack the archive

$ tar -zxvf cudnn-10.0-linux-x64-v7.6.5.32.tgz

Copy the unpacked contents to your CUDA directory

$ sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64/
$ sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include/

Give read access to all users

$ 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

Step 7: Setup CUDA path by adding the following lines at the end of ~/.bashrc file

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}}

Reload bashrc file

$ source ~/.bashrc

Step 8: Check if CUDA is successfully installed

$ 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

Removing CUDA Library:
If you wish to remove the CUDA Library for some reason then remove CUDA paths from ~/.bashrc file and issue the following commands

$ sudo /usr/local/cuda-10.0/bin/uninstall_cuda_10.0.pl
$ sudo rm -r /usr/local/cuda-10.0

Thank you for reading this post, If you like it then please clap and share it on Facebook, LinkedIn or Twitter so that other people get benefits from it.

You can follow me on Github, LinkedIn or contact me at atinesh.s@gmail.com

Happy Coding!

--

--