The Generic Mapping Tools (GMT) are a suite of tools for making maps. The graphics generated with default settings in GMT exceed in many ways those which would come out of most users’ ArcGIS work. Admittedly, GMT does come with a steep learning curve, not excluding the installation process. For earlier versions of GMT (4.x.x) installation is more simple and direct, as you can just install from the Ubuntu Software Center (or other package managers), however, these managers typically don’t have the most recent versions — in this case GMT version 5.1.x.
Without further adieu, in the following steps, we will collect the necessary components of the GMT install, compile, and install. Most of the guide comes from the GMT website, but is supplemented with some of what I think are helpful details for new users to GMT.
READ: This guide uses the terminal and a file explorer, but the entire install can be done from the terminal; in some steps incomplete commands to do operations via terminal are listed in square brackets […] where items in carrot brackets must be replaced with system/your-install specific items <…>. All terminal commands listed without brackets are required for successful install.
1) Begin by installing several dependency packages. Running the following command will be sufficient, as any already installed packages will be skipped.
For Ubuntu 16.04 to 17.10:
sudo apt-get install subversion ghostscript build-essential cmake libnetcdf-dev libgdal1-dev libfftw3-dev libpcre3-dev
For Ubuntu 18.04 (and later?):
sudo apt install subversion ghostscript build-essential cmake libnetcdf-dev libfftw3-dev libpcre3-dev libgdal-dev gdal-bin
2) Download the latest stable version of GMT using
svn checkout svn://gmtserver.soest.hawaii.edu/gmt5/trunk gmt5-dev
3) Visit the GMT download page and download the latest versions of the packages titled “gshhg-gmt-x.x.x.tar.gz” and “dcw-gmt-x.x.x.tar.gz”.
4) Copy each compressed folder into the directory downloaded via subversion — this should be located at ~/gmt5-dev by default. Uncompress the folders here.
[cp ./ && cp ./]
[tar -zxvf gshhg-gmt-x.x.x.tar.gz]
5) In the ~/gmt5-dev folder, enter the cmake folder, make a copy of the ConfigUserTemplate.cmake file and rename the copy to ConfigUser.cmake. Open this file in an editor.
[cp ConfigUserTemplate.cmake ./ConfigUser.cmake]
6) You need to edit the following lines of this file:
a. enable (uncomment) line 112 (set (GSHHG_ROOT…) and replace the path name with the absolute path to the gshhg-gmt-x.x.x folder.
b. enable copy in line 115
c. enable line 118 and replace the path name with the absolute path to the dcw-gmt-x.x.x folder.
d. enable copy in line 121
Save the file and return to the terminal. NOTE: the line numbers may change with updates by the GMT devs to the .cmake file.
7) cd into the ~/gmt5-dev folder and execute the following commands, waiting to finish each time.
sudo make install
That should complete your install of GMT 5.1.x! To test the install, try the following command into a new terminal window
gmt pscoast -R-130/-30/-50/50 -Jm0.025i -B30g30:.Mercator: -Di -W > mercator.ps
Check out the first article of my series on making maps with GMT here!
UPDATE: These instructions were tested Feb 2018 on Ubuntu 16.04 LTS and are still effective. They were tested April 2018 on Ubuntu 18.04 and are effective.
NOTE: The Anaconda Python distribution may cause a conflict in some dependency libraries. A workable solution is to remove Anaconda, including all hidden files, install GMT as detailed above, and then reinstall Anaconda if needed. Thanks to Frank Pazzaglia for this solution.