How to remove cuda completely from ubuntu?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Removing CUDA completely from Ubuntu can be necessary for various reasons, such as resolving version conflicts, preparing for a fresh installation, or reclaiming disk space. This comprehensive guide will walk you through the steps needed to effectively remove CUDA from your Ubuntu system, ensuring no residual files affect future software installations or operations.
Understanding CUDA in Ubuntu
CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model developed by NVIDIA. It allows developers to leverage the power of NVIDIA GPUs for general-purpose processing. When installing CUDA on Ubuntu, it includes multiple components such as CUDA Toolkit, driver, samples, and more.
Several methods can be used for CUDA installation, like package manager installation or using the runfile installer. The removal process slightly differs depending on the installation method used. This guide will cover both scenarios.
Step-by-Step CUDA Removal Process
1. Determine the Installation Method
Before proceeding, it's crucial to determine how CUDA was installed:
- Package Manager: If you used
aptorapt-get, the installation method is via a package manager. - Runfile: If you executed a file with a
.runextension, it’s a runfile installation.
Use the command below to check for installed CUDA packages and configuration files which will help you in identifying the method:
2. Stopping CUDA Services
Regardless of the method used, it's helpful to stop any services that might be using CUDA before purging it:
3. Remove CUDA Installed via Package Manager
If CUDA was installed via apt or apt-get, follow these steps:
- List Installed CUDA Packages: Use the following command to list all CUDA-related packages:
- Remove the Packages: Execute the following command to remove all CUDA packages:
- Clean Up Residues: Ensure any leftover dependencies are removed:
4. Remove CUDA Installed via Runfile
For systems where CUDA was installed via a .run file, follow these steps:
- List CUDA Installations: Check the directory where CUDA is typically installed:
- Remove CUDA Directories:
- Revert Environment Variables and Path Modifications:
Remove or comment out any CUDA-related paths from your profile scripts (~/.bashrc, ~/.zshrc):
Delete lines like:
After editing and saving, refresh the environment variables:
5. Remove NVIDIA Drivers (Optional)
If you wish to remove NVIDIA drivers as well, execute:
6. Verification of CUDA Uninstallation
To verify that CUDA has been uninstalled, attempt the following:
- Ensure
nvccis unresponsive:
It should return an error if CUDA is no longer installed.
- Check GPU Status:
This should only display information if NVIDIA drivers are still installed.
Key Points Summary
| Task | Command or Path | |
| List current NVIDIA packages | dpkg -l | grep -i nvidia | |
| Stop services | sudo systemctl stop nvidia-persistenced | |
| Remove CUDA via apt | Remove sudo apt-get --purge remove '*cuda*' | |
| Clean-up residues | sudo apt-get autoremove
sudo apt-get autoclean | |
| Remove directories (runfile) | sudo rm -rf /usr/local/cuda* | |
| Reset environment variables | Remove from ~/.bashrc, then source ~/.bashrc | |
| Remove drivers (optional) | sudo apt-get --purge remove '*nvidia*' | |
| Verification | nvcc --version
nvidia-smi |
Conclusion
Removing CUDA from an Ubuntu system involves a systematic approach to ensure complete eradication of all related files. Using package management tools simplifies this process, but even .run file installations can be handled effectively with careful directory management and path reset. Understanding how to manage these components ensures a clean system, ready for new installations or configurations.
Related reading
- How to remove nodes from TensorFlow graph?
- How to remove the last layer from trained model in Tensorflow
- How to replace or insert intermediate layer in Keras model?
- How to resolve KeyError 'val_mean_absolute_error' Keras 2.3.1 and TensorFlow 2.0 From Chollet Deep Learning with Python
- How to reuse VGG19 for image classification in Keras?
- How to reverse the operation of torch.nn.functional.grid_sample?
- How to run eval.py job for tensorflow object detection models
- How to run Keras on multiple cores?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.