In this tutorial you will learn how to install R on Ubuntu 20.04 Focal Fossa Server/Desktop.
In this tutorial you will learn:
- How to install R
- How to install latest R version
- How to add official R-Project repository
- How to install R library
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
Software | R |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How To Install R on Ubuntu 20.04 step by step instructions
- Update the package index:
$ sudo apt update
Ubuntu repository contains stable version R packages. However, optionally if you wish to install the latest GNU R version add the official R-Project repository:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 $ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu eoan-cran35/'
- Install R:
$ sudo apt install r-base
- confirm the R installation by checking its version:
$ R --version
- Start using R:
$ R
- (optional) Install RStudio, the integrated development environment for R.
DID YOU KNOW?
Ubuntu repository contains approximately 860 ready to install and use stable library R packages. This means that in most cases you do not need to install and compile R library from source using R shell. In fact this is not recommended at all! All you need is to install an appropriater-cran
package by using theapt
command. See bellow.To install additional libraries using
apt
command, first search the package index for available packages. For example let’s see if the R libraryggplot2
is available:$ apt-cache search r-cran | grep ggplot2 r-cran-cowplot - GNU R streamlined plot theme and plot annotations for 'ggplot2' r-cran-egg - GNU R extensions for 'ggplot2': custom geom, custom themes, plot r-cran-ggally - GNU R extension to r-cran-ggplot2 r-cran-ggdendro - GNU R create dendrograms and tree diagrams using 'ggplot2' r-cran-ggforce - accelerating GNU R ggplot2 r-cran-ggplot2 - implementation of the Grammar of Graphics r-cran-ggridges - Ridgeline Plots in 'ggplot2' r-cran-ggthemes - extra themes, scales and geoms for r-cran-ggplot2
To install the actual R library package enter:
$ sudo apt install r-cran-ggplot2
Test the library installation by loading it from R shell:
$ R > library(ggplot2)