Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Anakiev2/b828ed2972c04359d52a44e9e5cf2c63 to your computer and use it in GitHub Desktop.
Save Anakiev2/b828ed2972c04359d52a44e9e5cf2c63 to your computer and use it in GitHub Desktop.
How to install nvidia-legacy-340xx-driver on Debian 12 Bookworm

OUTDATED

Although this guide still works and even works on Debian 13 it's deprecated.

It's replaced by this new guide which supports both 64-bit and 32-bit libraries.

I will keep it because the information here is useful.

OUTDATED

 
 

How to install nvidia-legacy-340xx-driver on Debian 12 Bookworm

This guide will show you how to download, compile and install the nvidia-legacy-340xx-driver on Debian 12. Some people install the driver directly from sid but this will mix packages from both stable and unstable which may create issues. It's recommended to update and upgrade your system before you start.

It was reported to work with nvidia-legacy-390xx-driver just replace the appropriate package names.

Step 1. Download the source code.

Install these packages.

sudo apt install build-essential fakeroot devscripts

You can manually download the source code from debian.org and go to Step 2 or continue with Step 1. Don't worry you won't be able to install packages from sid.
Add 'deb-src http://httpredir.debian.org/debian unstable main non-free contrib' to '/etc/apt/sources.list'.
Update your system.

sudo apt update

Create these folders.

mkdir -p Build/nvidia340 Build/nvidia-settings

Download the driver in 'Build/nvidia340'.

apt source nvidia-legacy-340xx-driver

Download the nvidia-settings in 'Build/nvidia-settings'.

apt source nvidia-settings-legacy-340xx

Delete 'deb-src http://httpredir.debian.org/debian unstable main non-free contrib' from '/etc/apt/sources.list'.
Update your system.

sudo apt update

Step 2. Compile the driver.

Run

debuild -b -uc -us

in both folders 'Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108' and 'Build/nvidia-settings/nvidia-settings-legacy-340xx-340.108'.
It will complain about missing build dependencies. Install them.

# Example
# sudo apt install debhelper-compat m4 libgl-dev libgtk2.0-dev libjansson-dev libvdpau-dev libxext-dev libxv-dev libxxf86vm-dev pkg-config xserver-xorg-dev debhelper dh-dkms patchelf po-debconf quilt linux-headers-amd64

Run again

debuild -b -uc -us

in both folders 'Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108' and 'Build/nvidia-settings/nvidia-settings-legacy-340xx-340.108' to compile the driver.

Step 3. Make a local repository.

Make a new folder '/nvidia'.

sudo mkdir /nvidia

Copy all *.deb files from 'Build/nvidia340' and 'Build/nvidia-settings' inside '/nvidia'.

sudo cp *.deb /nvidia

Create 'Packages'.

cd /nvidia
sudo sh -c 'dpkg-scanpackages . > Packages'

Add 'deb [trusted=yes] file:/nvidia ./' to '/etc/apt/sources.list'.
Enable 'contrib' in your '/etc/apt/sources.list'.

# Example
# deb http://deb.debian.org/debian bookworm main non-free-firmware contrib

Step 4. Install the driver.

For each additional kernel you have to manually install the respective linux-headers.
Update your system and install the driver.

sudo apt update
sudo apt install nvidia-legacy-340xx-driver nvidia-settings-legacy-340xx
# If the above line doesn't work try with
# sudo apt install --no-install-recommends --no-install-suggests nvidia-legacy-340xx-driver nvidia-settings-legacy-340xx libgles1-nvidia-legacy-340xx libgles2-nvidia-legacy-340xx

It's recommended to uninstall all other video drivers or at least nouveau.

sudo apt autoremove xserver-xorg-video-nouveau

Step 5. Configure Xorg.

Create a file /etc/X11/xorg.conf (to configure NVIDIA Optimus - read the comments).

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

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

Step 6. Clean up. OPTIONAL.

I would definitely keep the source code because I might have to rebuild the driver in the future otherwise you can run.

rm -r Build/nvidia340 Build/nvidia-settings
rmdir Build

