Skip to content

Instantly share code, notes, and snippets.

@ingo-m
Last active December 24, 2022 17:29
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ingo-m/60a21120f3a9e4d7dd1a36307f3a8cce to your computer and use it in GitHub Desktop.
Save ingo-m/60a21120f3a9e4d7dd1a36307f3a8cce 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 specifications:

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

    The full link to this version as of the time this document was created:
    http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run

  • 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
    
  • 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

  • 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
    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

  • 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

@MSchnei
Copy link

MSchnei commented Apr 4, 2017

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 $$?)
FEDORA = $(shell echo $(DISTRO) | grep -i fedora >/dev/null 2>&1; echo $$?)
RHEL = $(shell echo $(DISTRO) | grep -i 'red|rhel' >/dev/null 2>&1; echo $$?)
CENTOS = $(shell echo $(DISTRO) | grep -i centos >/dev/null 2>&1; echo $$?)
SUSE = $(shell echo $(DISTRO) | grep -i suse >/dev/null 2>&1; echo $$?)
ifeq ("$(UBUNTU)","0")
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
GLPATH := /usr/arm-linux-gnueabihf/lib
GLLINK := -L/usr/arm-linux-gnueabihf/lib
ifneq ($(TARGET_FS),)
GLPATH += $(TARGET_FS)/usr/lib/$(UBUNTU_PKG_NAME)
GLPATH += $(TARGET_FS)/usr/lib/arm-linux-gnueabihf
GLLINK += -L$(TARGET_FS)/usr/lib/$(UBUNTU_PKG_NAME)
GLLINK += -L$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
endif
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-ppc64le)
GLPATH := /usr/powerpc64le-linux-gnu/lib
GLLINK := -L/usr/powerpc64le-linux-gnu/lib
else
GLPATH ?= /usr/lib/$(UBUNTU_PKG_NAME)
GLLINK ?= -L/usr/lib/$(UBUNTU_PKG_NAME)
DFLT_PATH ?= /usr/lib
endif
endif
ifeq ("$(SUSE)","0")
GLPATH ?= /usr/X11R6/lib64
GLLINK ?= -L/usr/X11R6/lib64
DFLT_PATH ?= /usr/lib64
endif
ifeq ("$(FEDORA)","0")
GLPATH ?= /usr/lib64/nvidia
GLLINK ?= -L/usr/lib64/nvidia
DFLT_PATH ?= /usr/lib64
endif
ifeq ("$(RHEL)","0")
GLPATH ?= /usr/lib64/nvidia
GLLINK ?= -L/usr/lib64/nvidia
DFLT_PATH ?= /usr/lib64
endif
ifeq ("$(CENTOS)","0")
GLPATH ?= /usr/lib64/nvidia
GLLINK ?= -L/usr/lib64/nvidia
DFLT_PATH ?= /usr/lib64
endif

@ingo-m
Copy link
Author

ingo-m commented Apr 4, 2017

@MSchnei thanks

@ingo-m
Copy link
Author

ingo-m commented Apr 4, 2017

@ofgulban look at this

@littlekid
Copy link

specificatoins -> specifications

@ingo-m
Copy link
Author

ingo-m commented Apr 11, 2021

@littlekid thanks

Actually I wasn't aware anyone is using this gist :) Things have become a bit easier with the release of the NVIDIA Container Toolkit. If your goal is to use a GPU for machine learning (e.g. with tensorflow), you may want to look at this somewhat newer gist: https://gist.github.com/ingo-m/0952a9d77dc39250b559cbbb91ca9dae

@littlekid
Copy link

ty! 🙂

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