Installing proprietary nvidia graphics driver on debian wheezy amd64

When I first tried to manually install the proprietary nvidia driver I encountered the following error:

The CC version check failed:

The compiler used to compile the kernel (gcc 4.6) does not exactly match the current compiler (gcc 4.7). The Linux 2.6 kernel module loader rejects kernel modules built with a version of gcc that does not exactly match that of the compiler used to build the running kernel.

After some digging I found a nice solution for this problem:

Download proprietary nvidia driver

Download the latest 64-bit version of the proprietary nvidia driver. I got the following file:

Prepare your system

  1. Install the desired version of gcc:
    sudo apt-get install gcc-4.6
  2. Enable gcc to be switched between versions via update-alternatives
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20
  3. Switch to gcc version 4.6
    sudo update-alternatives --config gcc

Install the driver

You should be able to install the proprietary nvidia driver now without a warning about a wrong gcc version

sudo ./

Clean up

Switch back to the original version of gcc:

sudo update-alternatives --config gcc