Linux etc. demystified

Menu

Installing CUDA 5 on Ubuntu 12.04

This is a follow up to my previous post which was aimed at CUDA 4.2 on Ubuntu 12.04. Although 12.10 is out, it’s not as stable as I would like it to be – I’d recommend sticking with Ubuntu 12.04 for development unless you have specific reasons to upgrade. With CUDA 5, Nvidia has greatly simplified the installation process for Linux, packaging the CUDA toolkit, the SDK and the development drivers all in a neat little package.

Installing CUDA 5 will give you the option of opting for the development drivers or sticking with the regular ones. Personally, I chose the regular ones and they’ve worked out just fine (version 310.19 as of this writing).

STEP I – Driver installation (if you choose the regular drivers)

This section remains almost unchanged. Download the Nvidia drivers for Linux from their website, making sure to select 32 or 64-bit Linux based on your system.

Make sure the requisite tools are installed using the following command –

In order to get rid of any nVidia residuals, run the following command in a terminal –

sudo apt-get remove --purge nvidia*

This may take a while, so be patient. Once it’s done, reboot your machine. At the login screen, don’t login just yet. Press Ctrl+Alt+F1 to switch to a text-based login, and switch to the directory which contains the downloaded driver. Run the following commands –
sudo service lightdm stop
chmod +x NVIDIA*.run

where NVIDIA*.run is the full name of your driver. Next, start the installation with –
sudo ./NVIDIA*.run

Follow the onscreen instructions. If the installer throws up an error about nouveau still running, allow it to create a blacklist for nouveau, quit the installation and reboot. In that case, run the following commands again –
sudo service lightdm stop
sudo ./NVIDIA*.run

The installation should now proceed smoothly. When it asks you if you want the 32-bit libraries and if you want it to edit xorg.conf to use these drivers by default, allow both.

Reboot once the installation completes.

STEP II – CUDA toolkit installation

Download the CUDA toolkit (I used the Ubuntu 11.10 64-bit version). Navigate to the directory that contains the downloaded CUDA toolkit package, and run the following command –

chmod +x cuda*.run
sudo ./cuda*.run

where cuda*.run is the full name of the downloaded CUDA toolkit. Accept the license that appears. Next, choose to install the driver if you’ve not done so already (this is the development version). Installation of the driver will require switching to a text-based shell (Ctrl+Alt+F1), stopping lightdm as detailed in the previous step and running the toolkit installer as superuser. The CUDA 5.0 toolkit installation is compulsory, while that of the included samples isn’t. Allow the installer to proceed with default locations unless you have specific reasons for not doing so. This makes for easier troubleshooting in the future.

This process might take a while depending upon your system config. Once it’s done, double check the summary screen to make sure everything is in place. If the installation of the samples fails (which it does more often than not), it’s probably due to one or more missing libraries. In that case, install the required libraries and rerun the installer, choosing to install the samples alone.

To make sure the necessary environment variables (PATH and LD_LIBRARY_PATH) are modified every time you access a terminal, add the requisite lines (from the summary screen) to the end of ~/.bashrc as follows –

The paths used above will vary based on the install directory you choose for the toolkit. This wraps up the arguably simpler setup (compared to CUDA 4.x for Linux users), although the samples’ installation still suffers from dependency hell.

STEP III – CUDA samples installation and troubleshooting

While the installation of the samples should be straightforward (simply run the all in one toolkit installer), it’s often not all that easy. If you’re getting an error similar to “Samples installation failed due to missing libraries – libglut.so not found”, it’s typically because the installer looks for libglut.so and not variants (like libglut.so.3). To fix this, we’ll have to create softlinks so the installer can track down these files.

Determine if variants of libglut.so are present as follows –

sudo find /usr -name libglut\*

On my 64-bit installation of Ubuntu 12.04, this output the following text –

84 thoughts on “Installing CUDA 5 on Ubuntu 12.04”

First, why should i install the driver from its own file when the cuda download includes a driver in it?
Second, when I try installing the toolkit and samples it fails, says “Unsupported compiler: 4.7.2 Missing required library libglut.so. Toolkit: Installation Failed. Using unsupported compiler.. Samples: Installation Failed. Missing required libraries”

I followed your suggestions of requirements at the beginning, what then could be wrong?

