Skip to content

Instantly share code, notes, and snippets.

@morgangiraud
Last active December 11, 2020 15:48
Show Gist options
  • Save morgangiraud/990cf65dcb27068a4ca6b9db4957acc7 to your computer and use it in GitHub Desktop.
Save morgangiraud/990cf65dcb27068a4ca6b9db4957acc7 to your computer and use it in GitHub Desktop.
Script to reinstall manually nvidia drivers,cuda 9.0 and cudnn 7.1 on Ubuntu 16.04
# Remove anything linked to nvidia
sudo apt-get remove --purge nvidia*
sudo apt-get autoremove
# Search for your driver
apt search nvidia
# Select one driver (the last one is a decent choice)
sudo apt install nvidia-370
# Test the driver
sudo shutdown -r now
nvidia-smi
# If it doesn't work, sometimes this is due to a secure boot option of your motherboard, disable it and test again
# Install cuda
# Get your deb cuda file from https://developer.nvidia.com/cuda-downloads
sudo dpkg -i dev.file
sudo apt update
sudo apt install cuda
# Add cuda to your PATH and install the toolkit
# Also add them to your .bashrc file
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda-9.0
nvcc --version
# Use the toolkit to check your CUDA capable devices
cuda-install-samples-9.0.sh ~/.
cd ~/NVIDIA_CUDA-9.0_Samples/1_Utilities/deviceQuery
make
shutdown -r now
# Test cuda
cd ~/NVIDIA_CUDA-9.0_Samples/1_Utilities/deviceQuery
./deviceQuery
# Downloads cudnn deb files from the nvidia website:
# https://developer.nvidia.com/rdp/cudnn-download
# Install cudnn
tar -zxvf cudnn-9.0-linux-x64-v5.1.tgz
sudo mv cuda/include/* /usr/local/cuda-9.0/include/.
sudo mv cuda/lib64/* /usr/local/cuda-9.0/lib64/.
# Reload your shell
. ~/.bashrc
@aracthon
Copy link

Awesome! I followed this script and reinstalled CUDA and cuDNN! Now everything works well!

@magixer
Copy link

magixer commented Oct 17, 2017

Wow! Worked Streight forward

@vahdat-ab
Copy link

worked perfectly! Thanks.

@deeperlearner
Copy link

Wow, nice work!
Thank you for saving my time!

@cdies
Copy link

cdies commented Mar 22, 2018

Great work! Thanks!

@jihyeonRyu
Copy link

Thanks!!!!!

@tyaga08
Copy link

tyaga08 commented Apr 12, 2018

I am unable to install nvidia-370 using the apt search.
Is it ok if I download the drivers specified by the 'Additional Drivers' in the Softwares & Updates. The version specified is nvidia-340.

@OlofNiko
Copy link

How to add cuda to PATH and also how to install toolkit? @morgangiraud

@wiserain
Copy link

wiserain commented Apr 23, 2018

# add ppa graphic driver repository
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

# check which version is available
apt list nvidia-*

sudo apt install nvidia-396

@LiXiaoooowei
Copy link

Thank you so much! This saved me tons of time!

@MozhdehDokhani
Copy link

MozhdehDokhani commented Jun 15, 2018

Hi,
I successfully installed my nvidia driver and cuda 9.1. I also did everything that is needed to install cudnn 7.1. but when I run my code, I face the following error:

/////////////////////////////////////////////////////////////////
'libcudnn (R7) not found in library path.
Please install CuDNN from https://developer.nvidia.com/cuDNN
Then make sure files named as libcudnn.so.7 or libcudnn.7.dylib are placed in
your library load path (for example /usr/local/lib , or manually add a path to LD_LIBRARY_PATH)

Alternatively, set the path to libcudnn.so.7 or libcudnn.7.dylib
to the environment variable CUDNN_PATH and rerun torch.
For example: export CUDNN_PATH = "/usr/local/cuda/lib64/libcudnn.so.7"
/////////////////////////////////////////////////////////////////

My .bashrc file containes:

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

and I'm sure that the libcudnn.so.7 file exists in /usr/local/cuda-9.1/lib64
Any solution ?! :(

System Information:
Os: Ubuntu 18.04
Nvidia driver version: 390.48

@MozhdehDokhani
Copy link

Today I added this line to .bashrc file:

/////////////////////////////////////////////////////////////////
export CUDNN_PATH=/usr/local/cuda-9.1/lib64/libcudnn.so.7
/////////////////////////////////////////////////////////////////

and the error changed to:

/////////////////////////////////////////////////////////////////
Found Environment variable CUDNN_PATH = /usr/local/cuda-9.1/lib64/libcudnn.so.7/home/mozhdeh/torch/install/bin/luajit: /home/mozhdeh/torch/install/share/lua/5.1/trepl/init.lua:389: /home/mozhdeh/torch/install/share/lua/5.1/trepl/init.lua:389: /home/mozhdeh/torch/install/share/lua/5.1/cudnn/ffi.lua:1743: /usr/local/cuda-9.1/lib64/libcudnn.so.7: cannot open shared object file: No such file or directory
/////////////////////////////////////////////////////////////////

@MozhdehDokhani
Copy link

No solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment