Caffe
Ubuntu 16.04
Uninstall
Machine Learning
Linux

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:

bash
which caffe
ldconfig -p | grep caffe
python -c "import caffe; print(caffe.__file__)"

These commands tell you:

  • whether a caffe executable is on the path
  • whether shared libraries such as libcaffe.so are 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.

bash
cd ~/caffe
make clean
make cleandata

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:

bash
1sudo rm -f /usr/local/bin/caffe
2sudo rm -f /usr/local/lib/libcaffe.so*
3sudo rm -rf /usr/local/include/caffe
4sudo ldconfig

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.

bash
python -c "import caffe; print(caffe.__file__)"

If it resolves to a file under site-packages, remove that package directory explicitly.

bash
sudo rm -rf /usr/local/lib/python2.7/dist-packages/caffe
sudo rm -rf /usr/local/lib/python3.5/dist-packages/caffe

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.

bash
dpkg -l | grep caffe
sudo apt remove --purge caffe-cpu caffe-cuda
sudo apt autoremove

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.

bash
which caffe
ldconfig -p | grep caffe
python -c "import caffe"

A successful uninstall usually means:

  • no caffe executable is found on the path
  • no libcaffe library appears in ldconfig
  • importing caffe in Python fails with ImportError

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 autoremove aggressively and removing packages used by unrelated software.
  • Forgetting to clean PYTHONPATH or 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 --purge only 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.

Course illustration
Course illustration

All Rights Reserved.