Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Anakiev2/8d62e261c66554d3012bc7ff855a22a7 to your computer and use it in GitHub Desktop.
Save Anakiev2/8d62e261c66554d3012bc7ff855a22a7 to your computer and use it in GitHub Desktop.
How to install the Nvidia legacy driver (340xx or 390xx) on Debian 13 Trixie

How to install the Nvidia legacy driver (340xx or 390xx) on Debian 13 Trixie

This guide will show you how to compile and install the legacy Nvidia driver on Debian. The steps bellow are compatible with both nvidia-legacy-340xx-driver and nvidia-legacy-390xx-driver and can be installed on Debian 13 (Trixie) as well as Debian 12 (Bookworm) or Debian 11 (Bullseye) in both 64-bit and 32-bit version. Execute the lines one by one and wait for every line to finish before proceeding to next. Only the lines starting with sudo should be executed as root. The lines with sudo pbuilder will take a lot of time.

To install the nvidia-legacy-390xx-driver version replace 340xx with 390xx everywhere bellow.
To install both 64-bit and 32-bit libraries for wine/steam you should run Step 2. twice.
It was confirmed that this method also works with the nvidia-tesla-470-driver version.

Step 1. Prepare:

Update, upgrade and install the required packages.
If you use 32-bit system do not install linux-headers-amd64.
If you plan on using both 64-bit and 32-bit libraries check if your mirror list support both amd64 and i386. If not select one which does before you install pbuilder.

sudo apt update
sudo apt upgrade
sudo apt install pbuilder linux-headers-amd64

