Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install R and RStudio on Ubuntu 18.04 with essential libraries for data science. Based on pachamaltese/r_ubuntu_17_10.sh (for Ubuntu 17.10). Note: You need to make sure the default library location - /usr/local/lib/R/site-packages - is writable .
# Install R
sudo apt update
sudo apt install gdebi libxml2-dev libssl-dev libcurl4-openssl-dev libopenblas-dev r-base r-base-dev
# Install RStudio
cd ~/Downloads
wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-1.2.5001-amd64.deb
sudo gdebi rstudio-1.2.5001-amd64.deb
printf '\nexport QT_STYLE_OVERRIDE=gtk\n' | sudo tee -a ~/.profile
# Install common packages
R --vanilla << EOF
install.packages(c("tidyverse","data.table","dtplyr","devtools","roxygen2","bit64","readr"), repos = "https://cran.rstudio.com/")
q()
EOF
# Install TDD packages
R --vanilla << EOF
install.packages("testthis")
q()
EOF
# Export to HTML/Excel
R --vanilla << EOF
install.packages(c("htmlTable","openxlsx"), repos = "https://cran.rstudio.com/")
q()
EOF
# Blog tools
R --vanilla << EOF
install.packages(c("knitr","rmarkdown"), repos='http://cran.us.r-project.org')
q()
EOF
sudo apt install python-pip
sudo apt install python3-pip
sudo -H pip install markdown rpy2==2.7.1 pelican==3.7.1
sudo -H pip3 install markdown rpy2==2.9.3 pelican==3.7.1
# PDF extraction tools
sudo apt install libpoppler-cpp-dev default-jre default-jdk r-cran-rjava
sudo R CMD javareconf
R --vanilla << EOF
library(devtools)
install.packages("pdftools", repos = "https://cran.rstudio.com/")
install_github("ropensci/tabulizer")
q()
EOF
# TTF/OTF fonts usage
sudo apt install libfreetype6-dev
R --vanilla << EOF
install.packages("showtext", repos = "https://cran.rstudio.com/")
q()
EOF
# Cairo for graphic devices
sudo apt install libgtk2.0-dev libxt-dev libcairo2-dev
R --vanilla << EOF
install.packages("Cairo", repos = "https://cran.rstudio.com/")
q()
EOF
# Texlive for Latex/knitr
sudo apt -y install texlive
sudo apt -y install texlive-latex-recommended texlive-pictures texlive-latex-extra
@ElToro1966

This comment has been minimized.

Copy link
Owner Author

ElToro1966 commented May 6, 2018

The intention is to have a working R Studio installation with the typical packages used in data science on Ubuntu 18.04. If you think any packages are missing, or something isn't working in the script, please let me know. The script and the resulting RStudio-installation has been tested on Ubuntu Bungie 18.04 4.15.0-20-generic. Everything seems to work perfectly

@driflore94

This comment has been minimized.

Copy link

driflore94 commented May 12, 2018

Thanks a lot man!!!, this was very useful. 👍

@tayyabsayyad

This comment has been minimized.

Copy link

tayyabsayyad commented Jun 1, 2018

Thanks a lot. Made my work so easy.

@ElToro1966

This comment has been minimized.

Copy link
Owner Author

ElToro1966 commented Jun 8, 2018

Glad you like it :) Added readr and the TDD package testthis to the mix.

@Daxide

This comment has been minimized.

Copy link

Daxide commented Jun 8, 2018

