Installing GMT 6 on Ubuntu 20.04 LTS

Table of Content

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.


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 "${GMT_VERSION}/gmt-${GMT_VERSION}-src.tar.gz"
wget "${GSHHG_VERSION}/gshhg-gmt-${GSHHG_VERSION}.tar.gz"
wget "${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 in /home/$USER/src/ (the src directory under your home directory).


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 using source.


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.


One thought on “Installing GMT 6 on Ubuntu 20.04 LTS

  1. Nasir Seismology says:

    Excellent guidance.
    Easy to install.

Leave a 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.