Cannot install tseries and forecast packages in R

I'm trying to install the packages mentioned above, but I'm not able to. I've followed several tips, even so it was not possible to install the packages above. Even following the following commands, which already work with some packages, cannot be installed:

install.packages("forecast", INSTALL_opts = "--no-lock")
install.packages("tseries", dependencies = T)

When I try the first option the result is this:

Installing package into ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘quadprog’

tentando a URL 'https://cloud.r-project.org/src/contrib/quadprog_1.5-8.tar.gz'
Content type 'application/x-gzip' length 36141 bytes (35 KB)
==================================================
downloaded 35 KB

tentando a URL 'https://cloud.r-project.org/src/contrib/tseries_0.10-49.tar.gz'
Content type 'application/x-gzip' length 170539 bytes (166 KB)
==================================================
downloaded 166 KB

* installing *source* package ‘quadprog’ ...
** package ‘quadprog’ successfully unpacked and MD5 sums checked
staged installation is only possible with locking
** using non-staged installation
** libs
gfortran -fno-optimize-sibling-calls  -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong -msse2 -mfpmath=sse   -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong  -c aind.f -o aind.o
/bin/bash: gfortran: comando não encontrado
make: *** [/usr/lib/R/etc/Makeconf:190: aind.o] Erro 127
ERROR: compilation failed for package ‘quadprog’
* removing ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0/quadprog’
Warning in install.packages :
  installation of package ‘quadprog’ had non-zero exit status
ERROR: dependency ‘quadprog’ is not available for package ‘tseries’
* removing ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0/tseries’
Warning in install.packages :
  installation of package ‘tseries’ had non-zero exit status

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

A segunda opção apresenta o seguinte resultado:

Installing package into ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘quadprog’

tentando a URL 'https://cloud.r-project.org/src/contrib/quadprog_1.5-8.tar.gz'
Content type 'application/x-gzip' length 36141 bytes (35 KB)
==================================================
downloaded 35 KB

tentando a URL 'https://cloud.r-project.org/src/contrib/tseries_0.10-49.tar.gz'
Content type 'application/x-gzip' length 170539 bytes (166 KB)
==================================================
downloaded 166 KB

* installing *source* package ‘quadprog’ ...
** package ‘quadprog’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gfortran -fno-optimize-sibling-calls  -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong -msse2 -mfpmath=sse   -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong  -c aind.f -o aind.o
/bin/bash: gfortran: comando não encontrado
make: *** [/usr/lib/R/etc/Makeconf:190: aind.o] Erro 127
ERROR: compilation failed for package ‘quadprog’
* removing ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0/quadprog’
Warning in install.packages :
  installation of package ‘quadprog’ had non-zero exit status
ERROR: dependency ‘quadprog’ is not available for package ‘tseries’
* removing ‘/home/vitor/R/x86_64-pc-linux-gnu-library/4.0/tseries’
Warning in install.packages :
  installation of package ‘tseries’ had non-zero exit status

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

How to proceed properly?


"gfortran: comando não encontrado": The gfortran compiler is missing.

On Linux, R builds packages from source. Therefore you need the gcc toolchain. To get the bare minimum, you may do:

sudo apt install build-essential gfortran

Some R packages need other Linux packages as well. If you try to install tidyverse for instance, I believe you need libicu-dev libbz2-dev libxml2-dev libcurl4-openssl-dev libssl-dev as well. In general, to find out which Linux package is missing, you will need to decipher the compilation error messages, and maybe check the source code or the web for additional information.