R package の devtools をubuntuにインストールした時に発生したエラー ~ had non-zero exit status を解決する。

ubuntuにdevtoolsをインストールする際に発生したエラーにつまずいたので、備忘録として記しておきます。

## 発生したエラー
以下に発生したエラーを貼っています。(長いので折りたたんでいます。)

<details><summary>1回目のエラーメッセージ</summary>

```shell
> install.packages("devtools")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("devtools") :
  '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.1’
to install packages into? (yes/No/cancel) yes
also installing the dependencies ‘credentials’, ‘openssl’, ‘httr2’, ‘systemfonts’, ‘textshaping’, ‘curl’, ‘gert’, ‘gh’, ‘httr’, ‘ragg’, ‘xml2’, ‘usethis’, ‘pkgdown’, ‘rcmdcheck’, ‘roxygen2’, ‘rversions’, ‘urlchecker’
(中略)
* installing *source* package ‘openssl’ ...
** package ‘openssl’ successfully unpacked and MD5 sums checked
** using staged installation
Using PKG_CFLAGS=
--------------------------- [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: openssl (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=...'
-------------------------- [ERROR MESSAGE] ---------------------------
tools/version.c:1:10: fatal error: openssl/opensslv.h: No such file or directory
    1 | #include <openssl/opensslv.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘openssl’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/openssl’
* installing *source* package ‘systemfonts’ ...
** package ‘systemfonts’ successfully unpacked and MD5 sums checked
** using staged installation
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'freetype2' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lfontconfig -lfreetype
--------------------------- [ANTICONF] --------------------------------
Configuration failed to find the fontconfig freetype2 library. Try installing:
 * deb: libfontconfig1-dev (Debian, Ubuntu, etc)
 * rpm: fontconfig-devel (Fedora, EPEL)
 * csw: fontconfig_dev (Solaris)
 * brew: freetype (OSX)
If fontconfig freetype2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a fontconfig freetype2.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=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: fontconfig/fontconfig.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘systemfonts’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/systemfonts’
* installing *source* package ‘curl’ ...
** package ‘curl’ successfully unpacked and MD5 sums checked
** using staged installation
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lcurl
--------------------------- [ANTICONF] --------------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.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=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: curl/curl.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘curl’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/curl’
* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
 * deb: libxml2-dev (Debian, Ubuntu, etc)
 * rpm: libxml2-devel (Fedora, CentOS, RHEL)
 * csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.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=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘xml2’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/xml2’
ERROR: dependencies ‘openssl’, ‘curl’ are not available for package ‘credentials’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/credentials’
ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr2’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/httr2’
ERROR: dependency ‘systemfonts’ is not available for package ‘textshaping’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/textshaping’
ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/httr’
ERROR: dependency ‘curl’ is not available for package ‘rcmdcheck’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/rcmdcheck’
ERROR: dependency ‘xml2’ is not available for package ‘roxygen2’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/roxygen2’
ERROR: dependencies ‘curl’, ‘xml2’ are not available for package ‘rversions’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/rversions’
ERROR: dependencies ‘curl’, ‘xml2’ are not available for package ‘urlchecker’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/urlchecker’
ERROR: dependencies ‘credentials’, ‘openssl’ are not available for package ‘gert’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/gert’
ERROR: dependency ‘httr2’ is not available for package ‘gh’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/gh’
ERROR: dependencies ‘systemfonts’, ‘textshaping’ are not available for package ‘ragg’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/ragg’
ERROR: dependencies ‘curl’, ‘gert’, ‘gh’ are not available for package ‘usethis’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/usethis’
ERROR: dependencies ‘httr’, ‘ragg’, ‘xml2’ are not available for package ‘pkgdown’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/pkgdown’
ERROR: dependencies ‘usethis’, ‘pkgdown’, ‘rcmdcheck’, ‘roxygen2’, ‘rversions’, ‘urlchecker’ are not available for package ‘devtools’
* removing ‘/home/hello/R/x86_64-pc-linux-gnu-library/4.1/devtools’

The downloaded source packages are in
	‘/tmp/Rtmp9vMEe8/downloaded_packages’
There were 18 warnings (use warnings() to see them)
```
</details>

<details><summary>2回目のエラーメッセージ</summary>

