To say about one of the most popular and extensible languages, in this article we are going to learn you how to install R on Ubuntu 20.04. It is An open-source programming language and is widely used for performing data analysis and statistical computing. With an active community and supported by the R Foundation for statistical computing, R offers many user-generated packages for specific areas of study, which makes it applicable to many fields. In the following, you may learn how to install R and how to add packages from the official Comprehensive R Archive Network (CRAN).
The tutorial may be more useful if you know:
- about 1GB of RAM (at least)
- a non-root user with sudo privileges
- To set up, follow our Initial server setup on Ubuntu 20.04
How to install R on Ubuntu 20.04
1- Installing R
First, add the GPG key.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
After running, you should face the below output.
Executing: /tmp/apt-key-gpghome.cul0ddtmN1/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 gpg: key 51716619E084DAB9: public key "Michael Rutter <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1
After receiving the trusted key, you can add the repository. In case you are not using 20.04, find the relevant repository from the R Project Ubuntu list.
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
Identify lines as below, when output displays.
... Get:7 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ InRelease [3622 B] Get:8 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages [15.6 kB] ...
To include package manifests from the new repository, run update after this.
sudo apt update
One of the output lines should appear as below.
... Hit:5 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ InRelease ...
In order to see the update command in the output, the repository addition is successful.
Now install R with the following command.
sudo apt install r-base
To confirm the installation, press y to continue.
It is better to install an example package for every user on the system. So start R as root so that the libraries will be available to all users automatically. If you need to set a personal library for your user, run the R command without sudo
sudo -i R
R version 4.0.0 (2020-04-24) -- "Arbor Day" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) ... Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
2- Installing R packages from CRAN
As one of the R’s features is an abundance of add-on packages, you can install txtplot, a library that outputs ASCII graphs that include scatterplot, line plot, density plot, act, and bar charts to reach demonstration purposes.
... Installing package into ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified) ...
Load txtplot, after installation.
If there are no error messages, the installation is successful.
Dear user, we wish this tutorial would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.