[FIXED] Install Nvidia with Optimus driver on Ubuntu

Basic Setup
You need to open your terminal and enter the commands below.
If on 12.04.3, replace linux-headers-generic with linux-headers-generic-lts-raring.
  1. sudo add-apt-repository ppa:bumblebee/stable
  2. Enable the Universe and Multiverse repositories (for bumblebee and nvidia packages respectively).
  3. sudo apt-get update
  4. Install Bumblebee using the default proprietary nvidia driver for 12.04 - 13.04 :
    sudo apt-get install bumblebee bumblebee-nvidia virtualgl linux-headers-generic
    • And for 13.10 :
    sudo apt-get install bumblebee bumblebee-nvidia primus linux-headers-generic
  5. Reboot

Advanced Setups

For advanced users, if you do not want to use the proprietary nvidia driver or 32-bit libraries (for example, if you are only interested in power savings), you can do your custom installation.
Minimal setup : sudo apt-get install --no-install-recommends bumblebee
Depending on your needs, add to this line:
  • bumblebee-nvidia: proprietary nvidia driver support (if installed, become default over nouveau)
  • virtualgl: VirtualGL as backend
  • virtualgl-libs-ia32: 32bit support for VirtualGL on 64bit system, necessary to run 32bit app through optirun
  • primus: primus/primusrun as backend (virtualgl Stays default, you need to run optirun -b primus <app>)
  • primus-libs-ia32: 32bit support for primus/primurun on 64bit system, necessary to run 32bit app through optirun

Usage

To run your application with the discrete NVIDIA card run in the terminal:
  • optirun [options] <application> [application-parameters]
Example:
  • optirun steam

For a list of options for optirun run:
  • optirun --help
Normally you do not use optirun for your window manager, installations or other non graphic heavy demanding programs. The optirun command is mainly used for graphic demanding programs or for games.

Power Management

A primary goal of this project is to not only enable use of the discrete GPU for rendering, but also to enable smart power management of the dGPU when it's not in use. We're using either bbswitch (a module) or vga_switcheroo (kernel module, experimental) to do this in Bumblebee.
Since Bumblebee 3.0, this feature is enabled by default, using bbswitch. This allow automatic power management, without any configuration needs.
If Power Management doesn't work on your laptop, please go to this Power Management (PM) page and help to improve Bumblebee.

Troubleshooting

"Cannot access secondary GPU" error

In LTS 12.04.3, 13.04 and later, if your card seems to be inaccessible, i.e.[ERROR]Cannot access secondary GPU - error: [XORG] (EE) No devices detected. you need to edit the /etc/bumblebee/xorg.conf.nvidia (or /etc/bumblebee/xorg.conf.nouveau if using the noveau driver) and specify the correct BusID by following the instructions therein.

or you must see this

http://ubuntuforums.org/showthread.php?t=2080431

Updating drivers

The Bumblebee project recommends you install drivers only through APT and not drivers provided by nvidia.com directly. This said, whenever you update your drivers through the supported repositories, you need to setup the correct config values in /etc/bumblebee/bumblebee.conf. See also this FAQ on github

Example update to nvidia-319 driver

E.g. to update to the latest update of 319.x driver, you need to install it through apt.
sudo apt-get install nvidia-319-updates nvidia-settings-319-updates
Then you need to edit /etc/bumblebee/bumblebee.conf and set:
Driver=nvidia
KernelDriver=nvidia-319-updates
LibraryPath=/usr/lib/nvidia-319-updates:/usr/lib32/nvidia-319-updates
XorgModulePath=/usr/lib/nvidia-319-updates/xorg,/usr/lib/xorg/modules
By running optirun nvidia-settings (or optirun -b none nvidia-settings -c :8) you can assert you are using the installed kernel module and driver.

Uninstall

If you're unsatisfied with Bumblebee, you can remove it via:
  1. sudo apt-get install ppa-purge
  2. sudo ppa-purge ppa:bumblebee/stable
If you want to keep some programs from the bumblebee repository, you can also suffice by removing Bumblebee only (including its dependencies):

  1. sudo apt-get purge bumblebee
  2. sudo apt-get --purge autoremove

soureces : wiki.ubuntu.com/