Installation of tidyverse had a non-zero exit status on mac

Hi, Im a beginning to R, I only took one class back in 2018.
Im running version 1.1423 2009-2018 Rstudio on my mac.
I'm only using R to make a few plots of my data (violin plot W box plot overlay) but cant seem to get past package install and library steps.

These are the various installs I tried and every package I try to install give the same warning that the install had a non-zero exit status.

install.packages("tidyverse", repo = 'https://mac.R-project.org')
install.packages("tidyverse", dependencies = TRUE)
install.packages( "Rcpp", type = "source" )
install.packages( "dplyr" )

Here are the errors:

Warning in install.packages :
installation of package ‘openssl’ had non-zero exit status

  • installing source package ‘fs’ ...
    ** package ‘fs’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘fs’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/fs’
    Warning in install.packages :
    installation of package ‘fs’ had non-zero exit status
  • installing source package ‘rex’ ...
    ** package ‘rex’ successfully unpacked and MD5 sums checked
    ** 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
  • DONE (rex)
  • installing source package ‘brio’ ...
    ** package ‘brio’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘brio’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/brio’
    Warning in install.packages :
    installation of package ‘brio’ had non-zero exit status
  • installing source package ‘ps’ ...
    ** package ‘ps’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘ps’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/ps’
    Warning in install.packages :
    installation of package ‘ps’ had non-zero exit status
  • installing source package ‘lubridate’ ...
    ** package ‘lubridate’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘lubridate’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/lubridate’
    Warning in install.packages :
    installation of package ‘lubridate’ had non-zero exit status
  • installing source package ‘rlang’ ...
    ** package ‘rlang’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘rlang’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rlang’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rlang’
    Warning in install.packages :
    installation of package ‘rlang’ had non-zero exit status
  • installing source package ‘xml2’ ...
    ** package ‘xml2’ successfully unpacked and MD5 sums checked
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    Found pkg-config cflags and libs!
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    Using PKG_CFLAGS=-I/usr/include/libxml2
    Using PKG_LIBS=-lxml2 -lz -lpthread -licucore -lm
    ------------------------- 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 ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/xml2’
    Warning in install.packages :
    installation of package ‘xml2’ had non-zero exit status
  • installing source package ‘ellipsis’ ...
    ** package ‘ellipsis’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘ellipsis’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/ellipsis’
    Warning in install.packages :
    installation of package ‘ellipsis’ had non-zero exit status
  • installing source package ‘knitr’ ...
    ** package ‘knitr’ successfully unpacked and MD5 sums checked
    ** R
    ** demo
    ** inst
    ** byte-compile and prepare package for lazy loading
    Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
    namespace ‘xfun’ 0.4 is being loaded, but >= 0.19 is required
    ERROR: lazy loading failed for package ‘knitr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/knitr’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/knitr’
    Warning in install.packages :
    installation of package ‘knitr’ had non-zero exit status
    ERROR: dependency ‘ps’ is not available for package ‘processx’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/processx’
    Warning in install.packages :
    installation of package ‘processx’ had non-zero exit status
    ERROR: dependency ‘openssl’ is not available for package ‘httr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/httr’
    Warning in install.packages :
    installation of package ‘httr’ had non-zero exit status
  • installing source package ‘purrr’ ...
    ** package ‘purrr’ successfully unpacked and MD5 sums checked
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘purrr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/purrr’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/purrr’
    Warning in install.packages :
    installation of package ‘purrr’ had non-zero exit status
    ERROR: dependency ‘ellipsis’ is not available for package ‘vctrs’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/vctrs’
    Warning in install.packages :
    installation of package ‘vctrs’ had non-zero exit status
    ERROR: dependency ‘processx’ is not available for package ‘callr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/callr’
    Warning in install.packages :
    installation of package ‘callr’ had non-zero exit status
    ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rvest’
    Warning in install.packages :
    installation of package ‘rvest’ had non-zero exit status
    ERROR: dependency ‘httr’ is not available for package ‘covr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/covr’
    Warning in install.packages :
    installation of package ‘covr’ had non-zero exit status
    ERROR: dependency ‘callr’ is not available for package ‘pkgbuild’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/pkgbuild’
    Warning in install.packages :
    installation of package ‘pkgbuild’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘vctrs’ are not available for package ‘tidyselect’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/tidyselect’
    Warning in install.packages :
    installation of package ‘tidyselect’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘vctrs’ are not available for package ‘hms’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/hms’
    Warning in install.packages :
    installation of package ‘hms’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘vctrs’ are not available for package ‘pillar’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/pillar’
    Warning in install.packages :
    installation of package ‘pillar’ had non-zero exit status
    ERROR: dependencies ‘callr’, ‘fs’ are not available for package ‘reprex’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/reprex’
    Warning in install.packages :
    installation of package ‘reprex’ had non-zero exit status
    ERROR: dependency ‘pkgbuild’ is not available for package ‘pkgload’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/pkgload’
    Warning in install.packages :
    installation of package ‘pkgload’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘pillar’, ‘vctrs’ are not available for package ‘tibble’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/tibble’
    Warning in install.packages :
    installation of package ‘tibble’ had non-zero exit status
    ERROR: dependency ‘tibble’ is not available for package ‘rematch2’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rematch2’
    Warning in install.packages :
    installation of package ‘rematch2’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘tibble’, ‘tidyselect’, ‘vctrs’ are not available for package ‘dplyr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/dplyr’
    Warning in install.packages :
    installation of package ‘dplyr’ had non-zero exit status
    ERROR: dependencies ‘ellipsis’, ‘tibble’ are not available for package ‘forcats’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/forcats’
    Warning in install.packages :
    installation of package ‘forcats’ had non-zero exit status
    ERROR: dependencies ‘hms’, ‘tibble’ are not available for package ‘readr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/readr’
    Warning in install.packages :
    installation of package ‘readr’ had non-zero exit status
    ERROR: dependencies ‘diffobj’, ‘rematch2’, ‘tibble’ are not available for package ‘waldo’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/waldo’
    Warning in install.packages :
    installation of package ‘waldo’ had non-zero exit status
    ERROR: dependencies ‘dplyr’, ‘ellipsis’, ‘tibble’, ‘tidyselect’, ‘vctrs’ are not available for package ‘dbplyr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/dbplyr’
    Warning in install.packages :
    installation of package ‘dbplyr’ had non-zero exit status
    ERROR: dependencies ‘forcats’, ‘hms’, ‘readr’, ‘tibble’, ‘tidyselect’, ‘vctrs’ are not available for package ‘haven’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/haven’
    Warning in install.packages :
    installation of package ‘haven’ had non-zero exit status
    ERROR: dependencies ‘dplyr’, ‘ellipsis’, ‘tibble’, ‘tidyselect’, ‘vctrs’ are not available for package ‘tidyr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/tidyr’
    Warning in install.packages :
    installation of package ‘tidyr’ had non-zero exit status
    ERROR: dependencies ‘dplyr’, ‘ellipsis’, ‘tibble’, ‘tidyr’ are not available for package ‘broom’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/broom’
    Warning in install.packages :
    installation of package ‘broom’ had non-zero exit status
    ERROR: dependencies ‘brio’, ‘callr’, ‘ellipsis’, ‘pkgload’, ‘processx’, ‘ps’, ‘waldo’ are not available for package ‘testthat’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/testthat’
    Warning in install.packages :
    installation of package ‘testthat’ had non-zero exit status
    ERROR: dependency ‘testthat’ is not available for package ‘isoband’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/isoband’
    Warning in install.packages :
    installation of package ‘isoband’ had non-zero exit status
    ERROR: dependencies ‘broom’, ‘tibble’, ‘tidyr’, ‘tidyselect’, ‘vctrs’ are not available for package ‘modelr’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/modelr’
    Warning in install.packages :
    installation of package ‘modelr’ had non-zero exit status
    ERROR: dependencies ‘isoband’, ‘tibble’ are not available for package ‘ggplot2’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/ggplot2’
    Warning in install.packages :
    installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/7k/b3qpndxj42v4ms4rgs1nnj200000gn/T/RtmpFOu2HS/downloaded_packages’

For old R versions, like the one you have installed, packages are only available in source form so they require compilation in order to install, for compiling packages on macOS you need to install Xcode in your system (not in R) and the recommended development tools for macOS systems.