How to Install CUDA on Ubuntu 18.04 Bionic Beaver

Install CUDA on Ubuntu 18.04

In this article, we will have explained the necessary steps to install and configure CUDA on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

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.

Install CUDA on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Installing CUDA on Ubuntu 18.04.

Go to download page of CUDA Toolkit 10.1 here. After downloading the .deb file execute the following commands:

sudo dpkg -i cuda-repo-ubuntu1804-10-1-local-10.1.105-418.39_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

If you finished installing, don’t forget adding the CUDA PATH to your ~/.bashrc:

sudo nano ~/.bashrc

Add the following two lines to the end of the ~/.bashrc:

export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

There are a couple of patches for cuda. If you want to install them too, you have to download the patches and for every patch you have to execute the following commands:

sudo dpkg -i <the-file-you-have-downloaded.deb> 
sudo apt update
sudo apt upgrade

Step 3. Verifying the installation.

Run nvcc -V to check if CUDA is correctly installed. You must see the following output:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Mar__1_21:46:03_CDT_2019
Cuda compilation tools, release 10.0, V10.1

That’s all you need to do to install Nvidia CUDA on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.