How To Install and Configure “R” on Ubuntu 16.04

In this article, we will learn how to install and configure R on Ubuntu 16.01. “R” is an open-source programming language which can be specially used for statistical computing and performing analytical data. Where “R” has the community well know for the packages generated by the users in a specific area of study. We will install the “R” package using the CRAN (Comprehensive “R” Archive Network).


  • We need a Linux machine install with Ubuntu 16.04 server with a minimum of 1 GB of RAM.

  • A non-root user with Sudo permissions on the machine.

Adding the CRAN repository to the Machine and Install R Package

Since “R” is the fastest-moving package, we will not get the stable version from the Ubuntu repositories, so we needed to add the CRAN repository to our local machine.

$ sudo apt-key adv --keyserver --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
Executing: /tmp/tmp.YZv0REiwBU/ --
gpg: requesting key E084DAB9 from hkp server
gpg: key E084DAB9: public key "Michael Rutter <>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Once the trusted key is to install on the server database, we can add the repository to the machine with the below command.

$ sudo add-apt-repository 'deb [arch=amd64,i386] xenial/'

Once the repository is added, we will now update the machine with the below command

$ sudo apt-get update
Hit:1 xenial InRelease
Hit:2 jessie InRelease
Hit:3 xenial-updates InRelease
Hit:4 xenial-backports InRelease
Hit:5 xenial InRelease
Hit:6 xenial-security InRelease
Hit:7 xenial/ InRelease
Reading package lists... Done
W: Signature by key E79ACECB87D8DCD23A20AD2FFB40D3E6508EA4C8 uses weak digest algorithm (SHA1)Once the update is done and update the local machine we will now install the r-base package from the CRAN repository.

Below is the command to install the R package.

$ sudo apt-get install r-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-21 linux-headers-4.4.0-21-generic linux-image-4.4.0-21-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
bzip2-doc cdbs cpp-5 dh-translations fontconfig fontconfig-config fonts-dejavu-core g++-5 gcc-5
gcc-5-base gfortran gfortran-5 icu-devtools intltool libasan2 libatomic1 libauthen-sasl-perl
libblas-common libblas-dev libblas3 libbz2-dev libcairo2 libcc1-0 libcilkrts5 libcurl3 libdatrie1
libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libelf1 libencode-locale-perl
libfile-basedir-perl libfile-desktopentry-perl libfile-listing-perl libfile-mimeinfo-perl
libfont-afm-perl libfontconfig1 libfontenc1 libgcc-5-dev libgfortran-5-dev libgfortran3 libgl1-mesa-dri
libgl1-mesa-glx libglapi-mesa libgomp1 libgraphite2-3 libharfbuzz0b libhtml-form-perl
libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl
libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl libice6 libicu-dev
libio-html-perl libio-socket-ssl-perl libipc-system-simple-perl libitm1 libjbig0 libjpeg-dev
libjpeg-turbo8 libjpeg-turbo8-dev libjpeg8 libjpeg8-dev liblapack-dev liblapack3 libllvm3.8 liblsan0
liblwp-mediatypes-perl liblwp-protocol-https-perl liblzma-dev libmailtools-perl libmpx0 libnet-dbus-perl
libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libpango-1.0-0 libpangocairo-1.0-0
Creating config file /etc/R/Renviron with new version
Setting up r-cran-boot (1.3-18-1cran1xenial0) ...
Setting up r-cran-cluster (2.0.5-1xenial0) ...
Setting up r-cran-foreign (0.8.67-1xenial0) ...
Setting up r-cran-mass (7.3-45-1xenial0) ...
Setting up r-cran-kernsmooth (2.23-15-2xenial0) ...
Setting up r-cran-lattice (0.20-34-1xenial0) ...
Setting up r-cran-nlme (3.1.128-2xenial0) ...
Setting up r-cran-matrix (1.2-7.1-1xenial0) ...
Setting up r-cran-mgcv (1.8-15-1cran1xenial0) ...
Setting up r-cran-survival (2.39-4-2xenial0) ...
Setting up r-cran-rpart (4.1-10-1) ...
Setting up r-cran-class (7.3-14-1xenial0) ...
Setting up r-cran-nnet (7.3-12-1xenial0) ...
Setting up r-cran-spatial (7.3-11-1xenial0) ...
Setting up r-cran-codetools (0.2-15-1cran1xenial0) ...
Setting up r-recommended (3.3.2-1xenial0) ...
Setting up r-base (3.3.2-1xenial0) ...
Setting up liblzma-dev:amd64 (5.1.1alpha+20120614-2ubuntu2) ...
Setting up r-doc-html (3.3.2-1xenial0) ...
Setting up x11-utils (7.7+3) ...
Setting up x11-xserver-utils (7.7+7) ...
Setting up libauthen-sasl-perl (2.1600-1) ...
Setting up r-base-html (3.3.2-1xenial0) ...
Setting up liblwp-protocol-https-perl (6.06-2) ...
Setting up libwww-perl (6.15-1) ...
Setting up libxml-parser-perl (2.44-1build1) ...
Setting up intltool (0.51.0-2) ...
Setting up dh-translations (129) ...
Setting up cdbs (0.4.130ubuntu2) ...
Setting up libxml-twig-perl (1:3.48-1) ...
Setting up libnet-dbus-perl (1.1.0-3build1) ...
Setting up r-base-dev (3.3.2-1xenial0) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...

