2015-04-16 28 views

回答

2

我准备了以下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; 

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

http://localhost:8787 

是登录提示后会出现&然后与当前系统用户凭据登录。

2

我使用它来安装R的当前版本和RStudio的在Ubuntu(32位或64位)的预览版,与我经常使用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 
# http://stackoverflow.com/a/15046782/1036500 
# check if 32 or 64 bit and install appropriate version... 
# http://stackoverflow.com/a/106416/1036500 

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" 
# http://stackoverflow.com/q/4090169/1036500 
# 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" 

这来自我的虚拟机的设置脚本在这里:https://gist.github.com/benmarwick/11204658

+0

不错。但作为一般提示,'sudo apt-get install'可以有多个参数。所以我会折叠上面重复的许多行[我们是如何在Rocker容器中做的](https://github.com/rocker-org/rocker/blob/master/r-base/Dockerfile#L44-L49) 。 –

+0

谢谢,是的,你的方法更加整洁。 – Ben