Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# named .sh just so Github does correct syntax highlighting
# Inspired by
# This setup is available as a public AMI in US-East(N. Virginia): ami-9d0f3ff7
# Add repos for cmake and gcc
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update
# Install dependencies for tensorflow and opencv (only for pictures, not video)
sudo apt-get install -y build-essential cmake gcc-4.9 wget curl git libtbb-dev libfreetype6-dev libpng12-dev libzmq3-dev pkg-config python3-dev python3-numpy python3-pip software-properties-common swig zip zlib1g-dev openjdk-8-jdk openjdk-8-jre-headless
sudo apt-get upgrade
# blacklist noubeau to avoid cudasetup error
echo -e "blacklist nouveau\nblacklist lbm-nouveau\noptions nouveau modeset=0\nalias nouveau off\nalias lbm-nouveau off\n" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u
sudo reboot
sudo apt-get install -y linux-image-extra-virtual
sudo reboot
sudo apt-get install -y linux-source linux-headers-`uname -r`
# Download and install cuda driver
# verify checksum
cs=$(md5sum | cut -d' ' -f1)
if [ "$cs" != "312aede1c3d1d3425c8caa67bbb7a55e" ]; then echo "WARNING: Unverified MD5 hash"; fi
chmod +x
./ -extract=`pwd`/nvidia_installers
pushd nvidia_installers
sudo ./
# When prompted you'll need to:
# * Agree to the license terms
# * Accept the X Library path and X module path
# * Accept that 32-bit compatibility files will not be installed
# * Review and accept the libvdpau and libvdpau_trace libraries notice
# * Choose `Yes` when asked about automatically updating your X configuration file
# * Verify successful installation by choosing `OK`
sudo modprobe nvidia
sudo ./
# When prompted, you'll need to:
# * Accept the license terms (long scroll, page down with `f`)
# * Use the default installation path
# * Answer `n` to desktop shortcuts
# * Answer `y` to create a symbolic link
# Install cuDNN 6.5
# Note: You’ll need to register into the NVIDIA Accelerated Computing Developer Program
# and download the cuDNN v2 Library for Linux to your local workstation.
# You have to get the approval of your regestration from nvidia, it make take up to some days!
# You can upload library to host via gui of winscp. Settings for amazon:
tar -xzf cudnn-6.5-linux-x64-v2.tgz
sudo cp cudnn-6.5-linux-x64-v2/libcudnn* /usr/local/cuda/lib64
sudo cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda/include/
# Install Bazel
git clone
cd bazel
git checkout tags/0.1.5
sudo cp output/bazel /usr/bin
#export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
#export CUDA_HOME=/usr/local/cuda
echo 'export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"' >> ~/.bashrc
echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
# Install Tensorflow
git clone --recurse-submodules
cd tensorflow
git checkout r0.7
# When prompted, you'll need to:
# * type path for python 3: /usr/bin/python3
# * Build with GPU support - yes
# * Accept the defaults for Cuda SDK and Cudnn versions and locations. Just click Enter...
# * Specify Cuda compute device capability of `3.0`
# !!! Don't accept the default of `3.5,5.2` !!!
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/pip
sudo pip3 install --upgrade /tmp/pip/tensorflow-*.whl
# Install OpenCV
git clone
git checkout tags/3.1.0
# Switch off cuda!, OpenCV doesn't support the GPU module with Python. That means that you must write wrappers yourself to use it.
make -j8
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/'
sudo ldconfig
echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' >> ~/.bashrc

This comment has been minimized.

Copy link

lucaswiser commented Mar 4, 2016

sudo apt-get install openjdk-8-jdk openjdk-8-jre-headless does not work on Ubuntu 14.04 (but it does on 14.10). What OS did you use to set this up? What would you recommend on AWS?


This comment has been minimized.

Copy link

lucaswiser commented Mar 5, 2016

also for everyone building this on an aws g2 you'll run out of memory at line:
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

Right before this you should delete the nvidia_installer folder on your home directory, which will free up ~1gb.


This comment has been minimized.

Copy link

santteegt commented Apr 5, 2016

while trying to build tensorflow on an AWS EC2 instance, I am getting the following error:

ERROR: /home/ubuntu/Downloads/tensorflow/google/protobuf/BUILD:272:1: Linking of rule '//google/protobuf:protoc' failed: crosstool_wrapper_driver_is_not_gcc failed: error executing command third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -o bazel-out/host/bin/google/protobuf/protoc ... (remaining 15 argument(s) skipped): Process exited with status 1.

Do you know how can I solve this ?
Thanks for your help


This comment has been minimized.

Copy link

mthrok commented May 18, 2016

I am seeing the same error. Did you solve it?


This comment has been minimized.

Copy link

SpencerC commented May 25, 2016

Published new AMI in N. Virginia with 0.8.0 support: ami-1e19ee73


This comment has been minimized.

Copy link

jjangsangy commented Jun 3, 2016

Rather than

$ git clone --recurse-submodules
$ cd tensorflow
$ git checkout r0.7

When you run git checkout r0.7, git will remove the google/protobuf submodule.

You can more simply do it like so

$ git clone --branch r0.7 --recurse-submodules && pushd tensorflow

This comment has been minimized.

Copy link
Owner Author

AlexJoz commented Jul 11, 2016

Sorry guys, there were no notifications about comments =(

Made new setup with tf 0.9, but without opencv for now, also available as public ami:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.