I am unable to install the Nvidia driver on my Ubuntu 22.04. Previously, I had working Nvidia drivers and CUDA installation. However, to install python libraries such as pyTorch etc. I had to uninstall and install CUDA several times. Meanwhile I also had to downgrade my gcc from 11.3 to 9 as some of these libraries are not compatible with higher versions. The problem is now that when I am trying to install Nvidia driver (latest or recommended) there is some problem with the kernel. It says that my kernel was compiled using gcc version 11.3, but you are trying to build using gcc 9.5.
make.log:
$cat /var/lib/dkms/nvidia/470.182.03/build/make.log
DKMS make.log for nvidia-470.182.03 for kernel 5.15.0-69-generic (x86_64)
Do 27. Apr 12:11:09 IST 2023
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-69-generic'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
warning: the compiler differs from the one used to build the kernel
The kernel was built by: gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
You are using: gcc (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.0
make -f ./scripts/Makefile.build obj=/var/lib/dkms/nvidia/470.182.03/build \
single-build= \
need-builtin=1 need-modorder=1
ln -sf /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-kernel.o_binary /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-kernel.o
ln -sf /var/lib/dkms/nvidia/470.182.03/build/nvidia-modeset/nv-modeset-kernel.o_binary /var/lib/dkms/nvidia/470.182.03/build/nvidia-modeset/nv-modeset-kernel.o
CONFTEST: hash__remap_4k_pfn
.
.
.
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv.o] Error 1
make[2]: *** Waiting for unfinished jobs....
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-pci.o] Error 1
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-acpi.o] Error 1
make[1]: *** [Makefile:1906: /var/lib/dkms/nvidia/470.182.03/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-69-generic'
make: *** [Makefile:80: modules] Error 2
When I try to upgrade gcc with sudo apt install gcc
I get the following error:
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-s
ource-470.0.crash'
Error! Bad return status for module build on kernel: 5.15.0-69-generic (x86_64)
Consult /var/lib/dkms/nvidia/470.182.03/build/make.log for more information.
dpkg: error processing package nvidia-dkms-470 (--configure):
installed nvidia-dkms-470 package post-installation script subprocess returned
error exit status 10
dpkg: dependency problems prevent configuration of nvidia-driver-470:
nvidia-driver-470 depends on nvidia-dkms-470 (<= 470.182.03-1); however:
Package nvidia-dkms-470 is not configured yet.
nvidia-driver-470 depends on nvidia-dkms-470 (>= 470.182.03); however:
Package nvidia-dkms-470 is not configured yet.
dpkg: error processing package nvidia-driver-470 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
Processing triggers for initramfs-tools (0.140ubuntu13
.1) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-71-generic
Errors were encountered while processing:
nvidia-dkms-470
nvidia-driver-470
E: Sub-process /usr/bin/dpkg returned an error code (1)