This page explains how to install the Eigen linear algebra library on Ubuntu.

Install dependencies and tools

First, install GCC, CMake, GNU Make and Git if you haven't already.

sudo apt update
sudo apt install gcc g++ cmake make git

Download and install

#!/usr/bin/env bash

# Script to download and install Eigen3

set -ex

version="3.3.7" # Release tag on GitLab
prefix="$HOME/.local"

cd /tmp
# Download
git clone --single-branch --depth=1 --branch "$version" \
    https://gitlab.com/libeigen/eigen.git
mkdir eigen/build && cd $_
# Configure
cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="$prefix"
# Install
make install
You don't have to build anything, because Eigen is a header-only library.

Usage

To use Eigen in your project, you can use the following CMake snippet:

find_package(Eigen3 REQUIRED)

add_executable(eigen-demo main.cpp)
target_link_libraries(eigen-demo PRIVATE Eigen3::Eigen)

CMake has to find Eigen, so you need to make sure that $HOME/.local is in its search paths. See Installing Locally.

Tested on