Edit your /etc/apt/sources.list by adding contrib to the end of every line which starts with deb (if it's not already there).
Add this line too.

deb-src http://httpredir.debian.org/debian unstable main non-free contrib

Download the source code from Debian Sid.

sudo apt update
mkdir "$HOME/nvidia-340xx" "$HOME/nvidia-settings"
cd "$HOME/nvidia-340xx"
apt source --download-only nvidia-legacy-340xx-driver
cd "$HOME/nvidia-settings"
apt source --download-only nvidia-settings-legacy-340xx

Edit /etc/apt/sources.list and remove this line.

deb-src http://httpredir.debian.org/debian unstable main non-free contrib

Step 2. Compile:

To compile the 64-bit version replace ???? with amd64.
To compile the 32-bit version replace ???? with i386.
In case you want both amd64 and i386 libraries on a 64-bit system run Step 2. twice.

sudo apt update
sudo pbuilder create --distribution trixie --architecture ????
cd "$HOME/nvidia-340xx"
sudo pbuilder build nvidia-graphics-drivers-legacy-340xx_340.108-25.dsc
cd "$HOME/nvidia-settings"
sudo pbuilder build nvidia-settings-legacy-340xx_340.108-7.dsc

Optional: If you no longer need the files created during this process.

sudo rm /var/cache/pbuilder/aptcache/*
sudo rm /var/cache/pbuilder/base.tgz
rm -r "$HOME/nvidia-340xx" "$HOME/nvidia-settings"

Step 3. Install:

Create a local repository for automated install with apt.
The -m flag is only required if you want both amd64 and i386 versions.

cd /var/cache/pbuilder/result
sudo sh -c 'dpkg-scanpackages -m . > Packages'

Edit your /etc/apt/sources.list once more to add this line.

deb [trusted=yes] file:/var/cache/pbuilder/result ./

Optional: Run the next step only if you are on 64-bit system and want both 64-bit and 32-bit libraries.

sudo dpkg --add-architecture i386

Optional: The following was not required for my 340xx gpu. But recommended many times in the comments.

Edit /etc/default/grub and find the line starting with GRUB_CMDLINE_LINUX_DEFAULT. Make it like this.

GRUB_CMDLINE_LINUX_DEFAULT="nvidia_drm.modeset=1 noplymouth nosplash"

Then update grub.

sudo update-grub

Before you proceed make sure that you have matching linux-headers for every single linux-image version on your system.

sudo apt update
sudo apt install nvidia-legacy-340xx-driver nvidia-settings-legacy-340xx

Optional: I recommend to create /etc/X11/xorg.conf file.

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "ServerFlags"
    Option         "IgnoreABI" "1"
EndSection

Reboot your computer and you are done.

FAQ and Troubleshooting:

-> Was this tested?
Yes, it was tested on Debian 13 and Debian 12 with lxde and bspwm.
But I won't be surprised if modern desktop environments like GNOME or KDE Plasma don't work.

-> Does suspend to RAM work?
Yes, it does.

-> Which display manager works?
I've only tested lxdm and lightdm but should work with others as well.

-> Why should I even bother with this when I can just install from Debian Sid?
The drivers in Sid are compiled with newer version libraries which are not compatible with your current system. Installing them may look fine at first glance but will also install new incompatible packages and will overwrite some of your existing packages with ones from Sid. This may result in insatiability or even in unrecoverable system.

-> Is Wayland supported?
No.

-> My mouse and keyboard work in tty but not in Xorg.
Install xserver-xorg-input-all.

-> Some applications don't start. Especially the GTK4 ones.
GTK4 is not supported by this driver. But there is a workaround. Open a terminal-emulator and prepend GSK_RENDERER=cairo before the application's name, like this.

GSK_RENDERER=cairo pavucontrol
GSK_RENDERER=cairo ghb

Do not put GSK_RENDERER=cairo in /etc/environment or in any other way as environment variable. Because this will force almost all GUI programs to run in Cairo fallback renderer.

-> VDPAU doesn't work in mpv.
The version of mpv in the repositories doesn't include the x11 backend.
It can be added by recompiling mpv with this rule enabled -Dgl-x11=enabled. Then start mpv like this.

mpv --gpu-context=x11 --hwdec=vdpau

-> I've followed every single step but it doesn't work.
Run these and see if you have matching linux-headers for every linux-image.

apt list --installed | grep linux-image
apt list --installed | grep linux-headers

If there are missing ones, install them and go to the next question.

-> I've installed the linux-headers (after the Nvidia driver) but doesn't work. How to fix it?
Installing the headers after the driver doesn't trigger dkms. Run this.

sudo apt reinstall nvidia-legacy-340xx-kernel-dkms

-> Still doesn't work.
There might be a problem with /etc/X11/xorg.conf. Delete this file and try without it.
If doesn't work try to delete everything in /etc/X11/xorg.conf.d/ except 20-nvidia-legacy-340xx.conf.
Another possible solution is to generate new Xorg configuration with nvidia-xconfig.

-> How to use the deb822-style format sources?
If you prefer to use this format append the @macflav snipped to /etc/apt/sources.list.d/debian.sources.
I haven't tested this method yet.

# added for building nvidia-legacy driver
# deb-src http://httpredir.debian.org/debian unstable main non-free contrib
Types: deb-src
URIs: http://httpredir.debian.org/debian/
Suites: unstable
Components: main non-free contrib
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
#
# deb [trusted=yes] file:/var/cache/pbuilder/result ./
Types: deb
URIs: file:/var/cache/pbuilder/result/
Suites: trixie
Components: main
Trusted: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Then you have to move all amd64 packages from /var/cache/pbuilder/result to /var/cache/pbuilder/result/dists/trixie/main/binary-amd64/.
If you have any i386 they go to /var/cache/pbuilder/result/dists/trixie/main/binary-i386/.

-> Why pbuilder complains that either i386 or amd64 packages were not found even though I've updated my mirror list?
Modifying /etc/apt/sources.list after the pbuilder installation doesn't affect pbuilder. Fix your mirrors then run.

sudo apt purge pbuilder
sudo apt install pbuilder

-> I have Nvidia Optimus what should I do?
I don't have such hardware to test but this has been discussed in my previous guide.

-> In my case apt didn't automatically install the i386 packages.
Try to install them like this.
The third line is optional.

sudo dpkg --add-architecture i386
sudo apt install nvidia-legacy-340xx-driver-libs-i386
sudo apt install libnvidia-legacy-340xx-cuda1-i386

-> Should I keep the source?
Yes, you will have to recompile the driver once in a while.
Some day the Debian team will deprecate these drivers and delete the source from the servers.
Then you will have hard time finding the source elsewhere.

-> How often should I recompile the driver?
I don't know the exact answer but I have few assumptions.

Every time any of the dependencies is updated.
Every time GCC is updated.
If the driver stops working.
If dkms fails.

Before you start recompiling you can run these just in case.

sudo rm /var/cache/pbuilder/base.tgz
sudo rm /var/cache/pbuilder/result/*

-> Can I somehow make pbuilder faster?
Yes, if you use HDD and you have at least 8GB RAM you can significantly speed the process up.
If you use SSD there won't be much difference.
I can't find this method documented so I'm not sure if I can recommended it or not.

sudo mount -t tmpfs -o size=4G tmpfs /var/cache/pbuilder/build

When you finish using pbuilder run.
Everything in /var/cache/pbuilder/build will be instantly deleted after this command.

sudo umount /var/cache/pbuilder/build

-> Wine/Steam doesn't work. Failed to load libGL: libGL.so.1:... No such file or directory...
Read the very first comment in the comments section below.

-> I see RIP warnings in the kernel log.
I was able to remove them (except one), by the following...
The nvidia-340xx source doesn't include this patch, while nvidia-390xx does.

--- a/nv-drm.c
+++ b/nv-drm.c
@@ -168,6 +168,9 @@
     .poll = drm_poll,
     .read = drm_read,
     .llseek = noop_llseek,
+#if defined(FOP_UNSIGNED_OFFSET)
+    .fop_flags   = FOP_UNSIGNED_OFFSET,
+#endif
 };
 
 static struct drm_driver nv_drm_driver = {

The easiest way to install it is to apply the patch directly to /usr/src/nvidia-legacy-340xx-340.108/nv-drm.c then run.

sudo apt reinstall nvidia-legacy-340xx-kernel-dkms

Uninstalling these, since I don't use them, removed the rest RIP warnings.

libnvidia-legacy-340xx-cuda1
libnvidia-legacy-340xx-nvcuvid1
libnvidia-legacy-340xx-encode1

-> I have other video drivers should I keep them?
These are not necessary.
Purging xserver-xorg will also delete /etc/X11/xorg.conf. Recreate it if necessary.

xserver-xorg
xserver-xorg-video-all
xserver-xorg-video-amdgpu
xserver-xorg-video-ati
xserver-xorg-video-dummy
xserver-xorg-video-fbdev
xserver-xorg-video-nouveau
xserver-xorg-video-vesa
xserver-xorg-video-vmware

-> My question is not listed here.
I've made an earlier version of this guide here where a lot has been discussed. You might find something useful reading there.

Useful logs and tools for troubleshooting:

Replace lxdm with your display manager.

systemctl status lxdm.service
cat /var/log/Xorg.0.log
journalctl
dmesg

lsmod | grep nouveau
lsmod | grep nvidia
modprobe -r nouveau
modprobe nvidia
nvidia-settings
nvidia-xconfig
nvidia-smi
vdpauinfo
glxgears
glxinfo
lspci
@ethixill
Copy link

@macflav about using nvidia or nouveau, following what you discovered alongside @Anakiev2 I created and tested two scripts, one for disabling nvidia (you must run this first as it changes some files) when you followed this article thus use nouveau and one for enabling it back thus disabling nouveau:

I had done something similar. Thank you for sharing your solution. I'm sure it will help someone.

On another note, I decided to go back to Bookworm for the time being. Nouveau was not working for me on Trixie (I was constantly getting drm: failed to create ce channel, -22 and g84_gr_tlb_flush timeout, leading to random freezing), and I wasn't happy that GTK4 was not working with Nvidia 340.108. Let's hope the current stable release will improve support for old hardware in the future.

hello bro.
i was intrested with this subject so after 2 weeks i re-read this forum
so you found any soloution for ur problem?
or have you try another method in another distro (ubuntu 24 or else freeBSD)?
linux is great but its hard to us as old gpu users

@macflav
Copy link

macflav commented Sep 26, 2025

hello bro. i was intrested with this subject so after 2 weeks i re-read this forum so you found any soloution for ur problem? or have you try another method in another distro (ubuntu 24 or else freeBSD)? linux is great but its hard to us as old gpu users

I did a fresh install of Bookworm. I've been using Gnome on Wayland (with Nouveau, obviously), and it's "usable". The freezing still happens occasionally, but not nearly as often as it used to. If you need a reliable 100% stable system, better go with the Nvidia proprietary drivers instead, and live with the limitations (no Wayland, Cairo workaround for Gtk4 apps, etc.). I have a dual boot system, so if I need do to more serious work, I can still resort to Windows.

@ethixill
Copy link

I did a fresh install of Bookworm. I've been using Gnome on Wayland (with Nouveau, obviously), and it's "usable". The freezing still happens occasionally, but not nearly as often as it used to. If you need a reliable 100% stable system, better go with the Nvidia proprietary drivers instead, and live with the limitations (no Wayland, Cairo workaround for Gtk4 apps, etc.). I have a dual boot system, so if I need do to more serious work, I can still resort to Windows.

so the third party nvidia is work in debian 12? and for my pov i hate nouveau is trash
also i suffered with freezing in mint (change from cinamon to mate finaly to xfce and freezing is less) and in the last i try zram and the result is so light!!! if you dont use zram i recommend to use it
and the important point is why i cant install drivers from debian packages, and is still gtk4 apps dont work? (for cairo i use plank nyahoo) so maybe in next days i will try non-free driver from ubuntu for my mint (i hope i can setup drivers in debian live mod to know it's the magic solution or not?)
from someone who is intrested with driver 340 these days :)

@macflav
Copy link

macflav commented Oct 1, 2025

@ethixill This guide should work on both Debian 12 and 13. It's the most reliable way to use the system with stability. There will be limitations, though. For example, I couldn't get some games to work ('oolite' and 'Pioneer'), using 340.108. Interestingly, with Nouveau I can play oolite without any issues whatsoever. Pioneer, on the other hand, works for a while, until the dreadful freezing occurs. So, from my experience, some applications will trigger the freezing issue, and others don't.

@Kromgart
Copy link

Kromgart commented Oct 3, 2025

Thank you for this. I have Kepler-family GPU which is enough for my needs, but nvidia-tesla-470-driver was the last one that supported it, and it got deprecated in trixie. So I tried to follow the procedures in this guide for 470 - and it seems to work.
I haven't tried any games yet (see below), but so far it looks good: glmark2 and vkmark show x3-x4 score compared to nouveau, hardware video decoding works in mpv and firefox (with some elbow grease), nvidia-settings app also seems to work fine.

EDIT: One thing about the pbuilder: the i386 version of nvidia-settings was not building with some weird error, so I skipped it and installed only amd64 version of nvidia-settings + both i386 and amd64 versions of the driver, which seems to be good enough.

I've tried some games: SkyrimSE (steam), Dark Messiah of Might and Magic (steam), OpenMW.
No crashes. FPS is adequate.

Skyrim was freezing when I leave it running and afk until the screen shuts down - it could not wake up properly from this. Othirwise things are stable enough (as far as it can be with NVidia driver...)

Also it seems like new proton versions need vulkan 1.3 or better to convert directx shaders or smth like that. My GPU supports only vulkan 1.2, and some games were not starting until I forced older proton version in game properties (proton 7 in my case).

@Anakiev2
Copy link
Author

Anakiev2 commented Oct 5, 2025

@Kromgart Thanks for confirming I will add 470 as well.

@0bl1vyx
Copy link

0bl1vyx commented Oct 7, 2025

Please help me i am new to linux

@Anakiev2

I am installing the 390xx for my gt730 Fermi on Debian 13

I done all the steps correctly and then rebooted. But this showing Please fix it.

I am on lxde
Installing only amd64

IMG_20251007_210956

Update :-
Gemini fixed it. Adding this in grub fixed the issue. nvidia-drm.modeset=1

@Anakiev2
Copy link
Author

Anakiev2 commented Oct 8, 2025

I think most of the problems you have are caused by plymouth. It's useless just delete it.

@AnonEx-Machina
Copy link

@Anakiev2 Thankyou for your hardwork. Very appeciated.

https://wiki.archlinux.org/title/Table_of_contents

GRUB_CMDLINE_LINUX="nvidia_drm.modeset=1 noplymouth nosplash"

@Anakiev2
Copy link
Author

@tokamakfusionreactor Is this the correct URL?

@gorlik
Copy link

gorlik commented Oct 12, 2025

Thanks for the tutorial.
I still get the RIP upon driver load. There is a debian bug report on this. [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1099016]
glxgears works, 3D apps in wine work.
I can't get kicad, freecad or tuxracer to work. All crash immediately with:
[ 39.952562] kicad[3695]: segfault at 7fc160203370 ip 00007fc160203370 sp 00007fff9c172188 error 14 in libnvidia-tls.so.340.108[3370,7fc160203000+1ff000] likely on CPU 1 (core 1, socket 0)

@Anakiev2
Copy link
Author

@gorlik KiCad is hard and time consuming you have to recompile wxWidgets first than kicad without egl but if you do that every other application which uses wxWidgets won't work. I've made a tutorial some time ago (for Arch Linux) but it's much easier to switch to nouveau instead.
https://bbs.archlinux.org/viewtopic.php?id=286442

@BlackMoses2017
Copy link

Thank you so so much. You saved me buying a new card.

20220408_015229_IMG_5581

@Anakiev2
Copy link
Author

I had some time to update the guide. Hopefully this will fix the most issues.

@mahdi-salimi05
Copy link

mahdi-salimi05 commented Oct 24, 2025

When I attempt to run GTK applications (like all gtk4 or some gtk3); this error appears and the program won't run:

‍‍

(epiphany:2): epiphany-WARNING **: 14:24:35.018: Failed to search secrets in password schema: org.freedesktop.DBus.Error.ServiceUnknown
No provider of glGenSamplers found. Requires one of:
Desktop OpenGL 3.3
GL_ARB_sampler_objects
OpenGL ES 3.0

because this driver's EGL 1.4 only supports GLES GLSL ES 1.0. To fix, you can run those applications with GSK_RENDERER=cairo to disable hardware acceleration for rendering and it degrades performance for GTK, but it's certainly working. You can instead use GDK_DEBUG=gl-prefer-gl GSK_RENDERER=gl or (with 4.16) GDK_DISABLE=egl,gles-api,wgl,vulkan,dmabuf,offload,threads,glx GSK_RENDERER=gl to force those applications use GL instead of EGL or even GLX (those applications runs with GLX but it is buggy and the application has flickering issues).
Some Qt6 apps that have GLX problems should run with QT_XCB_GL_INTEGRATION=xcb_egl to use EGL.

To make these changes for all apps, put this to /etc/environment:(this will force all apps to use accelerated GL)

GDK_DEBUG=gl-prefer-gl
GDK_DISABLE=egl,gles-api,wgl,vulkan,dmabuf,offload,threads,glx
QT_XCB_GL_INTEGRATION=xcb_egl
GSK_RENDERER=gl

@Anakiev2
Copy link
Author

@mahdi-salimi05 Thanks for sharing this information I will put it in the faq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment