How do I install/upgrade r-base to the latest version?

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
    

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