How to Install R on Ubuntu 18.04

  • 2019-04-02 01:29 AM
  • 111

Install R on Ubuntu 18.04

Install R on Ubuntu 18.04

R is a opensource programming language and software environment which comes with GUI (Graphical User Interface). R language specialized in statistical computing and graphics so it is widely used in statistical software development and data analysis. In this tutorial we are going to learn How to install R on Ubuntu 18.04.

Prerequisites

Before you start to install R on Ubuntu. You must have a non-root user account on your server with sudo privileges.

Installing R on Ubuntu

R language repository is not available in Ubuntu core repositories so we need to add the repository manually. Follow below instructions to add repository and install R on Ubuntu.

First add GPG key by using the following command in terminal:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

Now after adding GPG key you should add the repository by running the below command:

sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'

Update the apt package manager index by typing the following command in terminal:

sudo apt update

Run the following command to install R in Ubuntu:

sudo apt-get install r-base

Confirm the installation and check the version of R language by typing the following command:

R --version

The output should be:

R version 3.5.3 (2019-04-01) -- "Feather Spray"
Copyright (C) 2018 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.

Run Simple Hello World Program In R

Now we are going to run a simple R program in Ubuntu using following instructions.

Create a file named HelloWorld.R using the following command:

sudo nano HelloWorld.R

Copy and paste the following code in above file:

helloVariable <- "Hello World"
print(helloVariable)

Now run program by typing the following command in the terminal:

Rscript HelloWorld.R

The output should be:

[1] Hello World

You have successfully run Hello World program in R language.

Conclusion

You have successfully learned how to install R on Ubuntu 18.04. If you have any queries please don’t forget to comment out.

Learn More

The Data Science Course 2019: Complete Data Science Bootcamp
Machine Learning A-Z™: Hands-On Python & R In Data Science
Tableau 10 A-Z: Hands-On Tableau Training For Data Science!
R Programming A-Z™: R For Data Science With Real Exercises!
Machine Learning, Data Science and Deep Learning with Python
Intro to Data Science - Crash Course for Beginners
How to get started with Python for Deep Learning and Data Science
Hadoop Administration Tutorial for Beginners
R vs Python: What’s The Difference?

Originally published at https://linux4one.com

Suggest