Once the package is installed, we can verify the packages using the below command

$ sudo -i R
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
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.

Install the additional R Packages from CRAN Repository

As R has a lot of packages or add-on, where here in the demo we will install the txtplot which is an ASCII graph package which also includes the scatterplot, below is the command to be run from the R console.

> install.packages('txtplot')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
1: 0-Cloud [https]                           2: Algeria [https]
3: Australia (Melbourne) [https]             4: Australia (Perth) [https]
5: Austria [https]                           6: Belgium (Ghent) [https]
7: Brazil (RJ) [https]                       8: Brazil (SP 1) [https]
9: Bulgaria [https]                         10: Canada (MB) [https]
11: Chile [https]                           12: China (Beijing) [https]
13: China (Hefei) [https]                   14: China (Lanzhou) [https]
15: Colombia (Cali) [https]                 16: Czech Republic [https]
17: Denmark [https]                         18: France (Lyon 1) [https]
19: France (Lyon 2) [https]                 20: France (Marseille) [https]
21: France (Montpellier) [https]            22: France (Paris 2) [https]
23: Germany (Falkenstein) [https]           24: Germany (Münster) [https]
25: Iceland [https]                         26: India [https]
27: Ireland [https]                         28: Italy (Padua) [https]
29: Japan (Tokyo) [https]                   30: Malaysia [https]
31: Mexico (Mexico City) [https]            32: New Zealand [https]
33: Norway [https]                          34: Philippines [https]
35: Russia (Moscow) [https]                 36: Serbia [https]
37: Spain (A Coruña) [https]                38: Spain (Madrid) [https]
39: Switzerland [https]                     40: Taiwan (Chungli) [https]
41: Turkey (Denizli) [https]                42: UK (Bristol) [https]
43: UK (Cambridge) [https]                  44: UK (London 1) [https]
45: USA (CA 1) [https]                      46: USA (IA) [https]
47: USA (IN) [https]                        48: USA (KS) [https]
49: USA (MI 1) [https]                      50: USA (TN) [https]
51: USA (TX) [https]                        52: USA (WA) [https]
53: (HTTP mirrors)
trying URL ''
Content type 'application/x-gzip' length 6152 bytes
downloaded 6152 bytes
* installing *source* package ‘txtplot’ ...
** package ‘txtplot’ successfully unpacked and MD5 sums checked
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (txtplot)
The downloaded source packages are in

Once the add-on is installed, we can load the library and test the library with some sample packages.

> library('txtplot')

Once the package is loaded we will test the sample, where the sample datasets package contains the speed of cars and the distance for the stopper base on the data from 1920’s.

>txtplot(cars[,1], cars[,2], xlab = "speed", ylab = "distance")
120                                                  + * +
|                                                        |
d 100                                   +              * +
i | * *                                                  |
s 80                                + * *                +
t | * * * *                                              |
a 60 + * * * * * +
n | * * * * *                                            |
c 40 + * * * * * * * +
e | * * * * * * *                                        |
20 + * * * * * +
| * * *                                                  |
0 +----+-----------+------------+-----------+---------+--+
5 10 15 20 25

In the above article we have installed R uses the CRAN repository which is an open-source from RStudio Server as we have completed the server side installation and test some sample date with graphs.

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 20-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started