Is there any way to automate the Installation Of R-Studio on Linux Systems? It should automatically detect operating system and install R and R-Studio with required dependencies. Thanks..
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I have prepared the following shell script to make this installation fully automated.
#!/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;
How to Launch R-Studio in Ubuntu or Debian Systems? Enter the following command on the terminal:
rstudio;
How to Launch R-Studio in CentOS or RedHat Systems? Open the Following URL in browser:
http://localhost:8787
After that Login prompt will appear & then Login with the current system user credentials.
回答2:
I use this to install the current release of R and the preview release of RStudio on Ubuntu (32 or 64 bit), along with pkgs that I use frequently:
#!/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"
This comes from my VM setup script here: https://gist.github.com/benmarwick/11204658