Search code examples
linuxrvagranthomesteadrmysql

Installing R-Script and RMySQL on a vagrant box


I have been looking for a guide to install R-Script and (in particular) RMySQL on a laravel homestead vagrant box. However the documentation I have found has either been for windows OS's or has failed before installing the RMySQL package.

So my question is this: How do I go about installing R Script and RMySQL onto a "homestead" vagrant box?

The steps I have already followed are as follows:

> 1) vagrant up  
> 2) vagrant ssh  
> 3) sudo apt_get install r-base 
> 4) sudo apt-get install r-base-dev  
> 5) sudo apt-get update

This successfully installs R onto my vagrant box. However, when I try to install the RMySQL package as per the following article

https://snipt.net/raw/646356bd03e88788f6055e0f9eb55394/?nice

using install.packages("RMySQL"), then i get the following error:

> -bash: syntax error near unexpected token '"RMySQL"'

I have tried with single quote, double quotes and without quotes an each time it returns an unexpected token. I have also tried running this as vagrant@homestead:/$ and vagrant@homestead:~$ but to no avail.

Once I have understood the manual process of adding these packages, I plan on automatically provisioning my vagrant box with both R and the RMySQL. Any suggestions on how this is best achieved would also be helpful. As you may be able to tell from this question, I am fairly new to server administration so any assistance would be very much appreciated.


Solution

  • Installing R

    On a Mac:

    Have Homebrew installed

    brew tap homebrew/science
    brew install r
    

    Listen to your computer's fan for a while

    On a Debian-like system like Vagrant boxes - (Ubuntu 14.04 here):

    For installing on a Vagrant box, open a Terminal window using Vagrant Manager, then follow the instructions below.

    Add the R repository to aptitude

    sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'
    

    Add its GPG key so that you don't get cert errors

    gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
    gpg -a --export E084DAB9 | sudo apt-key add -
    

    Refresh aptitude

    sudo apt-get update
    

    Install R from new repository

    sudo apt-get -y install r-base
    

    Installing RMySQL

    First install libmysqlclient

    sudo apt-get install libmysqlclient-dev
    sudo apt-get install r-cran-rmysql
    

    Then Run R to enter a REPL

    install.packages('RMySQL')