This section covers the steps to install CUDA on Linux distributions. In this section, the installation of CUDA in Ubuntu, which is a popular Linux distribution, is discussed using distribution-specific packages or using the apt-get command (which is specific to Ubuntu).
The steps to install CUDA using the *.deb installer downloaded from the CUDA website are as follows:
- Open Terminal and run the dpkg command, which is used to install packages in Debian-based systems:
sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.deb
- Install the CUDA public GPG key using the following command:
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
- Then, update the apt repository cache using the following command:
sudo apt-get update
- Then you can install CUDA using the following command:
sudo apt-get install cuda
- Include the CUDA installation path in the PATH environment variable using the following command:
If you have not installed CUDA at default locations, you need to change the path to point at your installation location.
export PATH=/usr/local/cuda-x.x/bin${PATH:+:${PATH}}
- Set the LD_LIBRARY_PATH environment variable:
export LD_LIBRARY_PATH=/usr/local/cuda-x.x/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
You can also install the CUDA toolkit by using the apt-get package manager, available with Ubuntu OS. You can run the following command in Terminal:
sudo apt-get install nvidia-cuda-toolkit
To check whether the CUDA GPU compiler has been installed, you can run the nvcc -V command from Terminal. It calls the GCC compiler for C code and the NVIDIA PTX compiler for the CUDA code.
You can install the NVIDIA Nsight Eclipse plugin, which will give the GUI Integrated Development Environment for executing CUDA programs, using the following command:
sudo apt install nvidia-nsight
After installation, you can run the deviceQuery project located at ~/NVIDIA_CUDA-x.x_Samples. If the CUDA toolkit is installed and configured correctly, the output for deviceQuery should look similar to the following: