Installing MXNet on Alibaba Cloud ECS Ubuntu 16.04

By Alex Mungai Muchiri, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

MXNet is a great tool to use as your deep learning engine deployed in the cloud. MXNet provides a reliable tool to train your machine learning (ML) models, which can then be imported to portable devices such as smartphones. Furthermore, the community provides numerous resources to support the project. Some of the things to love about MXNet include:

  1. Caffe-like binaries: the binaries aid in building image datasets/record files that are packed efficiently.
  2. Keras-like syntax: the syntax enables the Python programming language to build deep learning models with ease.
  3. Techniques enabling training of deep neural networks on several GPUs and scale on machines.

For most first-time machine learning developers, Keras is a good choice. It is also easier to use it as the foundation for a neural network architecture as well as the training phases. However, MXNet allows massive scalability from those foundational experiments to ImageNet-size datasets. With MXNet, you can build datasets that are packed efficiently and have the network trained on multiple GPUs on several machines. Furthermore, it is possible to have the system performance in the optimal because C/C++ binaries bind Python to MXNet. MXNet being an Apache project has numerous developers creating new tools and tutorials for the community. Therefore, MXNet is a great choice for your deep learning backend.

This tutorial teaches several ways you can install MXNet, the deep learning tool on Alibaba Cloud ECS running Ubuntu 16.04. At the time of writing, MXNet does not support a higher version for Ubuntu. In particular, this series is meant to help developers to create and train new deep learning models using MXNet.

CUDA Dependencies

MXNet enables building with GPU, which requires setting up the runtime for CUDA and cuDNN. To begin with, install the CUDA toolkit after downloading it. The recommended version is CUDA 9.2. Then, download cuDNN 7.1.4 and unzip the file.

Then, in the cuDNN root directory, place its header and libraries in the local CUDA Toolkit folder.

Install MXNet for Python


Run these scripts to install Ubuntu 16.04 dependencies to support MXNet Python development.

In order to achieve the fastest training speed with the tool, it is best to use the latest MXNet with CUDA 9.2 package.

Install training package:

Install inference package:

However, you can select a different combination if your objectives are not merely the training speed.

Availability of pip Packages

In this table, we list pip packages recommended for respective MXNet versions.

When installing any MXNet version coupled with one of the packages listed in the table, include == in the required version. For instance, to install MXNet 1.2.0 with CUDA 8, run the command:

Building MXNet from Source

There is also the option of building MXNet from source, in which case you can easily install builds that are specific to supported languages such as Scala, Julia, R or Perl. There are two steps involved in the process:

  1. From the C++ source code of MXNet, build the shared library in your machine.
  2. Install the MXNet packages that are supported for the language. There are some scripts that handle all the MXNet builds dependencies.

Notably, you can change your build’s compilation options using the make/ file before building MXNet.

Building the Shared Library

There are two options for building the MXNet library: quick or manual.

Quick MXNet Installation

For the quick build of MXNet, you will find the script below in the /docs/install folder:

Manual MXNet Installation

Install git and the build tools.

Install OpenBLAS. A BLAS library helps to accelerate MXNet numerical computations on CPU machines. It comes in different versions including OpenBLAS, ATLAS, and MKL. While you can choose either of the libraries, we shall go with OpenBLAS for now:

Install OpenCV. OpenCV for MXNet enables the loading of images and augmenting operations efficiently.

Build an MXNet core shared library from downloaded MXNet sources. There is option for building on CPU or GPU

Build on CPU:

To build on GPU, verify you have all CUDA dependencies installed):

The USE_OPENCV and USE_BLAS file flags rely on OpenCV and BLAS library.

There are further compilation options in make/ once executed, the commands create a library named

If you need a library for visualizing network graphs on MXNet, you can additionally install graphviz.

Jupyter Notebook is another library you can install to run tutorials:

Install MXNet Language Packages

After installing the core library, install the preferred programming language interface package of your choice: Scala, R, Julia, Perl.

Installing the MXNet Scala Package

For this package, you will need the Maven package as a dependency. Run the scripts below:

Next, run the MXNet-Scala demo project. The project is available on the open source MXNet-Scala demo project’s README.

Run the Maven repository like so:

Linux CPU

Linux GPU

Install R Package for MXNet

There is also the option for running the R package, which is a two-step process:

  1. Build from source, which is an MXNet core shared library
  2. Create R bindings

There is the option for either quick or manual installation:

Quick Installation

For a quick MXNet-R installation, run the scripts below:

Manual MXNet-R Installation

The manual process is an alternative, but there are minimum requirements:

  1. GCC 4.8
  2. GNU Make

Build the MXNet core shared library by installing the tools:

Install OpenBLAS. We shall select ATLAS or MKL but in this case, we choose OpenBLAS.

Install OpenCV like so:

Build an MXNet core shared library after downloading the source.

Make the MXNet-R bindings and then install them like so:

Run the command below to verify your MXNet-R installation:

When prompted with an R prompt respond as so:

The output should be similar:

Install the Julia MXNet Package

The Julia MXNet package is available on GitHub but ins separate repository names MXNet.jl. However, the package requires that you set the MXNET_HOME environment variable to bind Julia to a libmxnet installation. Run the command below:

The root directory of libmxnet should have a path to the libmxnet installation on the machine. That is to mean, that $MXNET_HOME/lib contains the file available. The requirement is that in the root directory of libmxnet, say ~, run the following:

Additionally, you could also include the command in your ~/.bashrc file so as to install Julia package in the console like so:

If you are keen on learning more about Julia, check out the MXNet Julia documentation.

Install an MXNet Package for Scala

The MXNet-Scala package is another package that you could install, depending on your skill. With it, acquire Maven package as a dependency. On your Ubuntu machine, run the following:

Run the Maven repository like so:

Linux CPU

Linux GPU

Setting up for Scala was successful!

Install the MXNet Package for Perl

For Perl users, the first requirement is to must complete building the shared library. Thereafter, you can then build MXNet from its source. In the MXNet root directory, run the command below:


We have looked at the various methods of installing MXNet and its dependencies on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 server. Installation of MXNet is the first step for the deep learning project running on either CPU, GPU or both. Once installed, you would easily identify with the binaries that enable you to build image record files efficiently.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.