24

I am pretty new to Linux. I installed R-base in my Ubuntu 12.04 using the Software Center (which by default is r-2.14). I want to upgrade to/install R 3.02 or newer. How can I do that? Thank you.

27

You need to add R's repository to your system:

  1. Use your favorite text editor (I'm using gedit as an example) to open /etc/apt/sources.list:

    sudo -H gedit /etc/apt/sources.list
    
  2. Add this line to the file (if this is slow, use another mirror. You may also want to change precise into the codename for your Ubuntu version --- e.g., trusty for 14.04):

     deb http://cran.rstudio.com/bin/linux/ubuntu precise/
    
  3. Update the list of packages

    sudo apt-get update
    
  4. Install the latest R-base (you can also use the software center again):

    sudo apt-get install r-base
    
| improve this answer | |
  • Are there any changes in the second command for ubuntu 14.04 users? – Vineet Kaushik Nov 14 '14 at 5:48
  • @VineetKaushik yes, change precise to quantal. – terdon Nov 14 '14 at 9:51
  • @terdon You need a trailing slash after precise in step 2, as precise/. I know it's a bit different than most apt repositories, but that's how the instructions at cran.rstudio.com/bin/linux/ubuntu spell it out. – Daniel Kessler Dec 18 '14 at 16:31
  • @DanielKessler does the slash make any differenece? Trailing slashes are usually optional and can be left out. The version name is just a directory in the repository so it really shouldn't make any difference. – terdon Dec 19 '14 at 7:31
  • 1
    to avoid warnings/errors about gpg keys, use secure apt: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 cran.rstudio.com/bin/linux/ubuntu/#secure-apt – amc Jun 14 '16 at 3:03
3

Having had to spend time figuring this out and forgetting how it works, and then having to figure it out again multiple times, here's a more complete answer that is future-proof.

  1. Edit the sources.list file. This file contains the servers that apt-get consults to check whether software exists and where it can be downloaded from. One can edit the file using the following command:

    sudo -H gedit /etc/apt/sources.list
    

    This requires the gedit editor. If you get an error, either install this (sudo apt-get install gedit) or use another editor like nano (sudo nano /etc/apt/sources.list).

  2. Find a working server to download R from that also has the version of R you are interested in. This often means that one has to look for the name of the latest Ubuntu release. A list of releases is maintained on the Ubuntu website. Look for the latest released version and use only the first word in its name without capitalization. For instance, for the 16.04 release, the full name is Xenial Xerus and the name to use is thus xenial. Thus, we add the following line to the sources.list:

    deb http://cran.rstudio.com/bin/linux/ubuntu xenial/
    

    Note that the above line uses the rstudio.com mirror. One can choose another mirror from this long list and appropriately alter the URL. For instance:

    deb http://mirrors.dotsrc.org/cran/bin/linux/ubuntu xenial/
    
  3. Save and close the file. After this, one can install the newest version using:

    sudo apt-get update # update apt-get's list of known releases 
    sudo apt-get install r-base # install the newest available version of R
    
| improve this answer | |
1

The answers so far are useful but they all omit the next step which is pretty much going to be required of anyone who intends to use R seriously. Quoted lines are from the canonical R Installation and Administration Manual:

Users who need to compile R packages from source [e.g. package maintainers, or anyone installing packages with install.packages()] should also install the r-base-dev package:

sudo apt-get install r-base-dev

I think potential installers should be reading that Manual more carefully than the recommendations on this page have so far advised.

| improve this answer | |
-1

For Ubuntu 14.04 LTS the commands are

sudo -H gedit /etc/apt/sources.list

deb http://cran.rstudio.com/bin/linux/ubuntu quantal/

*Note: the forward slash is required otherwise you get an error

sudo apt-get update 

sudo apt-get install r-base
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.