```shell
(前略)
--------------------------- [ANTICONF] --------------------------------
Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
 * deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
 * rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
 * csw: libharfbuzz_dev libfribidi_dev (Solaris)
 * brew: harfbuzz fribidi (OSX)
If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.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=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: hb-ft.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘textshaping’
* removing ‘/usr/local/lib/R/site-library/textshaping’
* installing *source* package ‘httr’ ...
** package ‘httr’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (httr)
* installing *source* package ‘rcmdcheck’ ...
** package ‘rcmdcheck’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rcmdcheck)
* installing *source* package ‘roxygen2’ ...
** package ‘roxygen2’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c cpp11.cpp -o cpp11.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c escapeExamples.cpp -o escapeExamples.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c isComplete.cpp -o isComplete.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c leadingSpaces.cpp -o leadingSpaces.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c parser2.cpp -o parser2.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/cpp11/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c wrapUsage.cpp -o wrapUsage.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o roxygen2.so cpp11.o escapeExamples.o isComplete.o leadingSpaces.o parser2.o wrapUsage.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-roxygen2/00new/roxygen2/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (roxygen2)
* installing *source* package ‘rversions’ ...
** package ‘rversions’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rversions)
* installing *source* package ‘urlchecker’ ...
** package ‘urlchecker’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (urlchecker)
* installing *source* package ‘gert’ ...
** package ‘gert’ successfully unpacked and MD5 sums checked
** using staged installation
Found OpenSSL3
Using static libgit2 for Linux x86_64
Using PKG_CFLAGS=-DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include
Using PKG_LIBS=-L/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/lib -lstatgit2 -lrt -lpthread -lstatssh2 -lstatssl -lstatcrypto -ldl
Configuration OK!
** libs
rm -f gert.so branch.o clone.o commit.o config.o conflicts.o files.o ignore.o init.o merge.o rebase.o stash.o submodules.o tag.o utils.o version.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c branch.c -o branch.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c clone.c -o clone.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c commit.c -o commit.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c config.c -o config.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c conflicts.c -o conflicts.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c files.c -o files.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c ignore.c -o ignore.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c merge.c -o merge.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c rebase.c -o rebase.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stash.c -o stash.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c submodules.c -o submodules.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c tag.c -o tag.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c utils.c -o utils.o
gcc -I"/usr/share/R/include" -DNDEBUG -DSTATIC_LIBGIT2 -I/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/include -DR_NO_REMAP -DSTRICT_R_HEADERS    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4A2Reg/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c version.c -o version.o
gcc -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o gert.so branch.o clone.o commit.o config.o conflicts.o files.o ignore.o init.o merge.o rebase.o stash.o submodules.o tag.o utils.o version.o -L/tmp/RtmpqKhLaL/R.INSTALL8eba3a281f1c/gert/libgit2-1.4.2-x86_64_linux/lib -lstatgit2 -lrt -lpthread -lstatssh2 -lstatssl -lstatcrypto -ldl -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-gert/00new/gert/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (gert)
* installing *source* package ‘gh’ ...
** package ‘gh’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (gh)
ERROR: dependency ‘textshaping’ is not available for package ‘ragg’
* removing ‘/usr/local/lib/R/site-library/ragg’
* installing *source* package ‘usethis’ ...
** package ‘usethis’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (usethis)
ERROR: dependency ‘ragg’ is not available for package ‘pkgdown’
* removing ‘/usr/local/lib/R/site-library/pkgdown’
ERROR: dependency ‘pkgdown’ is not available for package ‘devtools’
* removing ‘/usr/local/lib/R/site-library/devtools’

The downloaded source packages are in
	‘/tmp/RtmpH2i1vg/downloaded_packages’
Warning messages:
1: In install.packages("devtools") :
  installation of package ‘textshaping’ had non-zero exit status
2: In install.packages("devtools") :
  installation of package ‘ragg’ had non-zero exit status
3: In install.packages("devtools") :
  installation of package ‘pkgdown’ had non-zero exit status
4: In install.packages("devtools") :
  installation of package ‘devtools’ had non-zero exit status
```
</details>
<details><summary>3回目のエラーメッセージ</summary>

```shell
(前略)
-----------------------------[ ANTICONF ]-------------------------------
Configuration failed to find one of freetype2 libpng libtiff-4 libjpeg. Try installing:
 * deb: libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev (Debian, Ubuntu, etc)
 * rpm: freetype-devel libpng-devel libtiff-devel libjpeg-turbo-devel (Fedora, CentOS, RHEL)
 * csw: libfreetype_dev libpng16_dev libtiff_dev libjpeg_dev (Solaris)
If freetype2 libpng libtiff-4 libjpeg is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a freetype2 libpng libtiff-4 libjpeg.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=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: ft2build.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘ragg’
* removing ‘/usr/local/lib/R/site-library/ragg’
ERROR: dependency ‘ragg’ is not available for package ‘pkgdown’
* removing ‘/usr/local/lib/R/site-library/pkgdown’
ERROR: dependency ‘pkgdown’ is not available for package ‘devtools’
* removing ‘/usr/local/lib/R/site-library/devtools’

The downloaded source packages are in
	‘/tmp/RtmpZz5q9A/downloaded_packages’
Warning messages:
1: In install.packages("devtools") :
  installation of package ‘ragg’ had non-zero exit status
2: In install.packages("devtools") :
  installation of package ‘pkgdown’ had non-zero exit status
3: In install.packages("devtools") :
  installation of package ‘devtools’ had non-zero exit status
```
</details>

## 解決方法
エラー文の中で注目すべき部分は、以下の[ANTICONF]部分です。
各OSごとにインストールすべきソフトウェアを示してくれています。指示に従ってインストールしましょう。

```shell
--------------------------- [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: openssl (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=...'
```
※上記の[ANICONF]の表示が複数出ているので、足りていないソフトウェアをすべて入れます。

実は、丁寧に解決策の案を提示してくれています。解決策の案に従って、足りていないソフトウェアをインストールしましょう。これを何度か繰り返せば問題なくインストールできました。
以下、devtoolsのインストールエラーを解決するためにインストールした時のコマンドです。
```shell
$ sudo apt install libssl-dev libfontconfig1-dev libcurl4-openssl-dev libxml2-dev
$ sudo apt install libharfbuzz-dev libfribidi-dev
$ sudo apt install libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev
```

## 終わりに
ここまで記事を読んでいただきありがとうございます。
皆さんの快適なRライフの一助となれたらうれしいです。
では、また他の記事でお会いしましょう。
バイバイ (@^^)/~~~