Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My notes on how to install caffe on Ubuntu

Caffe Installation

Note on how to install caffe on Ubuntu. Sucessfully install using CPU, more information for GPU see this link


  • verify all the preinstallation according to CUDA guide e.g.
lspci | grep -i nvidia
uname -m && cat /etc/*release
 gcc --version
  • install CUDA on Ubuntu, following this site to install CUDA. We get .deb file and dpkg from CUDA download page (add CUDA path to .bashrc, see below)
sudo dpkg -i cuda-repo-ubuntu1404_6.5-14_amd64.deb
sudo apt-get update
sudo apt-get install cuda
  • More to do see post installion at this link where we change directory to ~/NVIDIA_CUDA-6.5_Samples then type make. Afterward, run deviceQuery under ~/NVIDIA_CUDA-6.5_Samples

  • install BLAS (from libopenblas) and git (and unzip for opencv)

sudo apt-get install libopenblas-dev git unzip
  • install opencv, follow this site where I use this bash script to install opencv
chmod +x 
  • install Anaconda from this link then run

(add Anaconda path to .bashrc, see below)

  • install Boost using this command:
sudo apt-get install libboost-all-dev
  • install others by following Caffe documentation
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
  • Get latest version of protobuf using pip
pip install protobuf
  • Then clone caffe and follow the instruction
git clone
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python)
make all
make test
make runtest
  • Note that we apply this to anaconda according to Caffe issue
rm ~/anaconda/lib/libm.*
  • And I also do something like in /usr/lib/x86_64-linux-gnu/:
sudo cp
sudo cp

(according to this issue on Caffe)

  • After that we can make python interface for caffe - make pycaffe (in caffe/python)

###Customization Caffe

  • This is what I added to .bashrc
# CUDA                                                                                                     
export PATH=/usr/local/cuda-6.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-6.5/lib64:$LD_LIBRARY_PATH
export PATH
# Anaconda
export PATH=/home/ubuntu/anaconda/bin:$PATH
# Caffe Root
export CAFFE_ROOT=/home/ubuntu/caffe

###Error Found

  • According to tutorial When running ./examples/mnist/, I got following error:
libdc1394 error: Failed to initialize libdc1394
I0109 02:31:21.168457 30295 caffe.cpp:99] Use GPU with device ID 0
F0109 02:31:21.168894 30295 common.cpp:53] CPU-only Mode: cannot make GPU call.
  • Above problem solved by changing solver_mode: GPU to CPU in /caffe/examples/mnist/lenet_solver.prototxt
  • More installation: pip install protobuf

###To do list


This comment has been minimized.

Copy link

@Keerthikan Keerthikan commented Oct 4, 2015

Are you able to use the command line interface such as cmdcaffe ??


This comment has been minimized.

Copy link

@guillaume-chevalier guillaume-chevalier commented Dec 24, 2015

The script for installing OpenCV is broken, as ffmpeg can not anymore be installed via apt-get.


This comment has been minimized.

Copy link

@sriharsha0806 sriharsha0806 commented Jul 4, 2016

when i am running make runtest i am getting following error,
ERROR: something wrong with flag 'flagfile' in file '/home/sriharsha/gflags-master/src/'. One possibility: file '/home/sriharsha/gflags-master/src/' is being linked both statically and dynamically into this executable.
make: *** [runtest] Error 1

how to resolve it?


This comment has been minimized.

Copy link

@arindam31 arindam31 commented Apr 5, 2017

After finishing above steps, When i import lmdb in python, the import fails. Any ideas ? I am on ubuntu 14.04. Although my caffe is working fine.


This comment has been minimized.

Copy link

@SudhakarReddyPeddinti SudhakarReddyPeddinti commented May 25, 2017

For python interface of caffe. to import caffe in python, run export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH


This comment has been minimized.

Copy link

@qaz99 qaz99 commented Jul 12, 2017

nitdelhi@nitdelhi-HP-Compaq-Elite-8300-SFF:/caffe$ cp Makefile.config.example Makefile.config
/caffe$ make all
CXX .build_release/src/caffe/proto/
In file included from .build_release/src/caffe/proto/
.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
#error This file was generated by a newer version of protoc which is
.build_release/src/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
#error incompatible with your Protocol Buffer headers. Please update
.build_release/src/caffe/proto/caffe.pb.h:14:2: error: #error your headers.
#error your headers.
In file included from .build_release/src/caffe/proto/
.build_release/src/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/arena.h: No such file or directory
#include <google/protobuf/arena.h>
compilation terminated.
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1


This comment has been minimized.

Copy link

@sammilei sammilei commented Mar 4, 2018

get the same error as @qaz99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment