How to switch GCC version using update-alternatives

Multiple versions of GCC can be installed and used on Ubuntu. However, the default gcc and g++ will be pointed to the default versions of the actual compiler binaries. The update-alternatives tool makes it easy to switch between multiple versions of GCC. You can make any of these version as the default at any time effortlessly.

In this example, I have versions 4.8 and 4.9 of GCC on my system. You can install newer versions of GCC, as described here. The default is 4.8, but I want the freedom to switch it to 4.9 and back anytime I want. Let us begin:

  • Decide which symbolic links you want to group together as one unit. I like to switch /usr/bin/gcc and /usr/bin/g++ together.

  • Pass update-alternatives the first version of these symbolic links. Here I will inform about 4.8 version of these tools and links:

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

Here, we have provided the gcc as the master and the rest as two slaves. When master symbolic link is changed, the slaves will be changed too.

  • Pass the second version:
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 
  • Now you can switch between these versions by using:
$ sudo update-alternatives --config gcc

Tried with: Ubuntu 14.04

CUDA installation error of unmet dependencies

I was trying to install CUDA and got this error:

$ sudo apt-get install cuda
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cuda : Depends: cuda-6-5 (= 6.5-14) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

On searching, a lot of folks had this error. Their errors were solved when they removed old NVIDIA packages they had installed. But, I did not have any NVIDIA package installed!

What were these broken packages I had on the system, I didn’t know! I followed the dependency chain by trying to install cuda-6-5, which complained on another package and so on. In the end, I found that I had a lot of unnecessary packages, all of which had :i386 at the end of their name.

The strangest part was that running sudo apt-get autoremove had no effect on these packages, they were not removed. So, I manually removed all of them using sudo apt-get remove.

When I tried to install CUDA after this, it worked fine! :-)

Tried with: Ubuntu 14.04

Ubuntu Tweak

20150226_ubuntu_tweak

Ubuntu Tweak is one other tweak tool for Ubuntu that can be used to change settings of theme, fonts and desktop. Such tools have become essential since Unity no longer provides any settings to change them. A nice bonus in Ubuntu Tweak is the Janitor option that allows you to remove cruft of packages and such items from your system easily.

Ubuntu Tweak can be installed easily by using its official PPA:

$ sudo add-apt-repository ppa:tualatrix/ppa
$ sudo apt-get update
$ sudo apt-get install ubuntu-tweak

Tried with: Ubuntu Tweak 0.8.8 and Ubuntu 14.04

How to install CUDA 6.5 on Ubuntu 14.04

Installing CUDA is becoming increasingly easier on Ubuntu. I think I keep hitting problems because I am usually updating from an older NVIDIA graphics driver or CUDA version. NVIDIA continues to be quite bad at providing error-free upgrades. Anyway, this is what worked for me:

  • Do not try to install any of the NVIDIA drivers or CUDA packages that are in the Ubuntu repositories. I wasted a day with the errors these operations threw up!

  • Uninstall all CUDA packages and NVIDIA drivers you may have on your Ubuntu system.

  • Download the CUDA .deb package for Ubuntu 14.04 from here. For me, it was a cuda-repo-ubuntu1404_6.5-14_amd64.deb file.

  • The .deb file just adds a CUDA repository maintained by NVIDIA. Install this .deb file and update:

$ sudo gdebi cuda-repo-ubuntu1404_6.5-14_amd64.deb
$ sudo apt-get update
  • Installing CUDA now is easy as this:
$ sudo apt-get install cuda

This is a big install, it will install everything including a nvidia-340 driver that actually worked and NVIDIA NSight. After the install, reboot the computer. Your CUDA is ready for work now :-)

Note: I tried this on two systems. On one, it installed without any problem. On the other, it gave an error of unmet dependencies. I have described here how I solved this problem.

Tried with: NVIDIA GeForce GTS 250 and NVIDIA GTX Titan

How to remove old Linux kernels

20150225_kernel

Ubuntu updates Linux kernels almost every month. If you regularly update Ubuntu, you will end up with a lot of old Linux kernels.

A Linux kernel in Ubuntu is installed as four packages. They are listed here for kernel 3.13.0-43: linux-headers-3.13.0-43, linux-headers-3.13.0-43-generic, linux-image-3.13.0-43-generic and linux-image-extra-3.13.0-43-generic.

You can of course look up the latest kernel version using uname -r and then proceed to remove all the rest of the Linux kernel packages manually.

An alternative that I like is to use Ubuntu Tweak tool. It can be installed easily, as described here.

In Ubuntu Tweak, go to Janitor -> System -> Old Kernel and you will be presented with all the Linux kernel packages on your system. The current kernel will not be included here, for obvious reasons. You can now pick and choose and select what you want to remove easily from here.

Tried with: Ubuntu Tweak 0.8.7 and Ubuntu 14.04

How to give read permissions to ReadyMedia

ReadyMedia (formerly known as MiniDLNA) needs to have read access to the directories and files in its media directories to be able to index them. By default, it runs as the user and group, both named as minidlna.

If the directories and files in the media directory have group read permissions, then ReadyMedia can get access to them by adding minidlna user to the group who owns those files:

$ sudo usermod -a -G joesgroup minidlna

Some programs create directories and files that have no group read permissions. For example, the Copy.com client on Linux only provides user read access to the directories and files that is syncs. In such a case, you will need to tinker with the startup script of ReadyMedia and change the user it runs as to the user who has access to those directories and files.

On my Raspbian, I found that the startup script for ReadMedia was /etc/init.d/minidlna. Open it and look for the line where the username is provided and change that to the username you want. On my Raspbian, the relevant lines were:

if [ -z $USER ]; then
    USER=minidlna
fi

I changed minidlna in the above lines to the username who had read access to those files. In the worst case, you can even change it to root.

Restart the server for changes to take effect:

$ sudo service minidlna force-reload

Tried with: ReadyMedia 1.0.24 and Raspbian 7

How to install PyCUDA

PyCUDA enables a Python program to pass data to and call CUDA kernels from a Python program. Getting it to install and work correctly on Ubuntu took a bit of work.

  • I tried installing the nvidia-343 drivers for Ubuntu. But, it turns out that only 340.x or earlier drivers support the GTS 250 I use for display (not for compute). So, I reverted back and installed nvidia-331 drivers. Note that the nvidia-331-updates driver will not work with CUDA either. Do not ask me why! :-)

  • Installing the CUDA toolkit was easier, just install nvidia-cuda-toolkit package.

  • PyCUDA is available in Ubuntu as a python-pycuda package. But, that is the very old 2013.1.1 version. Instead I installed it from the Python Package Index (PyPI):

$ sudo pip install pycuda

The install script kept complaining about the absence of a configure.py script, but it seemed to end with success.

Tried with: PyCUDA 2014.1, CUDA 5.5, NVIDIA 331 driver and Ubuntu 14.04