Uninstall Caffe on Ubuntu 16.04
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Uninstalling Caffe on Ubuntu 16.04 depends on how it was installed in the first place. Most Caffe setups on that version of Ubuntu were built from source, which means there is usually no single package-manager command that cleanly removes everything. The practical job is to identify the install location, remove the compiled artifacts, remove the Python bindings if they were installed, and then clean up any leftover system packages only if they were dedicated to Caffe.
Figure Out How Caffe Was Installed
Before deleting anything, determine whether Caffe came from source or from a package manager. A source build often lives in a project directory such as ~/caffe and installs libraries under /usr/local. Start with a few checks:
These commands tell you:
- whether a
caffeexecutable is on the path - whether shared libraries such as
libcaffe.soare registered - where the Python module lives if Python bindings were installed
If which caffe points into a build tree or /usr/local/bin, you are probably dealing with a source installation.
Remove a Source Build Safely
If you still have the original Caffe source directory, start there. Many source builds support build cleanup even if they do not provide a full uninstall target.
That only removes build products inside the source tree. It does not remove files copied into /usr/local, so you still need to inspect the install prefix. Common locations to remove are:
Do not run broad rm -rf commands against /usr/local blindly. Remove only the files that clearly belong to Caffe.
Remove Python Bindings
Many Caffe installations also place a Python package into site-packages or rely on PYTHONPATH pointing at the source tree. Check where Python resolves the module.
If it resolves to a file under site-packages, remove that package directory explicitly.
The exact path depends on which Python interpreter was used on the machine. If PYTHONPATH was customized in .bashrc or another shell file to point at the Caffe source tree, remove that line too.
Clean Up Apt Packages Only When Appropriate
Caffe often depends on packages such as OpenCV, protobuf, BLAS, Boost, and Python libraries. Do not remove those automatically unless you are sure they were installed only for Caffe and are not needed elsewhere.
If you installed a dedicated Ubuntu package for Caffe, remove it with apt.
But if the machine uses OpenCV, protobuf, or BLAS for other projects, leave those dependencies in place. Dependency cleanup should be deliberate, not automatic.
Verify That Caffe Is Gone
After removal, rerun the same checks from the start.
A successful uninstall usually means:
- no
caffeexecutable is found on the path - no
libcaffelibrary appears inldconfig - importing
caffein Python fails withImportError
That is a better signal than assuming the uninstall worked because one directory was deleted.
Common Pitfalls
- Assuming there is one universal uninstall command even though the original install was built from source.
- Deleting the source tree but forgetting files copied into
/usr/local. - Removing Python bindings from one interpreter while another interpreter still imports Caffe successfully.
- Running
apt autoremoveaggressively and removing packages used by unrelated software. - Forgetting to clean
PYTHONPATHor shell configuration that still points to an old Caffe path.
Summary
- First determine whether Caffe was installed from source or through a package manager.
- For source builds, remove compiled binaries, shared libraries, headers, and Python bindings explicitly.
- For package-managed installs, use
apt remove --purgeonly on the actual Caffe packages. - Verify the uninstall with
which,ldconfig, and a Python import test. - Clean up dependencies carefully, because many of them may still be shared with other tools.

