Installing R/RStudio on Ubuntu 14.04
My last experience with Linux was back in 2002/2003. At that time pretty much everything on Linux was done in the console. I remmember struggling for days with a simple Wifi connection because drivers were not readily available. Things have changed dramatically since then. Last week I installed Linux (Ubuntu 14.04) on an old Windows laptop. It took me about 20 mins to erase completely Windows, install Linux and start playing with R/Rstudio: simply amazing…. In this post I explain step by step what I did: bear in mind that I’m a Linux absolute beginner.
1 – Install Linux
- Go to Ubuntu website and download the version that matches your system
- Create a bootable USB key with the file downloaded above. I used a small utility called Rufus for this. Just follow the instructions on the website it’s very simple.
2 – Install R
Ubuntu 14.04 ships with R but it’s not the latest version. The latest version can be obtained from CRAN. An entry like : http://<my.favorite.cran.mirror>/bin/linux/ubuntu trusty/ has to be added to the /etc/apt/sources.list file, replacing <my.favorite.cran.mirror> by the actual URL of your favorite CRAN mirror (see http://cran.r-project.org/mirrors.html for the list of CRAN mirrors). Actually this is a bit tricky because you need admin rights to modify the sources.list file. I used a small utility called gksudo to open and modify the sources.list file. In the command line type the following:
gksudo gedit /etc/apt/sources.list
This will open the sources.list file in gedit. You just need to add the repository above then save and close
You can then install the complete R system, by typing the following in the console:
sudo apt-get update sudo apt-get install r-base
There are other ways of doing this but adding an entry to the sources.list file is apparently the prefered option. Ubuntu uses apt for package management. Apt stores a list of repositories (software channels) in the sources.list file. By editing this file from the command line, software repositories can be added or removed.
3 – Install RStudio
- Go to RStudio website, choose and download the right package for your system
- Open this file in Ubuntu Software Center
- Click install and you’re done
if you want to have RStudio icon on the launcher (all the icons on the left hand side of the screen)
- Go to Search and type RStudio, the RStudio icon should appear
- Drag and Drop RStudio icon to the launcher
All this might not be perfect but it worked for me without a glitch. I wanted to share my experience because I’m trully amazed by the improvements brought to Linux over the last few years.
As usual any comments welcome.
You can set this up as terminal commands and avoid having to physically type and browse the web for files. You should update the repository to your local one (info here: http://cran.r-project.org/mirrors.html) within these commands:
# Get the latest R version
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9
sudo add-apt-repository ‘deb http://star-www.st-andrews.ac.uk/cran/bin/linux/ubuntu trusty/’
sudo apt-get update
sudo apt-get install r-base
# Download and install RStudio
wget http://download1.rstudio.org/rstudio-0.98.1062-amd64.deb
sudo dpkg -i *.deb
rm *.deb
The main advantage with this approach is that you can make an install script for your setup, which makes maintaining multiple machines much easier and upgrades/rebuilds nearly painless. You can see mine here: http://scottishsnow.wordpress.com/software/ which will set you up with pretty much all the spatial science software you could need.
Thank you for the tip this is very useful. As mentionned I’m an absolute beginner with Linux
Very useful…
Thanks a lot!
#if you have some dependencies issue, you could try this too:
sudo gdebi *.deb
Before running “sudo dpkg -i *.deb”,
you may also need to install the libjpeg62 package (via “sudo apt-get install libjpeg62”).
Thank you, I was writing my setup script when I saw this. 🙂
Thank you very much
Best wishes
Thank you for the tip.
I found that gpg key option error occurred when add the server key in my Ubuntu 14.04 lts environment
Lastest rstudio binary download link is:
sudo wget http://download1.rstudio.org/rstudio-0.99.489-amd64.deb
Thank you
Software center wasn’t working for me to install RStudio (don’t know why), but this method through command line went fine. Thank you!
Very informatic. Thank you..
I wrote a bash script to do this (14.04). Stevie Jordan had a good point about using gdebi. I found that helped a lot in version 12.04
https://github.com/mGalarnyk/Installations_Mac_Ubuntu_Windows/blob/master/RStudio/RStudioUbuntu1404.bash
Made a video as well.
https://www.youtube.com/watch?v=GsuA5ugYqyw
May I suggest using the RRutter launchpad PPA for easier installiation of R for Ubununtu? You can use “apt-add-repository” to install the PPA. Details here: https://launchpad.net/~marutter/+archive/ubuntu/rrutter. This PPA seeds the CRAN Ubuntu sites, so the packages are identical.
Also check out c2d4u for Ubuntu packages for over 1000 R packages. https://launchpad.net/~marutter/+archive/ubuntu/c2d4u
sudo apt-get install r-base r-base-dev
might be useful to install more libraries.
[…] ………. […]
When I installed R, I had to add a “key” with the command:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9
I have tried in my desk top. The file opens with Software center and strats installation. But fails. Do not know the reason why? Could you help?
Thanks for reaching out but I need a bit more details to try to help you.
Thank you
You can also pull the latest r and rstudio from launchpad:
sudo add-apt-repository ppa:opencpu/rstudio
sudo apt-get update
sudo apt-get install rstudio-server
This worked on Ubuntu 14.04
how to open the downloaded file in the software center? I can not find the file in the software center.
An icon just apears and I click on it. I didn’t come accross any issue.
This was incredibly helpful, folks. Thanks a million!
May be of interest, my quickstart guide to setting up a new Linux install, it’s mainly for my own use but I’ve blogged it in case others find it useful.
(I much prefer the Linux Mint desktop to the vanilla Ubuntu version but it’s a matter of taste, of course).
http://chrisbeeley.net/?p=593
Thank you for the tip
Thanks. Worked perfectly .
I followed this and have a problem when loading rstudio:
R shared library (/usr/local/lib/R/lib/libR.so) not found. If this is a custom build of R, was it built with the –enable-R-shlib option?
I had a older version of R on this machine (the default) and Rstudio worked with it perfectly. The I tried to upgrade to R-3.2 using installing from source and this happened! anyone know why?
Try creating a soft link from your shared libR.so file to /usr/local/lib/R/libR.so (I think that’s the directory RStudio looks in). I struggled with this for a while.
Works great!!
When editing the source.list, don’t forget to include the command ‘deb’ at the beginning, e.g.,
deb https:///bin/linux/ubuntu trusty/
Thank you very much. Too usefull for me
Hi there thertrader
I’m not great at maths,command line editing is a bit steep learning curve. Following your instructions installing RStudio was a breeze. Thanks you,it works wonder !
Hi all,
I have followed the same process to install R, RStudio with Ubuntu 15.10 (already add Willy to repository). R installed successfully but RStudio could not start. I tried many times but RStudio did not open when I clicked on the RStudio icon after search. Any comments? Thanks
Hi all,
I tried with Ubuntu 15.10. R is installed and worked smoothly but RStudio cannot open.
Advise?
Thanks
Hi,
I’m using mainly Windows and my Linux post was just an attempt to test another working environment. Given the financial world huge dependency on Excel, I don’t think I’ll move to Linux any time soon. I think it’s under optimal but that’s they way it is. To cut a long story short, I’m far from being a Linux expert and given the little information you provide even if I was I’m not sure I could help 🙂
[…] http://www.thertrader.com/2014/09/22/installing-rrstudio-on-ubuntu-14-04/ […]
Thank you a lot!!! Very usefull!!