The main guide on how to install R for any flavour of linux, binary or from source, is at http://cran.stat.ucla.edu/
Three different pathways to a working install, from simple to hard:
- use the distributions package manager (easiest but not the most recent version)
- install binary (recommended)
- compile and install from source
I am assuming you are on Ubuntu 16.04 LTS.
A very easy way to get R is to just
sudo apt-get install r-base r-base-dev
However, this will install the fairly old version R 3.2.3.
If you want a newer version, I recommend R 3.4, not the most recent R 3.5, in this context. Here, the easiest way is to include a mirror by adding the line
deb https://cloud.r-project.org/bin/linux/ubuntu xenial/
to your /etc/apt/sources.list
file (requires sudo privileges).
Also you need to add a key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update
sudo apt-get -y install r-base r-base-dev
You most probably want to also install Rstudio or even Rstudio server.
Download and follow the instructions at: https://www.rstudio.com/products/rstudio/download/
For Ubuntu 16.04 LTS, this would be:
wget https://download1.rstudio.org/rstudio-xenial-1.1.456-amd64.deb
sudo apt -y install libjpeg62
sudo dpkg -i rstudio-xenial-1.1.456-amd64.deb