Can't install ggplot2 on Ubuntu

I can't install ggplot2. It looks like it's a library compile error:

Installing 'ggplot2' ...
[1/4] Installing digest...
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/digest_0.6.29.tar.gz'
Content type 'application/x-gzip' length 162775 bytes (158 KB)
==================================================
downloaded 158 KB

* installing *source* package ‘digest’ ...
** package ‘digest’ successfully unpacked and MD5 sums checked
** using staged installation
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c SpookyV2.cpp -o SpookyV2.o
** libs
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c aes.c -o aes.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3.c -o blake3.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3_dispatch.c -o blake3_dispatch.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3_portable.c -o blake3_portable.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c crc32.c -o crc32.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c digest.c -o digest.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c digest2int.c -o digest2int.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/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 -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c md5.c -o md5.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c pmurhash.c -o pmurhash.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c raes.c -o raes.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha1.c -o sha1.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha2.c -o sha2.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha256.c -o sha256.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c spooky_serialize.cpp -o spooky_serialize.o
[2/4] Installing isoband...
In file included from spooky_serialize.cpp:25:
/usr/share/R/include/R.h:39:11: fatal error: cstdlib: No such file or directory
   39 | # include <cstdlib>
      |           ^~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: spooky_serialize.o] Error 1
ERROR: compilation failed for package ‘digest’
* removing ‘/usr/local/lib/R/site-library/digest’

The downloaded source packages are in
	‘/tmp/RtmpLPVfC3/downloaded_packages’
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/isoband_0.2.5.tar.gz'
Content type 'application/x-gzip' length 1671911 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

* installing *source* package ‘isoband’ ...
** package ‘isoband’ successfully unpacked and MD5 sums checked
** using staged installation
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -Itestthat     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c clip-lines.cpp -o clip-lines.o
** libs
In file included from clip-lines.cpp:3:
/usr/share/R/include/R.h:39:11: fatal error: cstdlib: No such file or directory
   39 | # include <cstdlib>
      |           ^~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: clip-lines.o] Error 1
ERROR: compilation failed for package ‘isoband’
* removing ‘/usr/local/lib/R/site-library/isoband’
[3/4] Installing scales...

The downloaded source packages are in
	‘/tmp/RtmpLPVfC3/downloaded_packages’
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘farver’

trying URL 'https://cloud.r-project.org/src/contrib/farver_2.1.0.tar.gz'
Content type 'application/x-gzip' length 1281864 bytes (1.2 MB)
==================================================
downloaded 1.2 MB

trying URL 'https://cloud.r-project.org/src/contrib/scales_1.1.1.tar.gz'
Content type 'application/x-gzip' length 515201 bytes (503 KB)
==================================================
downloaded 503 KB

g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c ColorSpace.cpp -o ColorSpace.o
* installing *source* package ‘farver’ ...
** package ‘farver’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
In file included from ColorSpace.cpp:1:
ColorSpace.h:4:10: fatal error: typeinfo: No such file or directory
    4 | #include <typeinfo>
      |          ^~~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: ColorSpace.o] Error 1
ERROR: compilation failed for package ‘farver’
* removing ‘/usr/local/lib/R/site-library/farver’
[4/4] Installing ggplot2...
ERROR: dependency ‘farver’ is not available for package ‘scales’
* removing ‘/usr/local/lib/R/site-library/scales’

The downloaded source packages are in
	‘/tmp/RtmpLPVfC3/downloaded_packages’
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘farver’, ‘digest’, ‘isoband’, ‘scales’

trying URL 'https://cloud.r-project.org/src/contrib/farver_2.1.0.tar.gz'
Content type 'application/x-gzip' length 1281864 bytes (1.2 MB)
==================================================
downloaded 1.2 MB

trying URL 'https://cloud.r-project.org/src/contrib/digest_0.6.29.tar.gz'
Content type 'application/x-gzip' length 162775 bytes (158 KB)
==================================================
downloaded 158 KB

trying URL 'https://cloud.r-project.org/src/contrib/isoband_0.2.5.tar.gz'
Content type 'application/x-gzip' length 1671911 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

trying URL 'https://cloud.r-project.org/src/contrib/scales_1.1.1.tar.gz'
Content type 'application/x-gzip' length 515201 bytes (503 KB)
==================================================
downloaded 503 KB

trying URL 'https://cloud.r-project.org/src/contrib/ggplot2_3.3.5.tar.gz'
Content type 'application/x-gzip' length 3063309 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

* installing *source* package ‘farver’ ...
** package ‘farver’ successfully unpacked and MD5 sums checked
** using staged installation
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c ColorSpace.cpp -o ColorSpace.o
** libs
In file included from ColorSpace.cpp:1:
ColorSpace.h:4:10: fatal error: typeinfo: No such file or directory
    4 | #include <typeinfo>
      |          ^~~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: ColorSpace.o] Error 1
