Professional Documents
Culture Documents
HowToSetUpRonUbuntu14.04|DigitalOcean
By:DeanAttali
Community
Share
Menu
Contents
HowToSetUpRonUbuntu14.04
Jul13,2015
ApplicationsUbuntu
Introduction
Risapopularopensourceprogramminglanguagethatspecializesinstatisticalcomputing
andgraphics.Itiswidelyusedbystatisticiansfordevelopingstatisticalsoftwareand
performingdataanalysis.OneofR'sstrengthsisthatitishighlyandeasilyextensibleby
allowinguserstoauthorandsubmittheirownpackages.TheRcommunityisknowntobe
veryactiveandisnotedforcontinuouslyaddinguser-generatedstatisticalpackagesfor
specificareasofstudy,whichmakesRapplicabletomanyfieldsofstudy.
The"ComprehensiveRArchiveNetwork"(CRAN)isacollectionofsites(calledmirrors)which
carryidenticalmaterial,consistingofmanyRpackagesandtheRdistributionsthemselves.
YoucandownloadRandmanyRpackagesfromanyoftheCRANmirrors,butwewillusethe
RStudiomirror.
Inthisguide,wewilllearnhowtosetupRonaDigitalOceanDropletrunningUbuntu14.04.If
yourDropletisrunningadifferentoperatingsystem,mostoftheinstructionswillstillapply,
butyoumayneedtomodifysomeofthecommands.Followingthisguidetocompletion
shouldtakeabout10-15minutes.
Prerequisites
Forthistutorial,youwillneed:
Ubuntu14.04Dropletwithatleast1GBofRAM.IfyourDroplethaslessthan1GBofRAM,
youneedtoadd1GBofswapspace(HowToAddSwaponUbuntu14.04givesyoustep-
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
1/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
by-stepinstructionsforaddingswapspace.)
Anon-rootuserwithsudoprivileges(InitialServerSetupwithUbuntu14.04explainshow
tosetthisup.)
Allthecommandsinthistutorialshouldberunasanon-rootuser.Ifrootaccessisrequired
forthecommand,itwillbeprecededby
sudo .InitialServerSetupwithUbuntu14.04explains
howtoaddusersandgivethemsudoaccess.
Step1SettingUpAPT
ToinstallR,we'regoingtousetheAPT(AdvancedPackagingTool)tool.Itusesaspecialfile
thatliststhesourcesofwherepackagesshouldbedownloadedfrom.Thatfileis
/etc/apt/sources.list .InordertogetthemostrecentversionofR,weneedtoaddthe
correctrepositorytothelistofsourcesbyaddingalinetothesourcesfile.Theexactlineyou
needtoaddwillvarydependingontheexactUbuntuversion.ForUbuntu14.04,runthe
followingcommandtoaddthecorrectrepositoryto
/etc/apt/sources.list .
$ sudoshc'echo"debhttp://cran.rstudio.com/bin/linux/ubuntutrusty/">>/etc/apt/source
IfyouarerunningadifferentUbuntuversion,consultthisdocumentforthecorrectrepository
toadd.
ToauthenticatepackagesdownloadedusingAPT,wehavetoaddapublickey.TheUbuntu
archivesonCRANaresignedwithakeywithIDE084DAB9.Addthiskeytoyoursystem.
$ gpgkeyserverkeyserver.ubuntu.comrecvkeyE084DAB9
Nextweneedtoaddthekeyto
apt .
$ gpgaexportE084DAB9|sudoaptkeyadd
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
2/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
Step2InstallingR
NowthatAPThasbeensetupproperly,wearereadytouseittoinstallR.
First,weneedtoupdatethelistofavailablepackagessinceweupdatedthesourceslist.
$ sudoaptgetupdate
NowwecaninstallR.Weusethe
y flagtoautomaticallyanswerYeswhenaskedifweare
surewewanttodownloadthepackage.
$ sudoaptgetyinstallrbase
Atthispoint,youshouldhaveaninstallationofthelatestRversiononyourDroplet.Youcan
testthisbyrunningthe
R command.
$ R
Youshouldseeoutputsimilartothefollowing.
Rversion3.2.1(20150618)"WorldFamousAstronaut"
Copyright(C)2015TheRFoundationforStatisticalComputing
Platform:x86_64pclinuxgnu(64bit)
RisfreesoftwareandcomeswithABSOLUTELYNOWARRANTY.
Youarewelcometoredistributeitundercertainconditions.
Type'license()'or'licence()'fordistributiondetails.
NaturallanguagesupportbutrunninginanEnglishlocale
Risacollaborativeprojectwithmanycontributors.
Type'contributors()'formoreinformationand
'citation()'onhowtociteRorRpackagesinpublications.
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
3/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
Type'demo()'forsomedemos,'help()'foronlinehelp,or
'help.start()'foranHTMLbrowserinterfacetohelp.
Type'q()'toquitR.
>
YouarenowinsidetheRinteractiveshellandcanrunarbitraryRcommands.
QuitR,andreturntoyourDropletwiththe
q() function:
> q(save="no")
Step3InstallingRPackagesfromCRAN
NowthatRisinstalledonyourDroplet,anyuserontheDropletcanuseR.WhenRis
installed,itautomaticallyinstallsanumberofdefaultpackages,butinordertodoanything
trulymeaningfulinRyouwillprobablyneedtoinstallextrapackages.Itisimportanttohave
atleast1GBofRAMavailableinordertoinstallmanypackages,whichisthereasonthatthe
prerequisitessectioninstructedyoutoaddswapspaceifyourDroplethaslessthan1GBof
RAM.
Asmentionedpreviously,CRANhostsnotonlyRitself,butmanyRpackagesaswell.To
installnewRpackagesthatarehostedonCRAN,ortoupdateexistingones,youusethe
install.packages() functioninR.Ifyouwantedtoinstallpackagesomepackage,you
wouldopenRandrunthefollowingRcommand.
#Thisisanexample,donotrunthis
install.packages("somepackage")
However,anypackageinstalledbyaspecificuserinRwillonlybeavailabletothatuserby
default.Forexample,ifusersammyinstallssomepackage,thenuserjessiewillnotbeableto
usesomepackageuntiltheyinstallitaswell.
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
4/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
ItispossibletoinstallanRpackageinawaythatmakesitavailabletoallusersonthe
Dropletbyinstallingitasroot.Asanexample,let'sinstallthe
shiny package,whichisavery
popularpackageusedtocreatewebapplicationsfromRcode.Onewaytoinstallthe
packageasrootwouldbetologinasroot,runR,andrunthe
install.packages()
command.However,it'srecommendednottologinasroot,soinsteadwecanjustruntheR
commandasroot.We'llalsospecifythe
repos parametersothatthepackageis
downloadedfromtheRStudioCRANrepository,thesameoneweusedwhendownloadingR
itself.
$ sudosuc"Re\"install.packages('shiny',repos='http://cran.rstudio.com/')\""
ByinstallingapackagethiswayratherthanopeningRandrunningthe
command,the
install.packages()
shiny packageismadeavailabletoallusersontheDroplet.
Let'sverifythat
shiny wasinstalledcorrectlybytryingtoloadit.StartanRsession.
$ R
InR,tryloadingthe
shiny package.
> library(shiny)
Runningthepreviouscommandshouldresultinnoerrors.NowquitR.
> q(save="no")
install.packages() function,therearemanymorepackagesthatarehostedonGitHub
butarenotonCRAN.ToinstallRpackagesfromGitHub,weneedtousethe
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
devtools R
5/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
package,solet'sinstallit.
The
devtools RpackagerequiresthreesystempackagestobeinstalledontheDroplet,
namely
packages:
$ sudoaptgetyinstalllibcurl4gnutlsdevlibxml2devlibssldev
Nowthe
devtools Rpackagecanbeinstalled.Rememberthatwewanttoinstallitusingthe
samemethodasdescribedabove,ratherthaninstallitwithinanRsession,because
devtools shouldbeavailabletoallusers.
$ sudosuc"Re\"install.packages('devtools',repos='http://cran.rstudio.com/')\""
Theabovecommandtoinstall
devtools couldtakeseveralminutestocomplete.
Step5InstallingRPackagesfromGitHub
Nowthatwehave
the
devtools installed,wecaninstallanyRpackagethatisonGitHubusing
install_github() function.JustlikewithCRANpackages,wheninstallingGitHub
packagesyouneedtorunthecommandfromthesystemshelltomakethepackage
availabletoallusers.Let'stryinstallingthe
functionalitytothe
anditsname(
shinyjs GitHubpackage,whichadds
shinyjs ).
$ sudosuc"Re\"devtools::install_github('daattali/shinyjs')\""
Let'sverifythat
shinyjs wasinstalledcorrectlybytryingtoloadit.StartanRsession.
$ R
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
6/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
InR,tryloadingthe
shinyjs package.
> library(shinyjs)
Runningthepreviouscommandcouldresultinsomemessages,butnoerrormessages.Now
quitR.
> q(save="no")
NextSteps
YounowhaveaworkingRinstallationonyourDroplet.
TolearnmoreaboutR,visittheofficialRwebsite,ortrylearningRhands-onandinteractively
withthe
swirl package.
FormoreinformationonCRANandwhatitoffers,visittheofficialCRANwebsite.
ForabetterexperiencewritingRcodeonyourDroplet,youmaywanttoinstallanRStudio
Serverusingthistutorial.
IfyouwanttohostanyofyourShinycodeonyourDroplet,youmaywanttoinstallaShiny
Serverusingthistutorial.
Conclusion
Inthisguide,wewentthroughthestepsrequiredtosetupRonanUbuntu14.04Droplet.We
alsolearnedthedifferencebetweeninstallingRpackagesfromGitHubvsCRANandhowto
ensurethatthesepackagesaremadeavailableforallusersontheDroplet.
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
7/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
Heart
Share
Author:
Subscribe
Editor:
DeanAttali
TammyFox
SpinupanSSDcloudserverinunderaminute.
Simplesetup.Fullrootaccess.Straightforwardpricing.
DEPLOYSERVER
RelatedTutorials
HowtoInstallandConfigureMagentoonUbuntu14.04
HowToDeployaRailsAppwithazk
HowToRunAMeteorAppSecurelyWithSandstormonUbuntu14.04
HowToDeployaClojureWebApplicationonFreeBSD10.2
HowToDeployaClojureWebApplicationonUbuntu14.04
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
8/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
6Comments
Leaveacomment...
Loggedinas:
Notifymeofreplies
tomycomment
Comment
chrisfs59 August8,2015
Thanksabunchforthis!Quiteuseful
daattali August8,2015
Gladtoknowifhelps,thanksfortakingthetimetosaythat:)
drexlar October11,2015
CongratulationsDean.Excellenttutorial.IfollowedyourtutorialtotheletterandIcouldinstallR
andthepackagesyoumentionedinmyUbuntu14.04.3.Thankyouforsharingthiswiththe
community.
diegodiazespino January22,2016
Another"Easywaytoinstall*onUbuntu*"byDigitalOcean.Thanks,yousaveourtime
saileswari January24,2016
AfterInstallingR,itriedtoinstalledbelowstatement.
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
9/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
$sudoapt-get-yinstalllibcurl4-gnutls-devlibxml2-devlibssl-dev
Itdisplaysthebelowerror.
"
Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
E:Unabletolocatepackagelibcur14-gnutls-dev"
whatshouldIdo?
daattali January24,2016
Firstofall,installingthesetoolsisnot100%mandatory.Youonlyneedthemifyouwanttouse
the
devtools package(which,inturn,youonlyneedtoinstallifyouwanttoinstallGitHub
packages).
Inregardstoyourerror,areyousureyoufollowedallthepreviousstepsexactly?Specifically,
areyouonUbuntu14.04,anddidyourunthesecommands:
sudoshc'echo"debhttp://cran.rstudio.com/bin/linux/ubuntutrusty/">>/etc/apt/sou
gpgkeyserverkeyserver.ubuntu.comrecvkeyE084DAB9
gpgaexportE084DAB9|sudoaptkeyadd
sudoaptgetupdate
sudoaptgetyinstalllibcurl4gnutlsdevlibxml2devlibssldev
Ifyouranthesecommandsandyou'reusingtherightOS,Idon'tseewhyitwouldn'tfindit.Try
creatingabrandnewdropletandfollowingtheseinstructionsagain,perhapstherewasaweird
problemwithyourdroplet.
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
10/11
18/4/2016
HowToSetUpRonUbuntu14.04|DigitalOcean
ThisworkislicensedunderaCreative
CommonsAttribution-NonCommercialShareAlike4.0InternationalLicense.
Copyright2016DigitalOceanInc.
Community
Distros&One-ClickApps
Tutorials
Questions
Terms,Privacy,&Copyright
https://www.digitalocean.com/community/tutorials/howtosetupronubuntu1404
Projects
Security
Tags
RSS
ReportaBug
GetPaidtoWrite
11/11