In this article, we will have explained the necessary steps to install and configure R on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
R is a open source programming language and free software environment for statistical computing with graphical interface. It is supported by the R Foundation for Statistical Computing and mainly used by statisticians and data miners for developing statistical software and performing data analysis.
Install R on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install R on Ubuntu.
First steps, it is recommended to begin the process using Comprehensive R Archive Network, CRAN to add the external repository:
sudo apt install dirmngr apt-transport-https ca-certificates software-properties-common gnupg2
Next, 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/'
Then, update the packages list and install the R package by typing:
sudo apt update sudo apt install r-base
You can verify the installation by running the following command which will print the R version:
Step 3. 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
Start by opening the R console as root:
sudo -i R
To install stringr package just type:
The installation will take some time and once completed, complete, load the library with:
Let’s create a simple vector named demo:
sample <- c("How", "to", "Install", "R", "on", "Ubuntu", "18.04 LTS")
Then, run the below command to print the length of a string:
 3 2 7 1 2 6 1
That’s all you need to do to install R on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.