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.

muru
  • 207,228
jahirju30
  • 241

4 Answers4

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
    
muru
  • 207,228
terdon
  • 104,119
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
    
muru
  • 207,228
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.

-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
muru
  • 207,228
Arthur
  • 129
  • 3