CUDA7.5 and Theano Setup in Ubuntu linux for Deep learning

TIPS that I’ve realized so far !

Before I forget the knowledge and tips from this massive hassle, I think I should write down something right now.

0. The BEST way to install CUDA&Theano in a nutshell.

  1. Install UBUNTU 14.04.
  2. Download RUN version of CUDA 7.5 toolkit.
  3. Disable Nouveau driver.
  4. Stop X server.
  5. Reboot.
  6. Install full version of CUDA 7.5 toolkit. (Driver, Toolkit, Samples)
  7. Edit .bashrc file to include PATH and LD_LIBRARY_PATH.
  8. Reboot.
  9. Install and update G++/GCC compiler.
  10. Compile CUDA sample and test deviceQuery.  
  11. install Numpy,Scipy,Pip, and Theano
  12. Install OpenBlas.
  13. Make .theanorc file.
  14. Test Theano library.
  • Ubuntu is highly recommended for beginners since it has tons of troubleshooting articles on the web. You would find information or guide about Ubuntu easier than any other type of Linux system. 1. Install UBUNTU 14.04.
  • I’m not gonna cover the Installation process of Ubuntu 14.04 here. Instead, you will be able to easily find it by googling it and tons of blog postings are covering Ubuntu installation issues.
  • I also recommend you to install “Anaconda” library. This is one of the easiest way to get all the dependencies that you need to run theano library.

2. Download RUN version of CUDA 7.5 toolkit.

  • DO NOT download NVIDIA graphics driver from NVIDIA graphics driver download webpage. This will cause a login error. I believe this page (NVIDIA graphics driver download) is solely purposed to support graphic oriented tasks. Forget this page. Don’t even click it.
  • Instead of that, refer to this page (CUDA toolkit download). There are two options. You can either select DEB installation or RUN file installation. I recommend RUN file installation because you can choose to opt out of installing the bundle driver and sample files.
  • According to various sources, some people suffer from NVIDIA graphics driver issue so that they should install specific NVIDIA driver which is not included in CUDA toolkit package. However, in my case, that was not the case. Both of my desktop and laptop system didn’t work with seperate driver. Having said that, I metion this issue because some of readers might suffer from this issue. If your system is not working with driver included in CUDA toolkit, refer to this page.

3. Disable Nouveau driver.

  • I’ve struggled with this issue for ages. The thing is, most of the QNA pages on the web omit this process and I have not been able to find out why does my linux system always show black screen after I reboot the system.
  • This was because of the “Nouveau” driver that crashes with NVIDIA driver. To nip this in the bud before it ruins your mental health, I suggest you a fancy solution with this issue.
  • We have to block Nouveau driver before it crashes with NVIDIA graphics driver. Type the following command.
$ sudo gedit /etc/modprobe.d/blacklist.conf
  • Then, add the following commands to block Nouveau driver.
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
# for other linux distributions
blacklist vga16fb
blacklist rivafb
blacklist nvidiafb
blacklist rivatv

4. Stop X server.

  • You should kill X server (Ubuntu GUI system) to install graphics related drivers. “ctrl + alt + F1” will lead you to text mode. Type the following command.
$ sudo service lightdm stop

5. Install full version of CUDA 7.5 toolkit. (Driver, Toolkit, Samples)

  • Go to the folder that you downloaded *.run file. Type the following command.
$ sudo chmod a+x
$ sudo ./
  • After browsing a long instruction article, you will encounter a few questions as followings. Please carefully read the questions and type your answers as the following.

Do you accept the previously read EULA? (accept/decline/quit): accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 346.46? ((y)es/(n)o/(q)uit): y

Do you want to install the OpenGL libraries? ((y)es/(n)o/(q)uit) [ default is yes ]: n

Install the CUDA 7.5 Toolkit? ((y)es/(n)o/(q)uit): y

Enter Toolkit Location [ default is /usr/local/cuda-7.5 ]: [Enter]

Do you want to install a symbolic link at /usr/local/cuda? ((y)es/(n)o/(q)uit): y

Install the CUDA 7.5 Samples? ((y)es/(n)o/(q)uit): y

Enter CUDA Samples Location [ default is /root ]: [Enter]


DO NOT install OpenGL library.This might cause an error with your graphic driver.

6. Reboot.

  • Reboot your system with the following command.
$ sudo reboot

