使用 Shell 脚本自动安装 R-Studio

Automated Installation of R-Studio Using Shell Script

有什么方法可以在 Linux 系统上自动安装 R-Studio?它应该自动检测操作系统并安装具有所需依赖项的 R 和 R-Studio。 谢谢..

我准备了以下 shell 脚本来使此安装完全自动化。

#!/bin/bash
# ******************************************
# Program: R-Studio Installation Script
# Developer: Pratik Patil
# Date: 16-04-2015
# Last Updated: 16-04-2015
# ********************************************

if [ "`lsb_release -is`" == "Ubuntu" ] || [ "`lsb_release -is`" == "Debian" ]
then
    sudo apt-get -y install r-base gdebi-core libapparmor1;
    sudo wget http://download2.rstudio.org/rstudio-server-0.98.1103-amd64.deb;
    sudo gdebi rstudio-server-0.98.1103-amd64.deb;

elif [ "`lsb_release -is`" == "CentOS" ] || [ "`lsb_release -is`" == "RedHat" ]
then
    sudo yum -y install R openssl098e;
    sudo wget http://download2.rstudio.org/rstudio-server-0.98.1103-x86_64.rpm;
    sudo yum -y install --nogpgcheck rstudio-server-0.98.1103-x86_64.rpm;
else
    echo "Unsupported Operating System";
fi

sudo rm -f rstudio-server-*;
sudo rstudio-server verify-installation;

如何在 Ubuntu 或 Debian 系统中启动 R-Studio? 在终端输入以下命令:

rstudio;

如何在 CentOS 或 RedHat 系统中启动 R-Studio? 在浏览器中打开以下 URL:

http://localhost:8787

之后会出现登录提示,然后使用当前系统用户凭据登录。

我用它在 Ubuntu(32 位或 64 位)上安装 R 的当前版本和 RStudio 的预览版,以及我经常使用的 pkgs:

#!/bin/bash

# this script can be run from the terminal with the next line (minus the #)
# bash install_things.sh

# you may  need to enter your password at a few points, so keep an eye on it while it runs.

# in case we need to step through:
# set -x
# trap read debug

echo "install a few dependancies for our workflow"
sudo apt-get update  -y
# sudo apt-get upgrade  -y
sudo apt-get install libgstreamer0.10-0 -y
sudo apt-get install libgstreamer-plugins-base0.10-dev -y
sudo apt-get install libcurl4-openssl-dev -y
sudo apt-get install libssl-dev -y
sudo apt-get install libopenblas-base -y
sudo apt-get install libxml2-dev -y
sudo apt-get install make -y
sudo apt-get install gcc -y
sudo apt-get install git -y
sudo apt-get install pandoc -y
sudo apt-get install libjpeg62 -y
sudo apt-get install unzip -y
sudo apt-get install curl -y
sudo apt-get install littler -y
sudo apt-get install openjdk-7-* -y
sudo apt-get install gedit -y
sudo apt-get install jags -y
sudo apt-get install imagemagick -y
sudo apt-get install docker-engine -y


echo "edit the sources file to prepare to install R"
# see http://cran.r-project.org/bin/linux/ubuntu/README
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" >> /etc/apt/sources.list' # I'm using Lubuntu

echo "get keys to install R"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 # # I'm using Lubuntu

echo "install R and some helpers"
sudo apt-get update
sudo apt-get install r-base  -y
sudo apt-get install r-base-dev -y
sudo apt-get install r-cran-xml  -y
sudo apt-get install r-cran-rjava -y
sudo R CMD javareconf # for rJava

echo "install RStudio from the web"
# use daily build to get rmarkdown & latest goodies
# 
# check if 32 or 64 bit and install appropriate version... 
# 

MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  # 64-bit stuff here

URL=$(wget -q -O -  http://www.rstudio.org/download/daily/desktop/ubuntu64 | grep -o -m 1 "https[^\']*" )

FILE=`mktemp`; sudo wget "$URL" -qO $FILE && sudo dpkg -i $FILE; rm $FILE

else
  # 32-bit stuff here

URL=$(wget -q -O -  http://www.rstudio.org/download/daily/desktop/ubuntu32 | grep -o -m 1 "https[^\']*" )

FILE=`mktemp`; sudo wget "$URL" -qO $FILE && sudo dpkg -i $FILE; rm $FILE
fi


echo "start R and install commonly used packages"
# 
# Make an R script file to use in a moment...
LOADSTUFF="options(repos=structure(c(CRAN='http://cran.rstudio.com/')))
update.packages(checkBuilt = TRUE, ask = FALSE)
packages <- c('codetools', 'Rcpp', 'devtools', 'knitr', 'ggplot2',  'plyr', 'dplyr', 'XML', 'RCurl', 'readxl', 'tidyr') 
# just some of my most often used ones
install.packages(packages)
# and some from github
devtools::install_git(c('https://github.com/rstudio/rmarkdown.git',  'https://github.com/hadley/reshape'))" # close the R script

# put that R code into an R script file
FILENAME1="loadstuff.r"
sudo echo "$LOADSTUFF" > /tmp/$FILENAME1

# Make a shell file that contains instructions in bash for running that R script file
# from the command line. There may be a simpler way, but nothing I tried worked.
NEWBASH='#!/usr/bin/env 
sudo Rscript /tmp/loadstuff.r'
FILENAME2="loadstuff.sh"

# put that bash code into a shell script file
sudo echo "$NEWBASH" > /tmp/$FILENAME2

# run the bash file to exectute the R code and install the packages
sh /tmp/loadstuff.sh
# clean up by deleting the temp file
rm /tmp/loadstuff.sh 

# done.
echo "all done"
echo "type 'sudo rstudio' in the terminal to start RStudio"

这来自我的 VM 设置脚本:https://gist.github.com/benmarwick/11204658