Getting Started With NVIDIA CUDA on Ubuntu 10.04

NVIDIA Graphics Card

DISCLAIMER: This is a post from my old blog that I copied here to help out anyone interested in installing  CUDA on Ubuntu. Please keep in mind that it was written a few years ago with Ubuntu 10.04 and the CUDA toolkit 3.2.16. Obviously some things have changed, but it should at least provide a decent starting place.


For those crazy enough to dive into the world of GPGPU, one option is NVIDIA’s CUDA. For this walkthrough, I will give you a tutorial on how to set up the CUDA SDK on Linux (specifically, Ubuntu). I recommend going here as a starting place:

Download the CUDA SDK here:

I’ve created a step-by-step guide on getting CUDA running in Ubuntu. Note that in a couple weeks, Ubuntu or CUDA might change, and these steps will no longer apply. I hope it works as a good starting place, though.


1) CUDA-enabled graphics card (I’m using a GTX 470)

2) A supported Linux distribution (I’m using Ubuntu 10.04 LTS 32-bit)

3) GCC installed. If it is not installed, call the following:

4) You can check the version of gcc with:

5) For this post, I installed gcc 4.4.3


From the “Downloads” page on NVIDIA’s “GPU Computing” site, navigate to the Linux section and download the following files:

  • Developer Drivers for Linux (32-bit)
  • CUDA Toolkit for Ubuntu Linux 10.04 (32-bit)
  • GPU Computing SDK code samples

Save them to some directory on your computer. ~/Downloads sounds nice.

Install the Driver

1) Exit the GUI by pressing Ctrl+Alt+F1

2) Log in using username/password

3) Kill the X server by issuing:

4) Assuming you only have the 3 NVIDIA files in your ~/Downloads directory, give them all execution permission:

5) Execute the driver install .run file as superuser (note the version/filename might be different):

6) If you get an error about the script failing, say “OK” to continue anyway.

7) Say “No” if asked to run the nvidia-xconfig utility.

8) Restart the GUI with:

OR reboot the system:

9) Login and make sure that the correct version of the driver was installed: System -> Administration -> NVIDIA X Server Settings. Check the “NVIDIA Driver Version” field in “X Server Information.” It should match the file version you just installed (260.19.26 in this case).

Install the CUDA Toolkit and SDK

1) If, for some reason, you have used the CUDA SDK previously, remove all the files from /usr/local/cuda and ~/NVIDIA_GPU_Computing_SDK.

2) Install the toolkit:

3) Define PATH variables to include the new directory (note: change lib to lib64 for 64-bit installations):

4) Optional: You many notice that you have to re-type the export lines every time you restart the computer. This can quickly become a real pain. If you want to have Ubuntu (or any Linux variant with Bash) call them on startup, use your favorite editor to open ~/.bashrc and add the following lines (I put them at the end):

5) Install the SDK as a regular user (when asked, install to the default directory):

Test the Installation

1) Check the version of nvcc:

2) Before you can compile any of the examples, you need a few libraries:

3) Create a few links so the code knows where to find the libraries:

4) Compile the examples in the SDK

5) Run the device query project to determine if programs can access the GPU:

The top line should report the device (or devices) available. Additionally, the bottom line should show a “PASSED” if all the tests passed.

6) Run a compiled example project for fun. We’ll use particles because it’s fun:

Make sure you get a cool box with falling particles. If so, then everything has been installed correctly and you can now compile and run CUDA code!

Hello World

In the spirit of all good programming assignments, we’ll start off with a simple “Hello World” app that will give a good starting place for making your own programs.

Create a new folder in your CUDA work directory and open a new file:

In that file, write out the basic Hello World program:

Save and exit the editor. Then, compile the program:

There shouldn’t be any errors. Therefore, you can just run it!

And that’s it! Granted, the GPU doesn’t do a whole lot….but it’s a nice template for making your own programs.

Next time, I’ll cover building and running the Hidden Markov Model engine for CUDA. Stay tuned!

Leave a Reply