I installed R and R studio but I get the following error message: Unable to find an installation of R on the system (which R didn't return valid output); Unable to locate R binary by scanning standard locations.
How do I instruct R studio how to find R binary?

@tepoe

This comment has been minimized.

Copy link

tepoe commented Aug 22, 2018

Thanks a lot! Works perfectly with Linux Mint 19, unlike other instructions on the web in my experience.

@sapuizait

This comment has been minimized.

Copy link

sapuizait commented Sep 1, 2018

Thank you ElToro - lots of nice features that I didnt know about!

@bvl2016

This comment has been minimized.

Copy link

bvl2016 commented Sep 8, 2018

Thank you very much!

@parveenmudgil

This comment has been minimized.

Copy link

parveenmudgil commented Nov 27, 2018

Thanks a lot

@sapuizait

This comment has been minimized.

Copy link

sapuizait commented Jan 17, 2019

This is fantastic! Thank you so much!

@nayan2000

This comment has been minimized.

Copy link

nayan2000 commented Jan 20, 2019

Thanks a lot! Works perfectly fine.

@remitoudic

This comment has been minimized.

Copy link

remitoudic commented Feb 14, 2019

👍

@nicolasaaron

This comment has been minimized.

Copy link

nicolasaaron commented Feb 15, 2019

Thank you very much !! this is really helpful

@ElToro1966

This comment has been minimized.

Copy link
Owner Author

ElToro1966 commented Jul 25, 2019

I installed R and R studio but I get the following error message: Unable to find an installation of R on the system (which R didn't return valid output); Unable to locate R binary by scanning standard locations.
How do I instruct R studio how to find R binary?

That's odd. Never had that problem. Are you sure R is installed correctly? If so, is it installed in the default location? See also https://support.rstudio.com/hc/en-us/community/posts/223945507-can-t-start-rstudio-how-to-specify-non-standard-path-to-R-

@albsch

This comment has been minimized.

Copy link

albsch commented Aug 6, 2019

Glad you like it :) Added readr and the TDD package testthis to the mix.

Please fix the script, line 18 is executed outside the R environment. It just ends with a syntax error currently. I'm actually wondering why people report it's working for them.

Also, for Ubuntu 18.04 users, make sure the default library location is writable (/usr/local/lib/R/site-packages). I had to add myself to the staff group.

@ElToro1966

This comment has been minimized.

Copy link
Owner Author

ElToro1966 commented Aug 30, 2019

Please fix the script, line 18 is executed outside the R environment. It just ends with a syntax error currently. I'm actually wondering why people report it's working for them.

Also, for Ubuntu 18.04 users, make sure the default library location is writable (/usr/local/lib/R/site-packages). I had to add myself to the staff group.

Code fixed. Comment on writeable library location added. Thanks.

@shevkoplyas

This comment has been minimized.

Copy link

shevkoplyas commented Dec 14, 2019

Thank you, Eric!
[Q] when it's time to "install.packages" I'm getting error: 'lib = "/usr/local/lib/R/site-library"' is not writable, how to solve?
[A] sudo chmod a+rwx /usr/local/lib/R/site-library

@shevkoplyas

This comment has been minimized.

Copy link

shevkoplyas commented Dec 14, 2019

also, this: install.packages("testthis")
gives an error: "trying to use CRAN without setting a mirror"
but if I add 2nd argument "repos" like below, then it works:
install.packages("testthis", repos = "https://cran.rstudio.com/")

@shevkoplyas

This comment has been minimized.

Copy link

shevkoplyas commented Dec 14, 2019

also the latest version of rstudio package is now moved from "1.2.5001" up to "1.2.5019" and will be different in future, so may be add a comment, that latest version number can be peeked up and adjusted by reading official download page: https://rstudio.com/products/rstudio/download/

@webenk

This comment has been minimized.

Copy link

webenk commented Dec 18, 2019

Nope! Now I'm sad.
I've installed R Studio about fifty times from R Studio's websit on my Ubuntu 18.04 box here and it crashes. The app will appear (maybe) and then instantly - it crashes. I've checked file permissions, combed through R Studio Community Forums - nothing seems to work.
I cleaned out everything on my machine related to R Studio so as to not "mix it up". I thought - perhaps this instruction sheet would solve it.
Nope! It still crashes.
I have to use Pycharm, which I totally hate - but I have no choice.
As I said: Now I'm sad.
MWH

@fcsest

This comment has been minimized.

Copy link

fcsest commented Jan 29, 2020

What this command line does (or should do)?
printf '\nexport QT_STYLE_OVERRIDE=gtk\n' | sudo tee -a ~/.profile

@shevkoplyas

This comment has been minimized.

Copy link

shevkoplyas commented Jan 29, 2020

@dorita-bio

This comment has been minimized.

Copy link

dorita-bio commented Feb 14, 2020

Thanks a lot, I managed to install Rstudio, however, it keeps crushing for me.
As soon as I load a file and try to generate plots, rstudio closes before any prior notice. Sometimes it also freezes.
Do you have an idea of what is happening please?

@shevkoplyas

This comment has been minimized.

Copy link

shevkoplyas commented Feb 14, 2020

@beuchi123

This comment has been minimized.

Copy link

beuchi123 commented Apr 7, 2020

Thanks a lot for this. it was super useful.

@hapstraid

This comment has been minimized.

Copy link

hapstraid commented Jun 1, 2020

It turned out to install only with the replacement of line 19 by:
install.packages("testthis", repos = "https://cran.rstudio.com/")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.