Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

How to install CUDA 5.0 on Ubuntu 12.04 LTS

πŸ“… 2013-Mar-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cuda, driver, nvidia, ubuntu ⬩ πŸ“š Archive

These steps helped me to successfully installΒ CUDA 5.0 on many Ubuntu 12.04 LTS computers, including headless servers that do not run X windows.

  1. Make sure the computer has a NVIDIA graphics card that is recognized by Linux. This can be done as shown here.

  2. Uninstall all NVIDIA drivers and kernel modules. Steps to do this are described here.

  3. Download CUDA 5.0 installer for Linux. There is no installer for Ubuntu 12.04 LTS, so download the installer for Ubuntu 11.10 instead.

  4. Make the installer executable and run it as sudo. When asked to install the NVIDIA driver, choose Yes. This is important, allow the installer to install its own drivers. Let it install CUDA to the default location: /usr/local/cuda-5.0/

  5. If the computer is a headless Ubuntu server which is not connected to a display or does not run X, then device files for your card are not created by default. So, create a shell script file (say /home/joe/NvidiaDevCreator.sh) with the following code:

#!/bin/bash

/sbin/modprobe nvidia

if [ "$?" -eq 0 ]; then
  # Count the number of NVIDIA controllers found.
  NVDEVS=`lspci | grep -i NVIDIA`
  N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l`
  NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l`

  N=`expr $N3D + $NVGA - 1`
  for i in `seq 0 $N`; do
    mknod -m 666 /dev/nvidia$i c 195 $i
  done

  mknod -m 666 /dev/nvidiactl c 195 255

else
  exit 1
fi

Add the line /home/joe/NvidiaDevCreator.sh to /etc/rc.local and restart the system. This ensures that the necessary dev files are created on every startup for access by CUDA programs.

  1. Add the following to your bashrc:
export CUDA_ROOT=/usr/local/cuda-5.0
export PATH=$PATH:$CUDA_ROOT/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64

This ensures that the CUDA libraries are available for dynamic loading by CUDA programs.

That is all! Any user on your Ubuntu 12.04 system should now be able to compile and run CUDA 5.0 programs without any special access permissions or privileges 😊

Note: I had problems when I used the nvidia-current and nvidia-current-updates drivers from Ubuntu. Only by uninstalling them and using the drivers that ship with the CUDA installer was I able to get CUDA working.

Tried with: NVIDIA GeForce 9900 GT and NVIDIA GTX 690


Β© 2022 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 @codeyarns@hachyderm.io β€’ πŸ“§