Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Building Tensorflow on CentOS 7.X from Source

I figured out how to build tensorflow from source in centOS. This process does not require any root access and you can do it anywhere. This will save your time and no need to worry much after this.

#What to prepare:

  1. Java 8
  2. Bazel
  3. Tensorflow
  4. CuDNN and CUDA toolkit (assume you have install them)

#Installation ##Bazel

I am using Bazel 0.3.2 since I found issues with Bazel in master branch.

check your JAVA_HOME since Bazel requires Java 8, you should download and install it first. This tutorial will not cover it.

$ git clone
$ git checkout tags/0.3.2
$ cd bazel
$ ./

It takes some time and after you finished, and add the binary path into the PATH variable, in this case

$ /PATH-TO-BAZEL/output/


This is the toughest software to build that I ever know (if you don't have any access to admin). You can download Tensorflow from github as mentioned in the website

$ git clone

Then, you may need to hack the code before you can start the configuration free from issues. Go to file tensorflow/third_party/gpus/crosstool/CROSSTOOL and update cxx_builtin_include_directory with

cxx_builtin_include_directory : "/usr/local/cuda/targets/x86_64-linux/include"

Run the configuration

$ ./configure

If you are wonder to use Tensorflow in a GPU with less than 3.5 compute capabilities, you may run this command and type the compute capabilities you desired


Build with bazel

# Without GPU support
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

# Build whl file
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Install tensorflow

pip install --upgrade /tmp/tensorflow_pkg/<your whl file>.whl

And done!

Copy link

haoxue15 commented Mar 14, 2017

Pretty good!

Copy link

daisyron commented May 19, 2017

I tried your instructions with the latest tensorflow (1.1) with no success: I've go the following error:

ERROR: /root/tensorflow/tensorflow/core/kernels/BUILD:2912:1: undeclared inclusion(s) in rule '//tensorflow/core/kernels:fake_quant_ops_gpu':
this rule is missing dependency declarations for the following files included by 'tensorflow/core/kernels/':
In file included from /usr/local/cuda-8.0/bin/..//include/host_config.h:173:0,
                 from /usr/local/cuda-8.0/bin/..//include/cuda_runtime.h:78,
                 from <command-line>:0:

System information:

  • Linux Centos 7.2
  • Kernel: 3.10.0-327.36.1.el7.x86_64
  • Compiler: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
  • Tensorflow: 1.1, installed from source.
  • nvcc: Cuda compilation tools, release 8.0, V8.0.44
  • CUDA: 8.0
  • cudaa: 5.1.5
  • bazel: 0.4.5

BTW on fedora 23 it works fine (have gcc 5.3, while centos 7 has 4.8.5).

Any help?


Copy link

mpenagar commented Jan 17, 2018


Think that instead of

$ git clone
$ git checkout tags/0.3.2
$ cd bazel
$ ./

It should be:

$ git clone
$ cd bazel
$ git checkout tags/0.3.2
$ ./

Anyway, I managed to build bazel (

$ mkdir bazel
$ cd bazel
$ wget
$ unzip
$ ./
$ cd ..

Copy link

cqychen commented Feb 10, 2018

bazel ,I suggest to use command :yum install bazel

Copy link

haramoz commented Sep 26, 2018

I am unable to use this command yum install bazel because i do not have root access, the centOS i need to setup is in the cluster environment.

Copy link

jorgeramirez commented May 24, 2019

For those coming from Google and trying to compile tensorflow current 1.12 release. Then, first,
use bazel from here. I encountered some issues while trying to use the newest version of bazel.

When trying to do

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

I encountered an error and fixed it following this tip. After this fix tensorflow compiled successfuly.

Copy link

AmericanEnglish commented Nov 7, 2019

As of tensorflow 2.0

I noticed that, as someone who came from google, these instructions didn't help except the build statement itself.
If you're someone who doesn't have root access and/or working in a cluster style environment. I'd like to mention these issues which talk about fixes for problems I encountered:

  1. Header errors despite their existence
  2. SWIG and issues with errors despite gcc being up to date. This issue talks about using a local version of SWIG instead.

I'd also like to respectfully plug my own gist that talks about it as well.

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