apt-get autoremove on ubuntu removes cuda.

I installed cuda 7 using the deb file provided by nvidia. However this deb file forces me to install nvidia-346. I want to have nvidia-355 which is more recent. Therefore after I installed cuda and overwrote my 355 driver with 346 I went in and reinstalled the 355 which is running fine with cuda. The only issue is now if I try to use apt-get autoremove it removes all of the cuda libraries. How can I have nvidia-355 and cuda 7.0 on the same system without this issue? I could just not use autoremove but I like running it occasionally to deal with other things.

THE EXACT LIST OF COMMANDS WILL BE DIFFERENT FOR YOUR SYSTEM.

You could use apt-mark hold to let apt know that it shouldn’t remove the cuda packages. For example I’m running linux mint 19.3 with cuda 10.0 and I ran these commands. I generated this list by dumping the list of packages that I don’t want removed and then ran xargs i.e.

cat cudaPackages.txt | xargs -l echo sudo apt-mark hold

Also be aware that the cuda toolkit installs some linux headers which need to be held back as well.

This way you can still use sudo apt autoremove

sudo apt-mark hold cuda-command-line-tools-10-0
sudo apt-mark hold cuda-compiler-10-0
sudo apt-mark hold cuda-cublas-10-0
sudo apt-mark hold cuda-cublas-dev-10-0
sudo apt-mark hold cuda-cudart-10-0
sudo apt-mark hold cuda-cudart-dev-10-0
sudo apt-mark hold cuda-cufft-10-0
sudo apt-mark hold cuda-cufft-dev-10-0
sudo apt-mark hold cuda-cuobjdump-10-0
sudo apt-mark hold cuda-cupti-10-0
sudo apt-mark hold cuda-curand-10-0
sudo apt-mark hold cuda-curand-dev-10-0
sudo apt-mark hold cuda-cusolver-10-0
sudo apt-mark hold cuda-cusolver-dev-10-0
sudo apt-mark hold cuda-cusparse-10-0
sudo apt-mark hold cuda-cusparse-dev-10-0
sudo apt-mark hold cuda-documentation-10-0
sudo apt-mark hold cuda-driver-dev-10-0
sudo apt-mark hold cuda-gdb-10-0
sudo apt-mark hold cuda-gpu-library-advisor-10-0
sudo apt-mark hold cuda-libraries-10-0
sudo apt-mark hold cuda-libraries-dev-10-0
sudo apt-mark hold cuda-license-10-0
sudo apt-mark hold cuda-memcheck-10-0
sudo apt-mark hold cuda-misc-headers-10-0
sudo apt-mark hold cuda-npp-10-0
sudo apt-mark hold cuda-npp-dev-10-0
sudo apt-mark hold cuda-nsight-10-0
sudo apt-mark hold cuda-nsight-compute-10-0
sudo apt-mark hold cuda-nvcc-10-0
sudo apt-mark hold cuda-nvdisasm-10-0
sudo apt-mark hold cuda-nvgraph-10-0
sudo apt-mark hold cuda-nvgraph-dev-10-0
sudo apt-mark hold cuda-nvjpeg-10-0
sudo apt-mark hold cuda-nvjpeg-dev-10-0
sudo apt-mark hold cuda-nvml-dev-10-0
sudo apt-mark hold cuda-nvprof-10-0
sudo apt-mark hold cuda-nvprune-10-0
sudo apt-mark hold cuda-nvrtc-10-0
sudo apt-mark hold cuda-nvrtc-dev-10-0
sudo apt-mark hold cuda-nvtx-10-0
sudo apt-mark hold cuda-nvvp-10-0
sudo apt-mark hold cuda-samples-10-0
sudo apt-mark hold cuda-toolkit-10-0
sudo apt-mark hold cuda-tools-10-0
sudo apt-mark hold cuda-visual-tools-10-0
sudo apt-mark hold libnvidia-common-410
sudo apt-mark hold linux-headers-4
sudo apt-mark hold linux-headers-4
sudo apt-mark hold linux-image-4
sudo apt-mark hold linux-modules-4
sudo apt-mark hold linux-modules-extra-4
sudo apt-mark hold nvidia-modprobe