How to fix R openssl error fatal error: openssl/opensslv.h: File or directory not found

Problem:

When installing the R openssl package using

BiocManager::install("openssl")

or any package depending on the openssl package, you see an error message like

-------------------------- [ERROR MESSAGE] ---------------------------
tools/version.c:1:10: fatal error: openssl/opensslv.h: File or directory not found
    1 | #include <openssl/opensslv.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘openssl’
* removing ‘/home/uli/R/x86_64-pc-linux-gnu-library/4.0/openssl’

Solution:

You need to install OpenSSL. On Ubuntu, install it using

sudo apt -y install libssl-dev

For other systems, see the description just above the error message by the authors of the package:

--------------------------- [ANTICONF] --------------------------------
Configuration failed because openssl was not found. Try installing:
 * deb: libssl-dev (Debian, Ubuntu, etc)
 * rpm: openssl-devel (Fedora, CentOS, RHEL)
 * csw: libssl_dev (Solaris)
 * brew: [email protected] (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'