• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install R on Ubuntu 18.04

Written by Admin
r, ubuntu
How to Install R on Ubuntu 18.04

R is a open source programming language and free software environment for statistical computing with graphical interface.R languages widely used for statistical computing and data mining for developing statistical software and performing data analysis. In this tutorial described how to install R on Ubuntu 18.04 system.

Prerequisites#

Make sure you are logged in with non-root user account with sudo privileges.

Installing R on Ubuntu#

R is a fast-moving project, the latest stable version isn’t always available from Ubuntu’s repositories, so we’ll need to add the external repository maintained by CRAN.

At first, you should install required dependencies to add new repository. Run below command to install dependencies:

sudo apt install dirmngr apt-transport-https ca-certificates software-properties-common gnupg2

Now need to enable CRAN repository and add the CRAN GPG key to your system by issue below command:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'

Once the repository added you should update package list by typing:

sudo apt update

Next issue below command to install R on Ubuntu:

sudo apt install r-base

You can verify the installation by running the following command which will print the R version:

R --version
Output
R version 3.6.0 (2019-04-26) -- "Planting of a Tree" Copyright (C) 2019 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 the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/.

Install R Packages from CRAN#

R is so popular because of wide availability of packages through the Comprehensive R Archive Network (CRAN). You should install build-essential package which contains the tools required for compiling R Packages.

sudo apt install build-essential

We are going to install a stringr package for an example, which provides fast, correct implementations of common string manipulations.

Start by opening the R console as root:

sudo -i R

It will show as below:

R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 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.

>

To install stringr package just type:

install.packages("stringr")

Installation will take some time and after completion load library using:

library(stringr)

Let’s create a simple vector named demo:

demo <- c("How", "to", "Install", "R", "on", "Ubuntu", "18.04")

Now run the below command to print the length of a string:

str_length(demo)
[1] 3 2 7 1 2 6 1

If you want to install more packages you can find it at CRAN Packages.

Conclusion#

You have successfully learned how to install R on Ubuntu 18.04 system. If you have any problem or suggestion please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Set Up Nginx Server Blocks on Debian 10
Next Article   Secure Nginx with Let’s Encrypt on Debian 10

Related Posts

  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook