How to install R on Ubuntu 16.04 Xenial?

Is there a convenient shell script that allows you to install everything at once?


  1. We need to add R repository, then install packages from it:

    • 3.4.4

      cat <<EOF | sudo tee /etc/apt/sources.list.d/r-cran.list
      deb https://cloud.r-project.org/bin/linux/ubuntu xenial/
      EOF
      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
      
      sudo apt-get update
      sudo apt-get install r-base r-base-dev
      
    • 4.0

      cat <<EOF | sudo tee /etc/apt/sources.list.d/r-cran.list
      deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/
      EOF
      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
      
      sudo apt-get update
      sudo apt-get install r-base r-base-dev
      
  2. Download RStudio from official site, for example, version 1.2.5042, and install it with gdebi:

    wget https://download1.rstudio.org/desktop/xenial/amd64/rstudio-1.2.5042-amd64.deb
    sudo apt-get install ./rstudio-1.2.5042-amd64.deb