How to Install Nvidia CUDA Toolkit on Ubuntu 18.04 LTS
Cuda is a parallel computing platform created by Nvidia that can be used to increase performance by harnessing the power of the graphics processing unit (GPU) on your system. Cuda is a software layer that allows software developers to access the GPU's virtual instruction set and parallel computational elements, for the execution of compute kernels.
In this tutorial, we will learn how to install Cuda on Ubuntu 18.04.
- Ubuntu 18.04 desktop installed to your system.
- A non-root user with sudo privileges.
Before starting, you will need to verify that your GPU can work with CUDA or not. You can verify it using the following command:
lspci | grep NVIDIA
You should see the following output:
01:00.0 3D controller: NVIDIA Corporation GM206M [GeForce GTX 965M] (rev a1)
Next, you will also need to install gcc, nvidia driver, kernel headers and development packages to your system. You can install them by just running the following command:
sudo apt-get install gcc-6 g++-6 linux-headers-$(uname -r) nvidia-384 -y
Once all the packages are installed, you can proceed to the next step.
Install NVIDIA CUDA Toolkit
First, you will need to download the latest version of the CUDA Toolkit to your system. The CUDA Toolkit contains the CUDA driver and tools needed to create, build and run a CUDA application.
You can download it using the following command:
wget -c https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda_9.2.88_396.26_linux
Once the download is completed, you can install it with the following command:
sudo chmod +x cuda_9.2.88_396.26_linux.run
sudo ./cuda_9.2.88_396.26_linux.run --verbose --silent --toolkit --override
Once the installation is completed succesfully, you should see the following output:
=========== = Summary = =========== Toolkit: Installed in /usr/local/cuda-9.2 Samples: Not Selected Please make sure that - PATH includes /usr/local/cuda-9.2/bin - LD_LIBRARY_PATH includes /usr/local/cuda-9.2/lib64, or, add /usr/local/cuda-9.2/lib64 to /etc/ld.so.conf and run ldconfig as root
Next, you will need to add the Cuda binary file path to your .bashrc file. You can do this with the following command:
Add the following line at the end of the file:
Save and close the file.
Next, verify the Cuda library path using the following command:
sudo echo "/usr/local/cuda-9.2/lib64" >> /etc/ld.so.conf
It is recommended to go to the Nvidia site and check for available patches. If you found any patches, then download it and install it. You can do this with the following command:
sudo chmod +x cuda_220.127.116.11_linux.run
sudo ./cuda_18.104.22.168_linux.run --silent --accept-eula
Once the patches have been installed, you should see the following output:
Welcome to the CUDA Patcher. Installation complete! Installation directory: /usr/local/cuda-9.2
Next, you will need to create symbolic links to GCC6 in the CUDA bin folder. You can do this with the following command:
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda-9.2/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda-9.2/bin/g++
Congratulations! you have successfully installed Cuda to your system.