nvidia-340 driver on Ubuntu 20.04

You'll need to install the 5.4 kernel, and uninstall 5.11.

  1. sudo apt purge nvidia*

  2. sudo apt install --install-recommends linux-generic

  3. Now reboot, and select kernel 5.4 at grub menu.

  4. sudo apt remove --purge linux-generic-hwe-20.04 linux-hwe-* linux-modules-5.11* linux-modules-extra-5.11*

  5. If everything worked so far, run sudo ubuntu-drivers autoinstall to install Nvidia driver.


Sticking with 5.4 kernel will not be an option forever. I had the same issue with a early 2009 iMac, where the last proprietary nvidia driver available for my C79 [GeForce 9400] card is also nvidia-340.

As said by others, this driver is not supported by kernels > 5.4.

It means the day you will go for a newer kernel (you will have to, soon or later), you will have 2 choices :

  1. try nouveau driver (I had lots of freeze issues on my iMac, but it could work for you, our cards are different)
  2. keep the nvidia-340 proprietary driver with the more recent kernel

For (2), there is a solution.

Basically, boot on your new kernel (like 5.11, with for instance nouveau driver), and do what is explained in the link above, something like :

sudo add-apt-repository ppa:kelebek333/nvidia-legacy
sudo apt-get update
sudo apt install nvidia-340

# Warning: below line for kernels >= 5.11
sudo apt install xorg-modulepath-fix

I did upgrade from 20.04 (kernel 5.4, already with kelebek333's nvidia-340 version) to 21.10 (kernel 5.13) on the old iMac (I had no issue during the upgrade itself). The upgrade process did remove kelebeck333 repo), and enabled the nouveau driver.

After booting the new system, I did apply (again) the commands above, and my nvidia configuration is now :

$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:    21.10
Codename:   impish

$ uname -r
5.13.0-28-generic

$ dpkg -l | grep nvidia
ii  nvidia-340                             340.108-4lmtrimpish3                amd64        NVIDIA binary driver - version 340.108
ii  nvidia-opencl-icd-340                  340.108-4lmtrimpish3                amd64        NVIDIA OpenCL ICD
ii  nvidia-settings                        470.57.01-0ubuntu3                  amd64        Tool for configuring the NVIDIA graphics driver
ii  screen-resolution-extra                0.18.1                              all          Extension for the nvidia-settings control panel

$ inxi -Gx
Graphics:  Device-1: NVIDIA C79 [GeForce 9400] vendor: Apple iMac 9 1 driver: nvidia v: 340.108 bus-ID: 03:00.0 
           Device-2: Apple Built-in iSight type: USB driver: uvcvideo bus-ID: 1-4:2 
           Display: server: X.org 1.20.13 driver: loaded: nvidia tty: 186x32