ERROR: compilation failed for package ‘farver’
* removing ‘/usr/local/lib/R/site-library/farver’
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c SpookyV2.cpp -o SpookyV2.o
* installing *source* package ‘digest’ ...
** package ‘digest’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c aes.c -o aes.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3.c -o blake3.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3_dispatch.c -o blake3_dispatch.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c blake3_portable.c -o blake3_portable.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c crc32.c -o crc32.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c digest.c -o digest.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c digest2int.c -o digest2int.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/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 -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c md5.c -o md5.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c pmurhash.c -o pmurhash.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c raes.c -o raes.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha1.c -o sha1.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha2.c -o sha2.o
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c sha256.c -o sha256.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c spooky_serialize.cpp -o spooky_serialize.o
In file included from spooky_serialize.cpp:25:
/usr/share/R/include/R.h:39:11: fatal error: cstdlib: No such file or directory
   39 | # include <cstdlib>
      |           ^~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: spooky_serialize.o] Error 1
ERROR: compilation failed for package ‘digest’
* removing ‘/usr/local/lib/R/site-library/digest’
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -Itestthat     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c clip-lines.cpp -o clip-lines.o
* installing *source* package ‘isoband’ ...
** package ‘isoband’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
In file included from clip-lines.cpp:3:
/usr/share/R/include/R.h:39:11: fatal error: cstdlib: No such file or directory
   39 | # include <cstdlib>
      |           ^~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:177: clip-lines.o] Error 1
ERROR: compilation failed for package ‘isoband’
* removing ‘/usr/local/lib/R/site-library/isoband’
ERROR: dependency ‘farver’ is not available for package ‘scales’
* removing ‘/usr/local/lib/R/site-library/scales’
ERROR: dependencies ‘digest’, ‘isoband’, ‘scales’ are not available for package ‘ggplot2’
* removing ‘/usr/local/lib/R/site-library/ggplot2’

The downloaded source packages are in
	‘/tmp/RtmpLPVfC3/downloaded_packages’


✔ Package 'ggplot2' successfully installed.
Warning messages:
1: In utils::install.packages("digest", repos = "https://cloud.r-project.org") :
  installation of package ‘digest’ had non-zero exit status
2: In utils::install.packages("isoband", repos = "https://cloud.r-project.org") :
  installation of package ‘isoband’ had non-zero exit status
3: In utils::install.packages("scales", repos = "https://cloud.r-project.org") :
  installation of package ‘farver’ had non-zero exit status
4: In utils::install.packages("scales", repos = "https://cloud.r-project.org") :
  installation of package ‘scales’ had non-zero exit status
5: In utils::install.packages("ggplot2", repos = "https://cloud.r-project.org") :
  installation of package ‘farver’ had non-zero exit status
6: In utils::install.packages("ggplot2", repos = "https://cloud.r-project.org") :
  installation of package ‘digest’ had non-zero exit status
7: In utils::install.packages("ggplot2", repos = "https://cloud.r-project.org") :
  installation of package ‘isoband’ had non-zero exit status
8: In utils::install.packages("ggplot2", repos = "https://cloud.r-project.org") :
  installation of package ‘scales’ had non-zero exit status
9: In utils::install.packages("ggplot2", repos = "https://cloud.r-project.org") :
  installation of package ‘ggplot2’ had non-zero exit status

I am using Ubuntu 20.04.
R version:

platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          1.2                         
year           2021                        
month          11                          
day            01                          
svn rev        81115                       
language       R                           
version.string R version 4.1.2 (2021-11-01)
nickname       Bird Hippie           

Hi,

as it fails with fatal error

fatal error: cstdlib: No such file or directory

I would suggest to start looking for cstdlib first:

sapi@t5810:~$ find /usr/ -iname cstdlib
/usr/include/boost/compatibility/cpp_c_headers/cstdlib
/usr/include/c++/10/cstdlib
/usr/include/c++/10/tr1/cstdlib

If there is nothing, then consider (re)instalation of it

sudo apt install libstdc++-10-dev

Hope it helps,
Grzegorz

2 Likes

Thanks for the help.
I have cstdlib:

/usr/include/c++/9/cstdlib
/usr/include/c++/9/tr1/cstdlib
/usr/include/c++/10/cstdlib
/usr/include/c++/10/10/cstdlib
/usr/include/c++/10/10/tr1/cstdlib
/usr/include/c++/10/tr1/cstdlib
/usr/include/boost/compatibility/cpp_c_headers/cstdlib

I also tried to reinstall libstdc++-10-dev (sudo apt install libstdc++-10-dev), but I am still having the same error during ggplot2 compilation.

Isn't there a way to install the library without compiling it from source?

Yes, you can get binaries for Ubuntu 20.04 from RSPM

install.packages("ggplot2", repos = 'https://packagemanager.rstudio.com/all/__linux__/focal/latest')
1 Like

or from deb package as well:

sapi@t5810:~$ sudo apt install r-cran-ggplot2 
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.