R is a popular open source programming language, often use for graphical and statistical computing. R was created by Ross Ihaka and Robert Gentleman. This post will talk about quick installation of R on Ubuntu 18.04 LTS Bionic Beaver. We will also talk about installing and using packages from CRAN ( Comprehensive R Archive Network )
For installation of R on Ubuntu 18.04 server, we should have
- atleast 1GB RAM size
- a non root user with sudo privileges
Step-1: Add GPG Key
Login to your Ubuntu 18.04 Server with non root user and add GPG Keys with following command. GPG Keys maintain package consistency and authenticity by requiring that distributors sign packages with GPG key.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
After running this command, we’ll see following output on terminal
Executing: /tmp/apt-key-gpghome.BdmLHeW5nd/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
Step-2: Add R official repository source
After adding GPG Key we will add R official repository source.
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
Above repository source is for Ubuntu 18.04, If you are not using Ubuntu 18.04 Bionic Beaver LTS. You can check other repository from the R project Ubuntu packages List
After running above command, Ubuntu will fetch list of all repository and it will also show latest one added, like this
Get:35 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease [3,609 B] Get:36 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages [22.3 kB]
Step-3: Update Ubuntu packages
Now we’ll run update command for loading files from new repository.
sudo apt-get update
Among the output lines, you should see following line.
Hit:1 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease
Step-4: Install R
As repository source file is in place, now we can install R using command
sudo apt install r-base
After running this command terminal will prompt for yes or no as a final input, you have to type in “yes” and installation will be started. It takes some time to install successfully, In my case total download size was 128 MB.
For verifying R installation you can run simply type R and hit Enter on terminal.
On running “R” command, you should see following output on terminal
R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 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.
For exiting from R, you can run q(). It will ask for saving workspace image, do as required to quit.
Step – 5: Installing R packages from CRAN
The popularity of R language can be somewhat attributed to its large store of packages and its simplicity for its installation. For installing a CRAN package in R we use install.pacakges() function. This command fetches package from specified repository and install on your computer.
For example, we’ll be installing ggplot2 package by using following command.
After running this command, R started to download package data from https://cloud.r-project.org and compile it. you will see number of lines on terminal, at the time of compilation.
For loading a R package, you can use following command.
Verfying installed packages in R
you can check whether a particular package is installed or not by using packageVersion function.
You should see output like this,depending upon version of package. It is output of above command.
If you are looking for ggplot2 examples you can check this website.
Thankyou for following this tutorial, R is now successfully installed on your machine. In case if you are getting any error write to us at nixgyd[at]gmail.com
You can also ask question about any issue by using comment section below. Thanks for reading.