You can remove 'deb [trusted=yes] file:/nvidia ./' from '/etc/apt/sources.list' and update your system.
You can also delete '/nvidia' and all *.deb files.

sudo rm -r /nvidia

Sources:

https://wiki.debian.org/SourcesList
https://wiki.debian.org/BuildingTutorial
https://wiki.debian.org/DebianRepository/Setup

@Anakiev2
Copy link
Author

I've just made a clean Debian 13 LXDE install following the guide. Worked without any issues:
1

@mahdi-salimi05
Copy link

mahdi-salimi05 commented Aug 19, 2025

I've just made a clean Debian 13 LXDE install following the guide. Worked without any issues: 1

i have installed the module and nvidia-smi detect my gpu; but when i run glxinfo | grep "OpenGL renderer" ; it says llvmpipe instead of nvidia. how can i fix that? could you run glxinfo | grep "OpenGL renderer" in your Debian 13 installation?

@Anakiev2
Copy link
Author

OpenGL renderer string: GeForce GT 240M/PCIe/SSE2

Be sure you have the correct Linux headers (for the kernel version you are using) and the Xorg configuration file. In case you didn't have the Linux headers while installing the driver - installing them after won't trigger dkms and will not work. In such case you can first install the headers and reinstall the Linux kernel to force run dkms.

@mahdi-salimi05
Copy link

mahdi-salimi05 commented Aug 19, 2025

OpenGL renderer string: GeForce GT 240M/PCIe/SSE2

Be sure you have the correct Linux headers (for the kernel version you are using) and the Xorg configuration file. In case you didn't have the Linux headers while installing the driver - installing them after won't trigger dkms and will not work. In such case you can first install the headers and reinstall the Linux kernel to force run dkms.

i have installed the driver from deb sid repository; because when i manually build the libraries; i can not open steam due to missing 32 bit library.
to fix llvmpipe OpenGL renderer we should run:

ln -sf /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/lib* /usr/local/lib/x86_64-linux-gnu/
ln -sf /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/lib* /usr/lib/x86_64-linux-gnu/
ln -sf /usr/lib/i386-linux-gnu/nvidia/legacy-340xx/lib* /usr/lib/i386-linux-gnu
ln -s /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/libGL.so.340.108 /usr/lib/x86_64-linux-gnu/libGL.so
ln -s /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/libGLESv1_CM.so.340.108 /usr/lib/x86_64-linux-gnu/libGLESv1_CM.so
ln -s /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/libGLESv2.so.340.108 /usr/lib/x86_64-linux-gnu/libGLESv2.so
ln -s /usr/lib/i386-linux-gnu/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
ln -s /usr/lib/i386-linux-gnu/libGLESv1_CM.so.1 /usr/lib/i386-linux-gnu/libGLESv1_CM.so
ln -s /usr/lib/i386-linux-gnu/libGLESv2.so.2 /usr/lib/i386-linux-gnu/libGLESv2.so

fix vdpau

ln -s /usr/lib/x86_64-linux-gnu/nvidia/legacy-340xx/libvdpau_nvidia.so.1 /usr/lib/x86_64-linux-gnu/libvdpau_nvidia.so
now glxinfo | grep "OpenGL renderer" shows:
OpenGL renderer string: GeForce 9500 GT/PCIe/SSE2

fix GTK 4 applicathions

add GSK_RENDERER=cairo to your /etc/environment

@Anakiev2
Copy link
Author

Do not put GSK_RENDERER=cairo in /etc/environment. This will force almost all applications to run in "cairo mode". Instead run only the ones which don't work via terminal like this:

GSK_RENDERER=cairo pavucontrol
GSK_RENDERER=cairo ghb
etc...

@Anakiev2
Copy link
Author

This guide is now OUTDATED and is replaced by this one

https://gist.github.com/Anakiev2/8d62e261c66554d3012bc7ff855a22a7

Where I was able to compile both 64-bit and 32-bit nvidia libraries and play two win32 games in wine.

preview1

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