Skip to content

Configuring a Linux Mint 20 system to be able to build oce from source

Clark Richards edited this page Jul 19, 2024 · 12 revisions

Configuring a Linux Mint 20/22 system to be able to build oce from source

Clark Richards 2020-11-14 (updated 2022-11-06 and 2024-05-22)

The purpose of this document is to outline the steps required to configure a "clean" Linux Mint 20 system (equivalent to Ubuntu 20.04) to be able to build and use the R oce package. These instructions have been tested on both a native Ubuntu 20.04 install (2020-11-14) and on a Windows 10 WSL (windows subsystem for linux) installation (2022-11-06), as well as on a native Linux Mint 21 (Ubuntu 22.04, on 2024-05-22, where it may be necessary to install the g++ system compiler tools and gfortran).

Installing R 4.4 on Ubuntu 22

https://www.digitalocean.com/community/tutorials/how-to-install-r-on-ubuntu-22-04

Install the latest version of R (4.2.2 as of 2022-11-06)

From here:

  1. Install the dependencies necessary to add a new repository over HTTPS:
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
  1. Add the CRAN repository to your system sources’ list:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

For Ubuntu 22.04 (Jammy), instead do:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/'
  1. Install R by typing:
sudo apt update
sudo apt install r-base
  1. Check the R version:
R --version

and you should see:

R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

Install oce and the system packages required for building dependencies

The normal way to install a package at this point is to type:

install.packages('packageName')

