Installing GMT 6 on Ubuntu 20.04 LTS

Table of Contents

GMT 6 is a popular plotting tool in regional and earth sciences, and it is a great software to draw the most beautiful figures with print quality.
This is a memorandum of the build and installation on Ubuntu 20.04 LTS on WLS2 of Windows 10 Pro. I referred to this site (in Japanese).
You may be able to install it with apt, but it is easy to build and recommended in the official site.

Install dependent packages

The first step is to install dependent packages. If some package is already installed, it will be skipped.

sudo apt update 
sudo apt upgrade -y
sudo apt install -y build-essential cmake libcurl4-gnutls-dev libnetcdf-dev gdal-bin libgdal-dev libfftw3-dev libpcre3-dev liblapack-dev libblas-dev libglib2.0-dev ghostscript ghostscript-x graphicsmagick ffmpeg xdg-utils

Setting the GMT version

To make the installation easier, you can set each version as shell variable. You may set the latest version. The following are the latest versions as of March 23, 2021.

GMT_VERSION="6.1.1"
GSHHG_VERSION="2.3.7"
DCW_VERSION="1.1.4"

Download and extract the source code

Create a src directory under your home directory (/ home/$USER/, where $USER should be your user name), download the source codes, and extract them.

# Work in your home directory
mkdir src
cd src
wget "https://github.com/GenericMappingTools/gmt/releases/download/${GMT_VERSION}/gmt-${GMT_VERSION}-src.tar.gz"
wget "https://github.com/GenericMappingTools/gshhg-gmt/releases/download/${GSHHG_VERSION}/gshhg-gmt-${GSHHG_VERSION}.tar.gz"
wget "https://github.com/GenericMappingTools/dcw-gmt/releases/download/${DCW_VERSION}/dcw-gmt-${DCW_VERSION}.tar.gz"
tar xzvf gmt-${GMT_VERSION}-src.tar.gz
tar xzvf gshhg-gmt-${GSHHG_VERSION}.tar.gz
tar xzvf dcw-gmt-${DCW_VERSION}.tar.gz

GSHHG and DCW are being moved from ~/src/ to ~/local/. Note this to avoid inconsistencies such as GSHHG not being found when the GMT script is executed.

mv gshhg-gmt-${GSHHG_VERSION} ../local/
mv dcw-gmt-${DCW_VERSION} ../local/

Creating a build script

Create a build script build_gmt.sh in /home/$USER/src/ (the src directory under your home directory).

#!/bin/bash
# build_gmt.sh
GMT_VERSION="6.1.1"
GSHHG_VERSION="2.3.7"
DCW_VERSION="1.1.4"
GSHHG_ROOT=/home/$USER/local/gshhg-gmt-${GSHHG_VERSION}
DCW_ROOT=/home/$USER/local/dcw-gmt-${DCW_VERSION}

cd gmt-${GMT_VERSION}
cat ./cmake/ConfigUserTemplate.cmake | \
sed -e 's%\#set (GSHHG_ROOT "gshhg_path"%'"set (GSHHG_ROOT ${GSHHG_ROOT}"'%g' | \
sed -e 's/\#set (COPY_GSHHG FALSE)/set (COPY_GSHHG TRUE)/g' | \
sed -e 's%\#set (DCW_ROOT "dcw-gmt_path"%'"set (DCW_ROOT ${DCW_ROOT}"'%g' | \
sed -e 's/\#set (COPY_DCW FALSE)/set (COPY_DCW TRUE)/g' \
> ./cmake/ConfigUser.cmake
mkdir build

Run the script build_gmt.sh using source.

source build_gmt.sh

Build and installation

Go to the build directory; build and install. The option of -j4 denotes building with 4 cores. Specifying the number of total cores in your system is fine.

cd build
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j4
sudo make install

The executable will be copied to /usr/local/bin/. In this case, there is no need to add PATH.

References

2 thoughts on “Installing GMT 6 on Ubuntu 20.04 LTS

  1. Nasir Seismology says:

    Excellent guidance.
    Easy to install.

  2. Abdisa kawo says:

    perfect demonstration!!!

Leave a Reply to Nasir Seismology Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.