11

So I tried to install R (after repairing ubuntu on my system) using following command :

sudo apt-get install r-base-core
sudo apt-get install r-recommended

It installs R 3.2 , but the latest version of R currently available to use is R 3.4, any idea why it is not installing R 3.4 ?

I lately installed R.3.4 manually, it works fine. just curious to know why it didn't installed at the first place using the command.

minie
  • 111
  • 1
  • 1
  • 5
  • 3
    You need to manually add the repository in `sources.list`. Have a look [here](https://stackoverflow.com/questions/10476713/how-to-upgrade-r-in-ubuntu) – Steven Beaupré Jun 15 '17 at 12:30
  • 1
    Can you not just add Michael Rutter's PPA - https://launchpad.net/~marutter/+archive/ubuntu/rrutter - then `sudo apt-get update && sudo apt-get upgrade`? – Phil Jun 15 '17 at 12:36
  • Thank you both of you for your responses...but @Phil It threw some error while trying PPA one. I manually added the repository information to sources.list and it worked well. – minie Jun 15 '17 at 13:23

3 Answers3

17

Follow these steps:

  1. Add this entry deb https://cloud.r-project.org/bin/linux/ubuntu xenial/ to your /etc/apt/sources.list file.

  2. Run this command in shell: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9.

  3. Update and install: sudo apt update; sudo apt install r-base.

I wrote a post that explains each step in detail (update: also covers installing R on Ubuntu 18.04); here's the link.

NickZeng
  • 1,180
  • 2
  • 12
  • 22
  • 1
    There is a small typo in your answer, it should be `keyserver.ubuntu.com` and not `eyserver.ubuntu.com` – steps May 23 '18 at 17:35
  • 1
    @steps Thanks for the comment! I have fixed the typo. – NickZeng May 28 '18 at 13:42
  • 6
    **Tested**: R 3.5 is out, add this: `deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/` instead, to `sources.list`; [Source](https://cran.r-project.org/bin/linux/ubuntu/) – agent18 Aug 13 '18 at 16:54
  • @ThejKiran I was waiting for this for months! tested and works too! amazing! thx buddy! – Ömer An Aug 24 '18 at 05:58
  • @ÖmerAn just look at the Source I have linked above. You don't have to ever wait at all. All instructions are given there, to get the latest. – agent18 Aug 25 '18 at 08:05
11

It installs 3.2 because that's the default in the Ubuntu 16.04 repository. If you want the most up to date version of R for Ubuntu it's best to follow the instructions at the cran page for R on Ubuntu.

Dason
  • 60,663
  • 9
  • 131
  • 148
  • Did you ever get this working at all? It didn't work at all for me until I edited the following file to be "xenial-cran35" instead of "xenial". `/etc/apt/apt.conf.d/01ubuntu` ```APT { Default-Release "xenial-cran35"; };``` – Scott May 28 '19 at 18:24
  • @Scott 3.5 wasn't released until almost a year after my original answer - so no I didn't need to do that step at the time because 3.4 was the most current version and 3.5 is what brought some breaking changes and required a slightly different approach. But I'm not sure what your point is since the page linked specifies to use xenial-cran35 – Dason May 28 '19 at 19:24
  • I'll add a better description as a separate answer, not because I want to supplant your answer, but because comments don't allow for good formatting or lots of text – Scott May 30 '19 at 18:02
0

The xenial-cran35/ version of the repo does NOT work if you have a "default release" set in apt, as is the case in some distros that work on top of Ubuntu, such as Mint. For my Mint distro, there exists a file /etc/apt/apt.conf.d/01ubuntu inside of which it declares the Default-Release "xenial"; What this means is that, since r-base exists in the ubuntu repo at version 3.2, with release "xenial", it'll never use the 3.6 branch from the other repo, because the release name for that repo is "xenial-cran35". You need to edit that file to change the default release to "xenail-cran35", or do something more pointed using apt preference files (https://wiki.debian.org/AptPreferences#A.2Fetc.2Fapt.2Fpreferences).

This is basically R's fault for having a poorly formatted repo. They should have had 2 repos, each of which had a "xenial" release folder, one url for their 3.2 branch work and one for the 3.5+ branch work. Instead they have one repo, and have bastardized the "release name" instead, which just sort of happens to work for base Ubuntu, but won't work if you have non-base configuration of apt in this way.

Scott
  • 954
  • 1
  • 8
  • 15