at the R prompt. On linux, this will fetch the source tarball from CRAN and compile it for use. On Windows/OSX, it is often possible to install the binary (i.e. already compiled) package straight from CRAN, however that is not possible for Linux (this isn't entirely true, but not all packages are available as binary packages, including oce).

The oce dependencies are:

Depends:	R (≥ 2.15), gsw, methods, testthat, utils
Imports:	Rcpp
LinkingTo:	Rcpp
Suggests:	akima, automap, DBI, foreign, knitr, lubridate, ncdf4, ocedata, raster (≥ 1.4.3), rgeos, rgdal, rmarkdown, RSQLite, R.utils, sf, sp, tiff, XML

To install oce from CRAN at this point, type:

install.packages('oce')

at the R prompt. This will install oce with all the "Depends" packages (including their required dependencies):

> install.packages('oce')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("oce") :
  'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘~/R/x86_64-pc-linux-gnu-library/4.0’
to install packages into? (yes/No/cancel) yes
also installing the dependencies ‘utf8’, ‘backports’, ‘prettyunits’, ‘pillar’, ‘pkgconfig’, ‘vctrs’, ‘assertthat’, ‘glue’, ‘fansi’, ‘rprojroot’, ‘pkgbuild’, ‘rstudioapi’, ‘diffobj’, ‘rematch2’, ‘tibble’, ‘brio’, ‘callr’, ‘cli’, ‘crayon’, ‘desc’, ‘digest’, ‘ellipsis’, ‘evaluate’, ‘jsonlite’, ‘lifecycle’, ‘magrittr’, ‘pkgload’, ‘praise’, ‘processx’, ‘ps’, ‘R6’, ‘rlang’, ‘waldo’, ‘withr’, ‘gsw’, ‘testthat’, ‘Rcpp’

(Many of those dependencies are are due to the testthat package, I believe).

In order to install oce with full capabilities, we need to install all the "Suggests" packages, many of which require system libraries. These requirements show up in their DESCRIPTION file, e.g. for the sf package you can see:

SystemRequirements:	C++11, GDAL (>= 2.0.1), GEOS (>= 3.4.0), PROJ (>= 4.8.0)

Required system libraries for "Suggests" packages:

To install all the "Suggests" packages to be able to use every aspect of the oce package, a number of system libraries are required.

Add the ubuntugis-unstable repository

Because of recent changes and developments in various "GIS"-related packages, I recommend adding the ubuntugis-unstable package repository to make sure that you have the most recent versions available (the "stable" versions that are installed in the regular repos are typically a few years behind).

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update

See https://launchpad.net/~ubuntugis/+archive/ubuntu/ubuntugis-unstable

Once that is done, the required system libraries are:

  • libnetcdf-dev
  • libgeos-dev
  • libgdal-dev
  • libudunits2-dev
  • libxml2-dev

The above system libraries can be installed with e.g. $ sudo apt install libnetcdf-dev. To install them all at once, do:

sudo apt install libnetcdf-dev libgeos-dev libgdal-dev libudunits2-dev libxml2-dev

Update 2024-05-22

It may be necessary to install the g++ and gfortran compiler tools, which can be done with:

sudo apt update && sudo apt install build-essential gfortran

Installing the development version of oce, from Github

To install the bleeding edge version of oce, from the Github development site, there are a few options.

  1. It can be done manually by downloading the source (directly or with git), and building from the command line with:
R CMD build oce && R CMD INSTALL oce_1.3.0.tar.gz
  1. Alternatively, you can use the remotes package from within R:
install.packages('remotes') # if it's not already installed
remotes::install_github("dankelley/oce", ref="develop")

Detailed install notes for "Suggests" packages

What I'm going to do is go through installing the "Suggests" packages one by one, so that I can identify exactly which system libraries need to be installed along the way. It shouldn't be necessary to do it this way, if you followed the instructions above, but this was how I made sure I had all the pieces identified to create the instructions above.

akima

install.packages('akima')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘sp’

automap

install.packages('automap')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘xts’, ‘intervals’, ‘zoo’, ‘spacetime’, ‘FNN’, ‘plyr’, ‘gstat’, ‘reshape’

DBI

install.packages('DBI')

foreign

install.packages('foreign')

knitr

install.packages('knitr')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘mime’, ‘stringi’, ‘highr’, ‘markdown’, ‘stringr’, ‘yaml’, ‘xfun’

lubridate

install.packages('lubridate')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘generics’

ncdf4

Need the libnetcdf-dev system package installed:

$ sudo apt install libnetcdf-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  hdf5-helpers libaec-dev libaec0 libcurl4-gnutls-dev libhdf5-103 libhdf5-cpp-103 libhdf5-dev libnetcdf15 libsz2
Suggested packages:
  libcurl4-doc libgnutls28-dev libidn11-dev libkrb5-dev libldap2-dev librtmp-dev libssh2-1-dev libhdf5-doc netcdf-bin netcdf-doc
The following NEW packages will be installed:
  hdf5-helpers libaec-dev libaec0 libcurl4-gnutls-dev libhdf5-103 libhdf5-cpp-103 libhdf5-dev libnetcdf-dev libnetcdf15 libsz2
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,780 kB of archives.
After this operation, 20.7 MB of additional disk space will be used.
install.packages('ncdf4')

ocedata

install.packages('ocedata')

raster

install.packages('raster')

rgeos

To be able to get the latest versions of all the relevant "GIS" system libraries, install the ubuntugis-unstable repository:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update

See https://launchpad.net/~ubuntugis/+archive/ubuntu/ubuntugis-unstable

Requires the libgeos-dev system library:

$ sudo apt install libgeos-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libgeos-3.8.1 libgeos-c1v5
Suggested packages:
  libgdal-doc
The following NEW packages will be installed:
  libgeos-3.8.1 libgeos-c1v5 libgeos-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 697 kB of archives.
After this operation, 3,218 kB of additional disk space will be used.
install.packages('rgeos')

rgdal

Requires the libgdal-dev system library:

$ sudo apt install libgdal-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  autoconf automake autotools-dev default-libmysqlclient-dev gdal-data libarmadillo-dev libarmadillo9 libarpack2 libarpack2-dev libboost-dev
  libboost1.71-dev libcfitsio-dev libcfitsio-doc libcfitsio8 libcharls-dev libcharls2 libdap-dev libdap25 libdapclient6v5 libdapserver7v5 libepsilon-dev
  libepsilon1 libexpat1-dev libfreexl-dev libfreexl1 libfyba-dev libfyba0 libgdal27 libgeotiff-dev libgeotiff5 libgif-dev libhdf4-0-alt libhdf4-alt-dev
  libjbig-dev libjson-c-dev libkml-dev libkmlbase1 libkmlconvenience1 libkmldom1 libkmlengine1 libkmlregionator1 libkmlxsd1 libltdl-dev libminizip-dev
  libminizip1 libmysqlclient-dev libodbc1 libogdi-dev libogdi4.1 libopenjp2-7-dev libpoppler-dev libpoppler-private-dev libpq-dev libpq5 libproj-dev
  libproj19 libqhull-dev libqhull-r7 libqhull7 librttopo-dev librttopo1 libspatialite-dev libspatialite7 libsqlite3-dev libssl-dev libsuperlu-dev
  libsuperlu5 libtiff-dev libtiffxx5 libtool liburiparser-dev liburiparser1 libwebp-dev libxerces-c-dev libxerces-c3.2 libxml2-dev libzstd-dev odbcinst
  odbcinst1debian2 proj-bin proj-data unixodbc-dev uuid-dev
Suggested packages:
  autoconf-archive gnu-standards autoconf-doc libitpp-dev libboost-doc libboost1.71-doc libboost-atomic1.71-dev libboost-chrono1.71-dev
  libboost-container1.71-dev libboost-context1.71-dev libboost-contract1.71-dev libboost-coroutine1.71-dev libboost-date-time1.71-dev
  libboost-exception1.71-dev libboost-fiber1.71-dev libboost-filesystem1.71-dev libboost-graph1.71-dev libboost-graph-parallel1.71-dev
  libboost-iostreams1.71-dev libboost-locale1.71-dev libboost-log1.71-dev libboost-math1.71-dev libboost-mpi1.71-dev libboost-mpi-python1.71-dev
  libboost-numpy1.71-dev libboost-program-options1.71-dev libboost-python1.71-dev libboost-random1.71-dev libboost-regex1.71-dev
  libboost-serialization1.71-dev libboost-stacktrace1.71-dev libboost-system1.71-dev libboost-test1.71-dev libboost-thread1.71-dev libboost-timer1.71-dev
  libboost-type-erasure1.71-dev libboost-wave1.71-dev libboost1.71-tools-dev libmpfrc++-dev libntl-dev libgeotiff-epsg geotiff-bin gdal-bin libhdf4-doc
  hdf4-tools libtool-doc libmyodbc odbc-postgresql tdsodbc unixodbc-bin ogdi-bin libfreetype6-dev postgresql-doc-12 sqlite3-doc libssl-doc libsuperlu-doc
  gcj-jdk libxerces-c-doc
The following NEW packages will be installed:
  autoconf automake autotools-dev default-libmysqlclient-dev gdal-data libarmadillo-dev libarmadillo9 libarpack2 libarpack2-dev libboost-dev
  libboost1.71-dev libcfitsio-dev libcfitsio-doc libcfitsio8 libcharls-dev libcharls2 libdap-dev libdap25 libdapclient6v5 libdapserver7v5 libepsilon-dev
  libepsilon1 libexpat1-dev libfreexl-dev libfreexl1 libfyba-dev libfyba0 libgdal-dev libgdal27 libgeotiff-dev libgeotiff5 libgif-dev libhdf4-0-alt
  libhdf4-alt-dev libjbig-dev libjson-c-dev libkml-dev libkmlbase1 libkmlconvenience1 libkmldom1 libkmlengine1 libkmlregionator1 libkmlxsd1 libltdl-dev
  libminizip-dev libminizip1 libmysqlclient-dev libodbc1 libogdi-dev libogdi4.1 libopenjp2-7-dev libpoppler-dev libpoppler-private-dev libpq-dev libpq5
  libproj-dev libproj19 libqhull-dev libqhull-r7 libqhull7 librttopo-dev librttopo1 libspatialite-dev libspatialite7 libsqlite3-dev libssl-dev
  libsuperlu-dev libsuperlu5 libtiff-dev libtiffxx5 libtool liburiparser-dev liburiparser1 libwebp-dev libxerces-c-dev libxerces-c3.2 libxml2-dev
  libzstd-dev odbcinst odbcinst1debian2 proj-bin proj-data unixodbc-dev uuid-dev
0 upgraded, 84 newly installed, 0 to remove and 0 not upgraded.
Need to get 58.9 MB of archives.
After this operation, 384 MB of additional disk space will be used.
install.packages('rgdal')

rmarkdown

install.packages('rmarkdown')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘base64enc’, ‘htmltools’, ‘tinytex’

RSQLite

install.packages('RSQLite')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘bit’, ‘bit64’, ‘blob’, ‘memoise’, ‘BH’, ‘plogr’

R.utils

install.packages('R.utils')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘R.oo’, ‘R.methodsS3’

sf

Needs the system library libudunits2-dev:

$ sudo apt install libudunits2-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libudunits2-0 libudunits2-data
The following NEW packages will be installed:
  libudunits2-0 libudunits2-data libudunits2-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 429 kB of archives.
After this operation, 1,026 kB of additional disk space will be used.
install.packages('sf')
Installing package into ‘/home/clark/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘e1071’, ‘classInt’, ‘units’

sp

install.packages('sp')

tiff

install.packages('tiff')

XML

This package requires the libxml2 system library, but for this system it was already installed (probably a dependency of one of the previous library installations).

install.packages('XML')
Clone this wiki locally