I chose to install the regular driver because I’ve had issues (display freezing, random crashes) on my machine with development drivers in the past. Also, the driver I downloaded separately (309.xx) was a later version than the one packaged with the installer (306.xx). You should be fine as long as you use version 304.54 or later. I’ve updated the post with the answer to your second question (refer STEP III – CUDA samples installation and troubleshooting). As for the toolkit installation failing, I used gcc v4.6.3 – which one are you using?

my gcc is v4.7.2
I was trying to get this to work on ubuntu 12.10 so that’s probably why i was having trouble.
I went back to 12.04 though. I’ll try this again and see if i have any problems. I’m trying to get this to work on a laptop and also want the bumblebee package to work

Do you mind if I use this in a video tutorial? I will cite this before going into it. Though it’s graphics driver first and then cuda as I’m doing tutorials for Steam on linux since it goes open beta this week.

I found that letting the cuda driver install the video driver did not register it to DKMS , so when i updated the kernel the video driver was broken and i had to reinstall it and make it register to DMKS that will automatically manage it

now in /tmp/nvidia there are the cuda toolkit , cuda samples and the driver i need
so i just entered

/tmp/nvidia/devdriver*.run –dkms

and followed the procedure , entering yes when you’re prompter to register the driver to DKMS and reboot, hopefully it should work !
to check if it’s registered run
$ sudo dkms status
and it should print something like
nvidia, 304.54, 3.2.0-35-generic, x86_64: installed
this way it should last for every update!
PS: to install the video driver you need to stop the desktop manager and do it while in the textual terminal like the original guide

I have a system with 4 K10’s and am running 12.04. I don’t need the video as this is a compute system only with a simple video card. After going through this tutorial I am still left with “-> no CUDA-capable device is detected”
I have no /dev/nvidia* which would be created if I have an nVidia card for video.
Thank you for any direction
Lawrence Downes

First, thanks for this wonderful tutorial.
I am also having this same problem while tying to run cuda simulations.
cudaGetDevice returned error code 35
Follwoing are some output that might hep you debug my problem.

It seems like an Optimus card, but the active card (from your lsmod output) is the onboard Intel HD 4000. I’m not familiar with Optimus on Linux, but last I heard, support for it pretty much sucked. Disabling graphics switching (either via the BIOS or the command line – not sure about the latter) should do the trick. After that you might have success following the guide. Good luck!

Error code 35 is most likely a driver issue resulting from either an old driver (not recent enough to run CUDA 5) or your program being linked to an older version of libcuda.so. In your case, “lsmod | grep -i video” returns no mention of the Nvidia proprietary driver. The easiest solution is to remove any existing NVidia driver(s) and residuals, and then installing the development drivers that are a part of the CUDA 5 installer. Check the post for instructions.

The installation of the included samples often fails due to certain missing (or improperly linked) libraries. In my experience, the most common error is the “libglut.so not found” one which I’ve addressed in step III. In rare cases, your system may altogether be missing libraries that are mentioned in the installer’s error messages. Softlinking isn’t an option here, and the required libraries must be manually installed first.

Hey I faced the same issue. This has nothing to do with cuda toolkit installation but the nvidia driver installation. libcuda.so does not come with the toolkit it comes with the driver even if you don’t install cuda it will exist /usr/lib/nvidia-current (Default directory for ubuntu don’t know about rest)

If you use the nvidia driver installed by Ubuntu from the restricted repository (which makes things a lot easier generally) the cuda library is not where the script expects it. I had to issue the following command (note the directory where I made it) :

FYI, some of the sample code(s) won’t compile without MPI. If you opt to install it, try openMPI.org and use the flag –disable-vt when configuring as VampirTrace is not currently compatible with CUDA 5.

Hey, if you’ve already got the proprietary NVidia drivers installed, you only need to run the CUDA installer. This is most probably in your Downloads folder – navigate to it using “cd ~/Downloads”. Let me know if you need further help.

wow, thanks for the quick reply. I am following the directions on this page and have not downloaded anything nor do I know if I already have the proprietary NVidia drivers. If the step on this page prior to the restart step include the installation of proprietary drivers then I have them. Everything seemed to go smoothly up to this point – I got through the section that states:

“In order to get rid of any nVidia residuals, run the following command in a terminal –
sudo apt-get remove –purge nvidia*

I then restarted and now i am not sure what to do. It sounds like I was supposed to download the CUDA package at some point. I did not follow any steps from the “previous post” because the first sentence says that that page is replaced by new instructions (this page). Should I go back to the “Previous post” and follow to some point and then come back to this page?

