How to Install R on Linux Ubuntu 16.04 Xenial Xerus

The long-awaited new Ubuntu LTS Xenial Xerus was released last week. I wrote a tutorial on installing R and R-Studio on the old 14.04 LTS, so I figured I’d update that document. Not much has changed for the new 16.04 version but there are new repositories.

Install R-Base

You can find R-Base in the Software Center; this would be the easy way to do it. However, the Software Center versions are often out of date, which can be a pain moving foward when your packages are based on the most current version of R Base. The easy fix is to download and install R Base directly from the Cran servers.

1. Add R repository

First, we’ve got to add a line to our /etc/apt/sources.list file. This can be accomplished with the following. Note the “xenial” in the line, indicating Ubuntu 16.04. If you have a different version, just change that.

sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list

2. Add R to Ubuntu Keyring

First:

 gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9

Then:

 gpg -a --export E084DAB9 | sudo apt-key add -

3. Install R-Base

Most Linux users should be familiar with the old…

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

Installing R-Studio

RStudio is not currently in the Software Center, but it can easily be installed manually:

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

rstudio16

45 thoughts on “How to Install R on Linux Ubuntu 16.04 Xenial Xerus

  1. Thank you for your so up-to-date and detailed information!

    Just to help if anyone have the same problem, I got an error of ‘keyserver unreachable’ from keyserver.ubuntu.com, which I had solved by specifying the protocol and port number as follows:
    gpg –keyserver hkp://keyserver.ubuntu.com:80 –recv-key E084DAB9

    1. Still having problem..It shows
      “gpg: fatal: can’t create directory `/HOME/akshay/jdk1.8.0_101/bin//.gnupg’: No such file or directory
      secmem usage: 0/0 bytes in 0/0 blocks of pool 0/65536”

  2. Thanx for the article.

    Cant get RStudio started though 🙁

    I am getting “load glyph failed”, any ideas? I cant find anything useful on the web. Tried latest version of Rstudio as well and the same issue.

    Thanx

    1. I tried to replicate the problem with a fresh install of 16.04 but can’t. You’re not running VNC by chance are you? I’ve seen this same issue with machines running VNC servers. The (for now) fix seems to be to uninstall the current version of RStudio and then grab the older one.

      `wget https://download1.rstudio.org/rstudio-0.98.1103-amd64.deb`
      `sudo gdebi -n rstudio-0.98.1103-amd64.deb`

      https://support.rstudio.com/hc/en-us/community/posts/204543108-Rstudio-Crashing-on-Ubuntu-14-04-2-LTS

  3. Thank you very much for the article.
    I am pretty new In Linux and I don’t know if it works for all flavors of Ubuntu, for example, Ubuntu Mate.

    1. Glad to help. Yes, it should work on MATE. I tested this on Ubuntu Server, which is the most stripped down version out there. Most of the “flavors” are just different desktop environments.

  4. Thanks for post.
    I can load rstudio, but in the terminal I get this error message:
    load glyph failed err=6 face=0x207d280, glyph=2797
    load glyph failed err=6 face=0x207d280, glyph=2797

    When I close rstudio I get this one:
    QApplication::qAppName: Please instantiate the QApplication object first

    Do you know what could it be?
    Thanks for the help.
    Best Regards,
    José

    1. Try re-installing gdebi. If you’re using command line it’s sudo apt-get install gdebi-core or if you prefer a GUI you can just sudo apt-get install gdebi

  5. Please I am struggling trying to install Rstudio. I have follow the instruction but after typing:
    sudo gdebi -n rstudio-0.99.903-amd64.deb I got the error:
    This package can not be installed
    Wrong architecture ‘amd64’

    does anyone know how to solve this?

    1. The `wget` command is just downloading the rstudio.deb file. Usually a “segmentation fault” error would occur during installation–probably at the `sudo gdebi` line below. Either way, I assume your using Ubuntu desktop, you could always try installing Rstudio via the Software Centre.

      1. Thank you for your answer. Usually it’s easier for me to use the terminal, but I’ve installed it from the Software Centre as you advised. I get this message when I try to open it:
        The R session failed to start.

        /usr/lib/rstudio/bin/rsession: symbol lookup error: /usr/lib/rstudio/bin/rsession: undefined symbol: Rf_PrintWarnings

        Any idea? As you can imagine, I’m not an expert in Linux, nor in R, sorry if it’s something obvious.

        1. Nevermind, I removed both R and R Studio and reinstalled them and now it looks like it’s finally working 🙂

  6. Trying to install on 16.10 doing s/xenial/yakkety/g where needed, and there’s an issue with installing R Studio. I get

    This package is uninstallable
    Dependency is not satisfiable: libgstreamer0.10-0

    from the gdebi command to install it. Looking around shows a libgstreamer1.0-0 in the yakkety repository, but no libgstreamer0.10-0.

  7. Are these instructions still current? I just tried to follow these instructions (16.04), but at sudo apt-get update, I get the following error message:

    E: Malformed line 57 in source list /etc/apt/sources.list (type)
    E: The list of sources could not be read.

    1. Yes, something happened when you tried to add the CRAN repo to your sources.list. I would try to edit the sources.list by hand and make sure you’re good to go. It’s located in /etc/apt. The line should be “deb http://cran.rstudio.com/bin/linux/ubuntu xenial/” exactly–don’t forget the backslash:)

  8. Just to follow up. Problem Solved. When copying and pasting the first command, for some reason some strange symbols were also copied into the source list. I suspect that the spaces around the | (pipe?) are causing the issue. So I wrote out the first command, instead of copying and pasting. Subsequently, I could copy and paste all the other commands without a problem.

    However, a second problem appeared, which is that r-dev was not available for installation… This does not bother me so much, and I had no problem installing R studio. Everything works. Just need to update R studio now…

    Thanks for posting these instructions!

  9. I would warn that if you are not careful and your version is NOT Xenial, you’ll get mysterious errors that complain you need more libraries. Don’t copy/paste the code. But it does work, otherwise. Thanks!

  10. I’m completely new to Ubuntu so I wasn’t quite sure how to follow these instructions. Eventually I just typed in exactly what was written here. Everything seems to have worked out fine. If you’re concerned that my mindlessness may have caused issues, you can read exactly what I did here http://toorightweare.blogspot.co.nz/2017/04/the-zombies-guide-to-installing-r-on.html

    But basically, thanks, I found getting R onto this computer post Ubuntu more difficult than getting Ubuntu on to it.

Leave a Reply