I have a dual-boot machine with Windows8 and Ubuntu 20.04.3 LTS.

It worked fine up until I pressed Yes (install) to some automatic updates from Ubuntu via the GUI pop-up window. These updates failed at around 70%. The problem is with nVidia drivers.

My motherboard is GT216 (GeForce GT 220). Running ubuntu-drivers devices I get:

driver: nvidia-340 - distro non-free recommended

driver: xserver-xorg-video-nouveau -distro free builtin.

After I shut down the computer after that failed update, at restart I got a login-infinite loop at the login screen (entered password, no login into Gnome Desktop, asked for password again, entered it again, no login into Gnome Desktop, repeat). I researched online and I found out that the nvidia-340 drivers are not compatible with my current kernel version.

Using tty terminals I worked through this tutorial https://www.if-not-true-then-false.com/2020/inttf-nvidia-patcher/ and then I installed nvidia-340 by running the executable I got via the tutorial. I followed the steps from here: https://www.if-not-true-then-false.com/2021/debian-ubuntu-linux-mint-nvidia-guide/#before-installation. I can now login into Gnome.


All my graphics programs are destroyed. In the past when my machine was functioning properly, I had installed Qt5 and linked against a framework I use for work. Now that framework doesn't function anymore, I cannot compile programs against the visualization drivers anymore.

I tried to reinstall the visualization drivers again, as I did 3-4 months ago on the same machine (when I successfully set up that framework I use for work): but I fail at the very first step: sudo apt install qt5-default

Removing nvidia-340 (340.108-0ubuntu5.20.04.2)... /var/lib/dpkg/info/nvidia-340.postrm: 59: /usr/sbin/update-initramfs: not found

dpkg: error processing package nvidia-340 (--remove):

installed nvidia-340 package post-removal script subprocess returned error exit status 127

dpkg: too many errors, stopping

Errors were encountered while processing:


Processing was halted because there were too many errorrs.

E: Sub-process /usr/bin/dpkg reurned an error code (1).

Attemtps I did:

  1. I have tried to do what it's written in here Ubuntu 18.10 problem with Nvidia 340 drivers

  2. I have tried to run sudo apt-get install nvidia-current : E : Package 'nvidia-current' has no installation candidate

  3. I have tried to switch to Nouveau from the Applications -> Software & Updates -> Additional Drivers, but it doesn't work. When I click to switch to that, Error while applying changes: pk-client-error-quark: Error while installing package: installed nvidia-340 package post-removal script subprocess returned error exit status 127 (313)

  4. I have tried to run nvidia-settings -> this pops up a new window with various information, which I can provide if needed.

  5. I have tried to run sudo apt-ache policy nvidia-340 -> this returns nvidia -340 : Installed : 340-108-0ubuntu5.20.04.2 candidate : 340-108-0ubuntu5.20.04.2 ... etc

  6. I have tried to run which nvidia-smi -> this returns nothing

6') I have tried to run nvidia-smi -> returns 'nvidia-smi' command nout found, can be installed with: and here appears a list of nvidia drivers it recommends installing via sudo apt install nvidia-XYZ or sudo apt install nvidia-utils-XYZ.

  1. I have tried to run sudo ubuntu-drivers autoinstall -> this returns the same thing as before: The following packages will be removed: nvidia-340 Removing nvidia-340 ... dpkg: error processing package nvidia-340 (--remove): installed nvidia-340 package post-removal script subprocess returned error exit status 127 dpkg: too many errors, stopping Errors were encountered while processing: nvidia-340 ...

  2. I have tried to run sudo apt-get install nvidia-340 -> this returns that nvidida-340 is already the newest version (340.108-0ubuntu5.20.04.2) 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 1 not fully installed or removed. Need to get 52,0 MB of archives. After this operation, 0B of additional disk space will be used. Do you want to continue ? Yes Y Get: 1 ... Fetched 52,0 MB in 2 s Processing triggers for libc-bin (2.31-0ubuntu9.2) ... and here I don't get any more returned statements and I just get a new line on the terminal to enter a new command as in $ > ... (so process exits alright and I can just continue doing stuff).

When writing (to configure my framework again) sudo apt install qt5-default I again get the same errors as above (in the Problem section)