also, I am so cautious that I am afraid to log into the GUI desktop for fear that not following the instructions will somehow nullify what I have already done. Thus, I have not downloaded any CUDA packages – I assumed the apt-get commands took care of the CUDA bits.

Really worked like a charm (3 weeks ago).Thank you so much!
I am new to linux and i noticed that some system updates may introduce problems. last update included nouveau and xorg something..i wondered about the reason that i had to update them but finally i clicked yes…and BOOM!
how can i just rip off everything and reinstall nvidia proprietary drivers+Cuda?
thank you!!! resolution in terminal is totally wrong…i use it almost blind.( i can see pixels…100% sure that i can login as root)
*sorry for my english*

My laptop has two GPU, namely Intel hd4000 and Nvidia GT630M, with Optimus technology. Since I will only be using Intel’s GPU for display, and the Nvidia card is for CUDA, is it possible just to intall the CUDA toolkit without installing the Nvidia Graphics driver? Also, do I need to install bumblebee to support the Optimus card?

thank you once again!!! I was afraid that i had to tweak some files, as remnants of the previous installations, but i just had to run again the driver installer, after purging nvidia*.
(I had a problem with Ctrl-F1, only the upper half of the screen seemed to display something and that something was (were) 4 mini screens side by side. Since it was difficult to guess only by pixel patterns, i just booted in failsafe mode and clicked to reset the default screen settings. Luckily after that i got a proper display and managed to install the driver through tty.)

It might be a good idea to mention the process for getting the driver as a specific stage. I found it a bit disconcerting, having rebooted, to be told “go to the directory where you downloaded the driver”.I was supposed to download a driver also???

There was some general discussion about drivers but nothing specific about downloading them. And also what is the process if you do not choose the regular drivers? Does the toolkit install the drivers? I guess the answers to these questions may be obvious but not to me the first time.

One point:
Setting LD_LIBRARY_PATH as you recommend breaks some programs (Namely gazebosim(.org)).
Setting it as
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.0/lib64:/lib
Maintains the old path and prevents breakage.

This is great, works perfectly fine in Lubuntu 13.04, after a little trial and error. I used the packages nvidia-cuda-toolkit and nvidia-cuda-dev that seem to install all that is needed. (But downloading from Nvidia, of course, can me more up-to-date). The only snag is the compiler, I had to edit host_config.h to disable the compiler check.

following your suggestions the following were tested:
sudo dpkg -r libgl1-mesa-dri
resulted in — dpkg: warning: there’s no installed package matching libgl1-mesa-glx
after this the rest is the same as was shown before.

The bug mentioned in your link would apply if you were using GNOME 3.8, which is highly unlikely since the version available in the Ubuntu 12.04 repos is GNOME 3.4. Use “gnome-shell –version” to verify it though. If it’s not 3.8, proceed with the following – “sudo apt-get install libglapi-mesa libgl1-mesa-dri”. Please let me know how it goes, we can continue this via chat if need be🙂

Hello guys,
I think its time to give up,
I installed ubuntu 12.04 two days ago. and wasted 36 hours on finding solution here at askubunto and other forum, following them more than 4 times reinstalled ubntu but its such a waste , not because ubuntu is not good, because there are so many different information here, so confusing for newbies like me. so thought its time to get back to window,
still i want to try one more time, this time i again reinstalled a fresh ubuntu
and here is what i want.

I want to run blender 2.69.
**what i have.**

i7 processor with 3gb
nvidia Geforce 640 with 4gb ram

**what i did so far.**

tried many follow up here on askubuntu. got some response to my help call too. but they just keep quite after a few answer and leave me in the middle of no where then i have install fresh and follow again different suggestion. the one i found very easy to follow is this.https://sn0v.wordpress.com/2012/12/07/installing-cuda-5-on-ubuntu-12-04/
but the installation of nvidia worked and the installation of cuda failed, again i installed ubuntu fresh one, and started second time this time the first step installation of nvidia failed.
now its fresh installation of ubuntu and waiting for one more time is some one comes up with the help would be appreciated. thanks.shamstaj@hotmail.com

The tutorial you wrote works. But after updating kernel, gpu is not getting detected. If I reinstall driver and cuda, then I am not able to login to my interface. How do I handle updating the system without disturbing my Cuda environment?