sudo apt-get --purge remove nvidia*
sudo apt autoremove
cc: error: unrecognized command-line option '-ftrivial-auto-var-init=zero'
At first glance, I suspect the GCC compiler is too old. After downgrading the GCC to gcc-10 and gcc-9, the error still existed.
Finally, I noticed that the driver of the Tesla P100 is very new (Release Date: 2023.3.30) and this page mentioned “gcc-12”. Therefore I upgraded the GCC to 12:
sudo apt install gcc-12 sudo ln -sf /usr/bin/gcc-12 /etc/alternatives/cc
Now the driver can be installed successfully.