How to Install CUDA on Ubuntu 18.04/16.04 Linux
This post will guide you how to install Nvidia CUDA Toolkit on your Ubuntu 18.04 or 16.04 Linux server. How do I install CUAD through Ubuntu package manager or executing a Runfile on Ubuntu system.
- What is CUDA?
- System Requirements
- Pre-installation Actions
- CUDA Installation with Package Manager
- CUDA Installation through Runfile
What is CUDA?
CUDA is a parallel computing platform and programming model invented by NVIDIA. It enables dramatic increases in computing performance by harnessing the power of the graphics processing unit (GPU). Software developer can use CUDA toolkit to access the GPU’s virtual instruction set and parallel computational elements.
System Requirements
If you want use CUDA Toolkit on your Ubuntu system, the following need to be installed:
- system need to have CUDA-capable GPU
- need to install GCC compiler
- NVIDIA CUDA Tookkit
Pre-installation Actions
Before install CUDA Toolkit on your system, you need to perform the following checks:
Checking if the system has a CUDA-capable GPU
To checking if your system has a CuDA-capable GPU, run the following command to check:
$ lspci | grep -i nvidia
If you do not see any outputs, and you need to update the PCI hardware database with the following command :
$ update-pciids
Checking if the system is running a supported version of Linux
You also need to check if your current version of Ubuntu system is supported by CUDA with the following command:
$ cat /etc/lsb_release
Outputs:
root@devops:~# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=18.04 DISTRIB_CODENAME=bionic DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
For the above outputs, you would see that the current Ubuntu version is 18.04. and this Linux version is supported by CUDA.
Checking if the system installed GCC compiler
You also need to make sure gcc compiler is intalled on your Ubuntu system, just using the following command to check if it is installed:
$ gcc --version
Outputs:
root@devops:~# gcc --version gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. root@devops:~#
So the installed GCC version is 7.3.0. and it is installed.
If GCC compiler is not installed on your system, you can install GCC compiler with the following apt command:
$ sudo apt install build-essential
CUDA Installation with Package Manager
If you want to install CUDA Toolkit on your system with package manager, you can download and install a repository package, and those package will inform the package manager where to find the actual installation packages, and it will not intall them. Just do the following steps:
#1 download the repository package from the CUDA Official site with the following wget command:
$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.105-1_amd64.deb
Outputs:
root@devops:~# wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.105-1_amd64.deb --2019-03-10 21:59:26-- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.105-1_amd64.deb Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 45.43.38.42, 45.43.38.98, 45.43.38.94, ... Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|45.43.38.42|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.105-1_amd64.deb [following] --2019-03-10 21:59:29-- https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.105-1_amd64.deb Resolving developer.download.nvidia.cn (developer.download.nvidia.cn)... 60.9.4.131, 60.9.4.142, 60.9.4.139 Connecting to developer.download.nvidia.cn (developer.download.nvidia.cn)|60.9.4.131|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2936 (2.9K) [application/x-deb] Saving to: ‘cuda-repo-ubuntu1804_10.1.105-1_amd64.deb’ cuda-repo-ubuntu1804_10.1.105-1_ 100%[=======================================================>] 2.87K --.-KB/s in 0s 2019-03-10 21:59:30 (65.9 MB/s) - ‘cuda-repo-ubuntu1804_10.1.105-1_amd64.deb’ saved [2936/2936]
#2 installing repository package downloaded in the first step, using the dpkg command to install it:
$ dpkg -i cuda-repo-ubuntu1804_10.1.105-1_amd64.deb
Outputs:
root@devops:~# dpkg -i cuda-repo-ubuntu1804_10.1.105-1_amd64.deb Selecting previously unselected package cuda-repo-ubuntu1804. (Reading database ... 230220 files and directories currently installed.) Preparing to unpack cuda-repo-ubuntu1804_10.1.105-1_amd64.deb ... Unpacking cuda-repo-ubuntu1804 (10.1.105-1) ... Setting up cuda-repo-ubuntu1804 (10.1.105-1) ... The public CUDA GPG key does not appear to be installed. To install the key, run this command: sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
#3 installing the CUDA public GPG key with the following command:
$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
Outputs:
root@devops:~# sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub Executing: /tmp/apt-key-gpghome.9Sw3Emku7u/gpg.1.sh --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub gpg: requesting key from 'http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub' gpg: key F60F4B3D7FA2AF80: public key "cudatools <cudatools@nvidia.com>" imported gpg: Total number processed: 1 gpg: imported: 1
#4 you need to update the Apt repository cache with the following command:
$ sudo apt update
Outputs:
root@devops:~# sudo apt update Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease Hit:3 http://dl.google.com/linux/chrome/deb stable Release Hit:4 http://mirrors.aliyun.com/ubuntu bionic-security InRelease Hit:6 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease Hit:7 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease Hit:8 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease Ign:9 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 InRelease Get:10 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 Release [564 B] Get:11 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 Release.gpg [801 B] Get:12 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 Packages [64.9 kB] Fetched 66.2 kB in 7s (10.1 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 72 packages can be upgraded. Run 'apt list --upgradable' to see them.
From the above outputs, you would notice that CUDA repos have been added to APT source list.
#5 you can start to install CUDA Tool key with apt command, type:
$ sudo apt install cuda
Outputs:
root@devops:~# sudo apt install cuda Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: augeas-lenses cpu-checker cryptsetup cryptsetup-bin db-util db5.3-util dmeventd extlinux hfsplus ibverbs-providers icoutils ipxe-qemu ipxe-qemu-256k-compat-efi-roms ldmtool libafflib0v5 libaio1 libaugeas0 libbfio1 libcacard0 libconfig9 libdate-manip-perl libdevmapper-event1.02.1 libewf2 libfdt1 libhfsp0 libhivex0 libibverbs1 libintl-perl libintl-xs-perl libiscsi7 libldm-1.0-0 liblvm2app2.2 liblvm2cmd2.02 libnl-route-3-200 librados2 librbd1 librdmacm1 libsdl1.2debian libspice-server1 libstring-shellquote-perl libsys-virt-perl libtsk13 libusbredirparser1 libvirt0 libwin-hivex-perl libxen-4.9 libxenstore3.0 linux-headers-generic-hwe-16.04 linux-image-generic-hwe-16.04 lsscsi lvm2 msr-tools osinfo-db qemu-block-extra qemu-system-common qemu-system-x86 qemu-utils scrub seabios sgabios sleuthkit supermin zerofree Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: ca-certificates-java cuda-10-1 cuda-command-line-tools-10-1 cuda-compiler-10-1 cuda-cudart-10-1 cuda-cudart-dev-10-1 cuda-cufft-10-1 cuda-cufft-dev-10-1 cuda-cuobjdump-10-1 cuda-cupti-10-1 cuda-curand-10-1 cuda-curand-dev-10-1 cuda-cusolver-10-1 cuda-cusolver-dev-10-1 cuda-cusparse-10-1 cuda-cusparse-dev-10-1 cuda-demo-suite-10-1 cuda-documentation-10-1 cuda-driver-dev-10-1 cuda-drivers cuda-gdb-10-1 cuda-gpu-library-advisor-10-1 cuda-libraries-10-1 cuda-libraries-dev-10-1 cuda-license-10-1 cuda-memcheck-10-1 cuda-misc-headers-10-1 cuda-npp-10-1 cuda-npp-dev-10-1 cuda-nsight-10-1 cuda-nsight-compute-10-1 cuda-nsight-systems-10-1 cuda-nvcc-10-1 cuda-nvdisasm-10-1 cuda-nvgraph-10-1 cuda-nvgraph-dev-10-1 cuda-nvjpeg-10-1 cuda-nvjpeg-dev-10-1 cuda-nvml-dev-10-1 cuda-nvprof-10-1 cuda-nvprune-10-1 cuda-nvrtc-10-1 cuda-nvrtc-dev-10-1 cuda-nvtx-10-1 cuda-nvvp-10-1 cuda-runtime-10-1 cuda-samples-10-1 cuda-sanitizer-api-10-1 cuda-toolkit-10-1 cuda-tools-10-1 cuda-visual-tools-10-1 default-jre default-jre-headless dkms fonts-dejavu-extra freeglut3 freeglut3-dev java-common libatk-wrapper-java libatk-wrapper-java-jni libcublas-dev libcublas10 libdrm-dev libgif7 libgl1-mesa-dev libgles1 libglu1-mesa-dev libglvnd-core-dev libglvnd-dev libice-dev libnvidia-cfg1-418 libnvidia-common-418 libnvidia-compute-418 libnvidia-decode-418 libnvidia-encode-418 libnvidia-fbc1-418 libnvidia-gl-418 libnvidia-ifr1-418 libopengl0 libpthread-stubs0-dev libsm-dev libvdpau1 libx11-dev libx11-doc libx11-xcb-dev libxau-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb1-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxi-dev libxmu-dev libxmu-headers libxnvctrl0 libxshmfence-dev libxt-dev libxxf86vm-dev mesa-common-dev mesa-vdpau-drivers nvidia-compute-utils-418 nvidia-dkms-418 nvidia-driver-418 nvidia-kernel-common-418 nvidia-kernel-source-418 nvidia-modprobe nvidia-prime nvidia-settings nvidia-utils-418 openjdk-11-jre openjdk-11-jre-headless screen-resolution-extra vdpau-driver-all x11proto-core-dev x11proto-damage-dev x11proto-dev x11proto-fixes-dev x11proto-input-dev x11proto-xext-dev x11proto-xf86vidmode-dev xorg-sgml-doctools xserver-xorg-video-nvidia-418 xtrans-dev Suggested packages: menu libice-doc libsm-doc libxcb-doc libxext-doc libxt-doc fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei libvdpau-va-gl1 nvidia-vdpau-driver nvidia-legacy-340xx-vdpau-driver Recommended packages: libnvidia-compute-418:i386 libnvidia-decode-418:i386 libnvidia-encode-418:i386 libnvidia-ifr1-418:i386 libnvidia-fbc1-418:i386 libnvidia-gl-418:i386 The following NEW packages will be installed: ca-certificates-java cuda cuda-10-1 cuda-command-line-tools-10-1 cuda-compiler-10-1 cuda-cudart-10-1 cuda-cudart-dev-10-1 cuda-cufft-10-1 cuda-cufft-dev-10-1 cuda-cuobjdump-10-1 cuda-cupti-10-1 cuda-curand-10-1 cuda-curand-dev-10-1 cuda-cusolver-10-1 cuda-cusolver-dev-10-1 cuda-cusparse-10-1 cuda-cusparse-dev-10-1 cuda-demo-suite-10-1 cuda-documentation-10-1 cuda-driver-dev-10-1 cuda-drivers cuda-gdb-10-1 cuda-gpu-library-advisor-10-1 cuda-libraries-10-1 cuda-libraries-dev-10-1 cuda-license-10-1 cuda-memcheck-10-1 cuda-misc-headers-10-1 cuda-npp-10-1 cuda-npp-dev-10-1 cuda-nsight-10-1 cuda-nsight-compute-10-1 cuda-nsight-systems-10-1 cuda-nvcc-10-1 cuda-nvdisasm-10-1 cuda-nvgraph-10-1 cuda-nvgraph-dev-10-1 cuda-nvjpeg-10-1 cuda-nvjpeg-dev-10-1 cuda-nvml-dev-10-1 cuda-nvprof-10-1 cuda-nvprune-10-1 cuda-nvrtc-10-1 cuda-nvrtc-dev-10-1 cuda-nvtx-10-1 cuda-nvvp-10-1 cuda-runtime-10-1 cuda-samples-10-1 cuda-sanitizer-api-10-1 cuda-toolkit-10-1 cuda-tools-10-1 cuda-visual-tools-10-1 default-jre default-jre-headless dkms fonts-dejavu-extra freeglut3 freeglut3-dev java-common libatk-wrapper-java libatk-wrapper-java-jni libcublas-dev libcublas10 libdrm-dev libgif7 libgl1-mesa-dev libgles1 libglu1-mesa-dev libglvnd-core-dev libglvnd-dev libice-dev libnvidia-cfg1-418 libnvidia-common-418 libnvidia-compute-418 libnvidia-decode-418 libnvidia-encode-418 libnvidia-fbc1-418 libnvidia-gl-418 libnvidia-ifr1-418 libopengl0 libpthread-stubs0-dev libsm-dev libvdpau1 libx11-dev libx11-doc libx11-xcb-dev libxau-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb1-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxi-dev libxmu-dev libxmu-headers libxnvctrl0 libxshmfence-dev libxt-dev libxxf86vm-dev mesa-common-dev mesa-vdpau-drivers nvidia-compute-utils-418 nvidia-dkms-418 nvidia-driver-418 nvidia-kernel-common-418 nvidia-kernel-source-418 nvidia-modprobe nvidia-prime nvidia-settings nvidia-utils-418 openjdk-11-jre openjdk-11-jre-headless screen-resolution-extra vdpau-driver-all x11proto-core-dev x11proto-damage-dev x11proto-dev x11proto-fixes-dev x11proto-input-dev x11proto-xext-dev x11proto-xf86vidmode-dev xorg-sgml-doctools xserver-xorg-video-nvidia-418 xtrans-dev 0 upgraded, 133 newly installed, 0 to remove and 72 not upgraded. Need to get 1,647 MB of archives. After this operation, 4,410 MB of additional disk space will be used. Do you want to continue? [Y/n] Y
You need to enter Y key on your keyboard to continue the installation process. After installation is completed, the CUDA Toolkit should be installed to your system successfully .
CUDA Installation through Runfile
You can also install CUDA Toolkit on your Ubuntu system with the Runfile installation via an interactive text-based interface. Just do the following steps:
#1 download the latest version of the CUDA Toolkit to local disk on your system, and the latest release of CUDA is 10.1.105.
$ wget https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.105_418.39_linux.run
#2 Once the installation package of CUDA is installed on your local disk, you need to make it as executable permission, and then install it.
$ chmod +x cuda_10.1.105_418.39_linux.run $ sudo sh cuda_10.1.105_418.39_linux.run
Colclusion
You should know that how to download and install the latest version of NVIDIA CUDA Toolkit on Ubuntu 16.04 or 18.04 from this guide. If you want to see more information about CUDA, you can go the official web site of CUDA directly.