Do you know what is happening or what shall I do? I really want to be able to compile applications again and run them on my machine.

I can provide any necessary info which might be useful to solve my problem.

Thank you in advance!

Edit (new info):

My current kernel version which appears as output when running uname -r is:


  • 1
    ...and what is "my current kernel version"? Nvidia-340 is only compatible with 5.4 kernel Ubuntu 20.04 was originally released with. If you happen to have 5.11, it would break things. Sep 24, 2021 at 21:12
  • @mikewhatever, thanks. My current kernel version is uname -r 5.11.0-36-generic. If the last Software Update made the kernel to arrive at this version, do you know what could I do, I don't know, to have a lower version of the kernel? I just want everything to work as before, it was all good.
    – velenos14
    Sep 24, 2021 at 21:25
  • At the grub menu, look under the Advanced choice, and you should have choices of the older kernels, with a hopefully working Nvidia driver.
    – ubfan1
    Sep 24, 2021 at 21:41
  • @ubfan1, thanks. When doing that, I can only choose from 4 alternatives: with Linux 5.11.0-36-generic, 5.11.0-36-generic (recovery mode), 5.11.0-34-generic, 5.11.0-34-generic (recovery mode) ...
    – velenos14
    Sep 24, 2021 at 21:52
  • 1
    You'll need to go back to 5.4 wiki.ubuntu.com/Kernel/… Sep 24, 2021 at 23:08

2 Answers 2


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.

  • thank you! just to check before I write these commands, from the link wiki.ubuntu.com/Kernel/…, I read that one step is as following: "And then install appropriate NNN version of the drivers: sudo apt install --install-recommends linux-modules-nvidia-NNN-generic " . Do I need to do this after sudo apt install --install-recommends linux-generic and before rebooting?
    – velenos14
    Sep 25, 2021 at 7:27
  • does Ubuntu install automatically all the necessary nVidia drivers when I log-in onto the kernel 5.4? Or do I need to manually install them after booting onto this kernel 5.4? so I am asking whether do I need to perform additional steps after booting onto kernel 5.4 in order to have correctly installed nVidia drivers
    – velenos14
    Sep 25, 2021 at 7:28
  • You'll need to install it. The ubuntu-drivers autoinstall should work for kernel 5.4. ...and yes, you need to install the 5.4 kernel first. Whether you reboot or not is less important, but if kernel 5.11 is still present, the Nvidia module will also build for it, and will fail. Sep 25, 2021 at 9:16
  • sorry, but sudo apt install --install-recommends fails! It reads: Fetched 75,5 MB in 4s ... Removing nvidia-340 (340.108-0ubuntu5.20.04.2) ... /var/lib/dpkg/info/nvidia-340.postrm: 59: /usr/sbin/update-initramfs: not found dpkg: error processing package nvidia-340 (--remove): installed nvidia-340 package post-removal script subprocess returned error exit status 127 dpkg: too many errors, stopping. Errors were encountered while processing: nvidia-340. E: Sub-process /usr/bin/dpkg returned an error code (1). Just to make sure: Do I need to run that command in my actual ubuntu terminal?
    – velenos14
    Sep 25, 2021 at 11:36
  • 1
    Alright, I've added step 0, according to your suggestion. Try and see if it works. For whatever reason, I have no access to chat, so can't join you there. Sorry about that. Sep 25, 2021 at 17:46

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

$ 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 

EDIT: The above upgrade procedure also applies to Ubuntu 22.04.

  • This is the only of a ton of solutions that works, also try the more votated, Ty Feb 7, 2022 at 1:27
  • Solution 2 also worked for me. thx
    – FedFranz
    Jun 22, 2022 at 10:24
  • 1
    This also works for Ubuntu 22.04
    – Chris
    Aug 14, 2022 at 22:36
  • 1
    Thanks @Chris. I also made the upgrade from 21.10 to 22.04 without any issue. l will add a note about it.
    – braoult
    Sep 11, 2022 at 17:31
  • Thanks! This works great on a Macbook Pro running Xubuntu 22.04 LTS. +1
    – Terrance
    Nov 16, 2022 at 14:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .