Installing Torch 7 deep learning on Ubuntu 16.04

Make sure you have followed caffe setup if not atleast install Prerequisite packages from that post.

Step 1: install general dependencies

sudo apt-get install --no-install-recommends git software-properties-common

Step 2: gedit ~/.bashrc (append following lines) and restart terminal (source ~/.bashrc)

export TORCH_ROOT=~/torch

Step 3: Download Torch repo in that root location

git clone $TORCH_ROOT --recursive

Step 4: Change directory to Torch folder


Step 5: Install torch dependencies


Step 6: Now, lets install torch

./ -b

Step 7: Install some extra dependencies after restarting terminal (source ~/.bashrc)

sudo apt-get install --no-install-recommends libhdf5-serial-dev liblmdb-dev

luarocks install tds
luarocks install ""
luarocks install ""
luarocks install lightningmdb LMDB_INCDIR=/usr/include LMDB_LIBDIR=/usr/lib/x86_64-linux-gnu

# If you have installed NCCL
luarocks install ""

luarocks install nngraph 
luarocks install optim
luarocks install nn

If you’d like to train on an NVIDIA GPU using CUDA (this can be to about 15x faster), you’ll of course need the GPU, and you will have to install the CUDA Toolkit. Then get the cutorch and cunn packages:

luarocks install cutorch
luarocks install cunn

Aditionally to load caffe models in torch

luarocks install loadcaffe

Step 8: Install torch/demos from github by command:

git clone

Go into the demos folder, then just run one of the demos:

th demos/train-on-cifar/train-on-cifar.lua

Training screenshot



4 thoughts on “Installing Torch 7 deep learning on Ubuntu 16.04

Add yours

  1. Great tancks for your post, it’s a great help to Install Torch on Ubuntu 16.04 !!!
    I’an in France and write in English it’s no ver easy for me.. but i’m a Deep Learning Enthusiast to !
    Best regards.

Join the Discussion

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: