Install Nvidia CUDA and drivers for Ubuntu 18.04

Below script will help you install graphic card drivers and CUDA, cudnn for Ubuntu 18.04. I use this code for my machine learning PC.

# Remove old packages
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt remove nvidia-cuda-toolkit
sudo apt remove nvidia-*

# Install
sudo apt update
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
sudo apt update
sudo apt install cuda-10-1
sudo apt install libcudnn7

# Set PATH
echo "# set PATH for cuda 10.1 installation" >> ~/.profile
echo "if [ -d \"/usr/local/cuda-10.1/bin/\" ]; then" >> ~/.profile
echo "    export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}" >> ~/.profile
echo "    export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" >> ~/.profile
echo "fi" >> ~/.profile

Đăng ký để nhận các bài viết mới nhất.