Skip to content

Instantly share code, notes, and snippets.

@ohenley
Forked from ingo-m/debian_install_cuda.md
Last active March 21, 2024 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ohenley/69aa9d27ec4ad4a0dd6ebe9e968abb27 to your computer and use it in GitHub Desktop.
Save ohenley/69aa9d27ec4ad4a0dd6ebe9e968abb27 to your computer and use it in GitHub Desktop.
How to install CUDA on Debian

How to install CUDA on Debian 8 (Jessie)

This document describes how to install nvidia drivers & CUDA in one go on a fresh debian install.

Work in progress

Preparations

  • Start with a fresh Debian install.

  • Download the CUDA driver with the following specificatoins:

    Parameter Type
    Operating system Linux
    Architecture x86_64
    Distribution Ubuntu
    Version 14.04
    Installer type runfile (local)

    You can download them directly:

    wget http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run /home/john/Downloads/
    

IMPORTANT NOTE: Cuda binaries (.run file) comes bundle with graphic drivers, eg cuda_7.5.18_linux.run ships with the nvidia 352 graphic drivers. Proceed with the installation of those bundled drivers only if your card is supported. Example, I have a GTX 1080ti which is only supported by the 375.82 and up. Therefore I had to first install the 375.82 graphic drivers, then proceed with the Cuda install and answer NO when asked to install the graphic drivers; then it worked. Proceed at OPTIONAL section further down.

  • Change file permission of the installation file:

    cd /home/john/Downloads/
    chmod a+x ./cuda_*.run
    
  • Get necessary packages:

    sudo apt-get update
    sudo apt-get install dkms build-essential linux-headers-$(uname -r)
    
  • Install 32 bit support:

    sudo dpkg --add-architecture i386
    sudo apt-get update
    sudo apt-get install lib32z1 lib32ncurses5
    
  • Blacklist the nouveau driver:

    sudo mousepad /etc/modprobe.d/blacklist-nouveau.conf
    

    Copy the following line into the document:

    blacklist nouveau
    blacklist lbm-nouveau
    options nouveau modeset=0
    alias nouveau off
    alias lbm-nouveau off
    
  • Disable the Kernel nouveau:

    echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
    
    sudo update-initramfs -u
    
  • Now reboot the system. If the nouveau was successfully disabled, the screen resolution should be lower.

  • Install the following packages:

    sudo apt-get install gcc g++ gcc-4.8 g++-4.8 gcc-4.9 g++-4.9 libxi6 libxi-dev libglu1-mesa libglu1-mesa-dev libxmu6 linux-headers-amd64 linux-source freeglut3-dev
    

Install the nvidia driver & cuda

OPTIONAL (If you have a graphic card not supported by the 352, Eg: the following will work for the 1080ti):

wget http://us.download.nvidia.com/XFree86/Linux-x86_64/375.20/NVIDIA-Linux-x86_64-375.20.run
chmod +x NVIDIA-Linux-x86_64-375.20.run
sudo ./NVIDIA-Linux-x86_64-375.20.run
  • Reboot again, start system in init 3. How to boot into init 3: When in starting screen press e to edit start commands, find relevant installation (quiet), add init 3

  • Log in as normal user, and activate su:

    su
    
  • Navigate to downloads folder (or where ever you put the installer), run cuda installer:

    cd /home/john/Downloads
    sh ./cuda_7.5.18_linux.run
    
  • Follow the installer menu. You will be asked several questions:

    Terms and condition? --> accept (If you feel like it...)
    Unsupported version, proceed? --> yes
    Install driver? --> yes (or NO if you already installed proper drivers for your card)
    Install OpenGL? --> yes
    Run nvidia-xconfig? --> 'yes' (This option is new in CUDA 8.0, not sure about the consequences.)
    Install CUDA toolkit? --> yes
    CUDA location? ---> /home/john/cuda-7.5
    Create symbolic link at /usr/local? --> yes
    Install samples? --> yes
    CUDA samples location? --> /home/john/cuda-7.5_samples

  • Make sure the output of this command is fine before proceeding further.

    nvidia-smi
    
  • Restart the system.

    sudo reboot
    

    This should start up successfully with GUI enabled (at native monitor resolution).

  • Add path exports to your .bashrc:

    sudo gedit /home/john/.bashrc
    

    Add the following lines:

    # Manually added by john to enable CUDA:
    export LD_LIBRARY_PATH=/home/john/cuda-7.5/lib64:$LD_LIBRARY_PATH
    export LIBRARY_PATH=/home/john/cuda-7.5/lib64:$LIBRARY_PATH
    export PATH=/home/john/cuda-7.5/bin:$PATH
    
  • Change permissions of cuda folders:

    sudo chown -R john /home/john/cuda-7.5
    sudo chgrp -R john /home/john/cuda-7.5
    sudo chown -R john /home/john/cuda-7.5_samples
    sudo chgrp -R john /home/john/cuda-7.5_samples
    

Check the result

Check whether the samples that do not require graphics ouput are working

  • Navigate to cuda samples location (as specified during installation):

    cd /home/john/cuda-7.5_samples/0_Simple/simplePrintf
    
  • Generate executable:

    make
    
  • An executable should have been created. Run it:

    ./simplePrintf
    

For samples that do require graphics ouput, the library paths need to be fixed.

  • Naviagte to a sample that does require graphics output, e.g.:

    cd /home/john/cuda-7.5_samples/5_Simulations/nbody
    
  • Locate the libary files by running:

    locate libGL.so
    locate libGLU.so
    locate libX11.so
    
  • Check which folder they are located in (e.g. /usr/lib/x86_64-linux-gnu).

  • In the samples folder, open findgllib.mk:

    gedit /home/john/cuda-7.5_samples/5_Simulations/nbody/findgllib.mk
    
  • Search for the following if-condition:

    ifeq ("$(TARGET_OS)","linux")
        # $(info) >> findgllib.mk -> LINUX path <<<)
        # Each set of Linux Distros have different paths for where to find their OpenGL libraries reside
        UBUNTU_PKG_NAME = "nvidia-352"
        UBUNTU = $(shell echo $(DISTRO) | grep -i ubuntu >/dev/null 2>&1; echo $$?)
        ...
    

    and replace it with the following code:

    ifeq ("$(TARGET_OS)","linux")
        GLPATH    ?= /usr/lib/x86_64-linux-gnu
        GLLINK    ?= -L/usr/lib/x86_64-linux-gnu
        DFLT_PATH ?= /usr/lib64
    
  • Generate executable:

    make
    
  • An executable should have been created. Run it:

    ./nbody
    

References:

http://www.allaboutlinux.eu/remove-nouveau-and-install-nvidia-driver-in-debian-8/2/
https://andrewbolster.info/2016/04/fixcuda-on-debian-jessie
http://unix.stackexchange.com/questions/218163/how-to-install-cuda-toolkit-7-x-or-8-on-debian-8-jessie-or-9-stretch

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