7. Edit .bashrc file to include PATH and LD_LIBRARY_PATH.

  • If you don’t enroll the directory contains CUDA toolkit, you won’t be able to compile any code based on GPU programming. Add the following commands to ~/.bashrc file.
  • CAUTION : In Ubuntu, there is no file such as ~/.bash_profile. You should edit ~/.bashrc file.
$ sudo gedit ~/.bashrc
  • Once you see the gedit screen, type the following commands, and save it.

export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

8. Reboot.

  • Reboot your system with the following command.
$ sudo reboot

9. Install and update G++/GCC compiler.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
(check the version of gcc and make by entering the following command.)
$ gcc -v
$ make -v

10. Compile CUDA sample and test deviceQuery.  

  • This process will check whether  your CUDA library is correctly installed in your Ubuntu system.
~$ cd NVIDIA_CUDA-7.5_Samples
~/NVIDIA_CUDA-7.5_Samples$ sudo make
~/NVIDIA_CUDA-7.5_Samples$ cd bin/x86_64/linux/release
~/release$ ./deviceQuery
  • Another easy way to check out whether your NVIDIA driver is in shipshape manner, you can use the following two commands.

$ nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2015 NVIDIA Corporation

Built on Mon_Feb_16_22:59:02_CST_2015

Cuda compilation tools, release 7.5, V7.5.27

$ nvidia-smi

Tue Jul 14 19:50:26 2015


| NVIDIA-SMI 346.46     Driver Version: 346.46         |


| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |

| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |


|   0  GeForce 840M        Off  | 0000:0A:00.0     N/A |                  N/A |

| N/A   50C    P0    N/A /  N/A |      6MiB /  2047MiB |     N/A      Default |




| Processes:                                                       GPU Memory |

|  GPU       PID  Type  Process name                               Usage      |


|    0            C+G   Not Supported                                         |


  • DO NOT TYPE “sudo apt-get install nvidia-cuda-toolkit”. This command is outdated one and this will lead you to CUDA 5.5 version. And it won’t work either. So, please follow the instruction I’ve written above.
  • You have to be sure with the above two commands. If there is any command that doesn’t pop out the above messages, that indicates that you have a problem with your NVIDIA CUDA driver and compiler.

11. Install Numpy,Scipy,Pip and Theano

  • Now, we have to install python libraries that is necessary for Theano library. Type the following.
$ sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git
  • Once you install pip installer, you can easily install Theano library with the following command.
$ sudo pip install Theano

12. Install OpenBlas.

$ sudo apt-get install libopenblas-dev

13. Make .theanorc file.

  • “.theanorc” file contains a few configuration for theano library. You should create theanorc file by typing the following command.
$ sudo gedit ~/.theanorc
  • In the Gedit edit window, type the followings and save the file.
fastmath = True
ldflags = -lopenblas

14. Test Theano library.

  • Go to any directory type the following to make a python file.
$ sudo gedit
  • Copy and paste this code. Save “” file.
$ python
  • If you can get the messages similar to the following messages, Theano library is successfully installed in your computer.
  • Check out if you are getting the message “Using cpu device”. If you get “cpu” message, you should fix your configuration about CUDA and Theano library.

Using gpu device 0: GeForce 840M

[GpuElemwise{exp,no_inplace}(), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]

Looping 1000 times took 1.03167891502 seconds

Result is [ 1.23178029  1.61879349  1.52278066 …,  2.20771813  2.29967761


Used the gpu

CUDA test has been finished

  • DO NOT update any system updates until you are very assure you can re-set up every above steps when those little freaks down your system entirely.


If you have any question, please mail me to the following address.


Author: inctrljinee

I'm a signal processing engineer.

10 thoughts on “CUDA7.5 and Theano Setup in Ubuntu linux for Deep learning”

  1. I am trying to use this guide, but I am stuck at 4. I hope you can help!

    when I kill x server, I cannot see anything. Instead of text mode, I just have a blank screen. What shall I do?!


  2. This was very helpful, thank you! I would just mention one thing, and that is in step 10 “nvcc -v” causes an error. I believe that the option should be uppercase, i.e. “nvcc -V”. Otherwise, great work! You saved me a great deal of time and frustration.


  3. That's my huge pleasure. Glad I helped someone on Earth. I fixed “nvcc -V” thing right away. Really appreciate your correction and sorry for causing you a problem with typo. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s