NVIDIA driver issues Ubuntu 16.04

I am trying to install the latest Nvidia drivers. After the install nvidia-smi can't find it.

The graphic card is a GeForce 860m, and my laptop is under Ubuntu 16.04.1 LTS.

What I did so far:

$ sudo apt-get purge nvidia-*
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt-get update
$ sudo apt-get install nvidia-367
$ reboot
$ nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

How can I make it work ?

EDIT: I realized $ sudo apt-get install nvidia-367 returned the error:

Error! Bad return status for module build kernel: 4.4.0-36-generic (x86_64)
Consult /var/lib/dkms/nvidia-367/367.44/build/make.log for more information.

Although the driver is actually running.

make.log contains lines like this:

Makefile:676: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler

and this:

cc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:258: recipe for target '/var/lib/dkms/nvidia-367/367.44/build/nvidia/nv-instance.o' failed
make[2]: *** [/var/lib/dkms/nvidia-367/367.44/build/nvidia/nv-instance.o] Error 1
Makefile:1403: recipe for target '_module_/var/lib/dkms/nvidia-367/367.44/build' failed
make[1]: *** [_module_/var/lib/dkms/nvidia-367/367.44/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-36-generic'
Makefile:81: recipe for target 'modules' failed
make: *** [modules] Error 2

Solution 1:

gcc-4.8 didn't support -fstack-protector-strong

I installed gcc-4.9 instead, purged and reinstalled the driver, and now it's working fine.

$ nvidia-smi
Tue Sep 13 17:31:24 2016
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.44                 Driver Version: 367.44                    |
|-------------------------------+----------------------+----------------------+
| 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 GTX 860M    Off  | 0000:01:00.0     Off |                  N/A |
| N/A   54C    P0    N/A /  N/A |      0MiB /  4043MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Ironic is that I used gcc-4.8 because IIRC a previous version of CUDA wasn't compatible with versions 4.9 or later.