Niranjan
Niranjan

Reputation: 171

Install latest version of R with all the packages on Ubuntu 16.04

I am using Ubuntu 16.04. I want to install R (version 3.5) on it. As the system version is older, it can't find this version from terminal line. I checked it with this command on the terminal line.

sudo apt-get install r-base=3.5

Which resulted in -

Version '3.5' for 'r-base' was not found

I want to install this version with all it's packages. What is the correct process? Can I get all the package files and installation files to install all of it in one go from my terminal? Please suggest me an appropriate way of achieving this.

Upvotes: 0

Views: 867

Answers (2)

JBGruber
JBGruber

Reputation: 12450

You have to install the newest version of R from a different PPA:

1. Add the PPA:

Currently, there are two different ones. For R 3.5 and above:

sudo add-apt-repository "deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -cs)-cran35/"

And one for R 3.4 (obviously the newer version is recommended):

sudo add-apt-repository "deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -cs)/"

2. Next, you need to add R to your keyring.

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

3. Update apt and install R (or r-base-dev if you wish to compile packages from source):

sudo apt-get update && sudo apt-get install r-base

4. (optional) install RStudio via gdebi:

sudo apt-get install gdebi-core
wget https://download1.rstudio.org/desktop/xenial/amd64/rstudio-1.2.5019-amd64.deb
sudo gdebi -n rstudio-1.2.5019-amd64.deb
rm rstudio-1.2.5019-amd64.deb

Steps are from this PDF.

Upvotes: 1

dc37
dc37

Reputation: 16178

Alternatively to the PPA, you can add the official Ubuntu archive of The Comprehensive R Archive Network CRAN to your sources.list by doing:

sudo echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" >> /etc/apt/sources.list

NB: The use of cloud.r allow the user to be automatically redirected to a nearby CRAN mirror.

Then, you will have to secure APT by providing the key for Ubuntu archives on CRAN by doing:

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

Then update the list of repository, make upgrades if any and install r-base

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install r-base r-base-dev

This will install r-base and r-base-dev, that will provided as their names indicated it, the base for R. If you want additionnal packages, start R (in terminal, by typing R) and then install packages of interest by doing:

install.packages("ggplot2") # an example of package

Upvotes: 0

Related Questions