title: Where to install R packages on Linux server that are to be used by multiple users?
body: <p>We are running RStudio Server on an AWS-hosted CentOS Linux server. We have multiple users on the server each using RStudio Server. We'd like to have a common path for all users to install packages so that:</p>
  
  <ol>
  <li>Each user does <em>not</em> need to install every package for their RStudio user profile</li>
  <li>If one person updates a package, every user will be using the updated  </li>
  </ol>
  
  <p>What is the best procedure to do this?</p>
  
  <p>My proposed solution was the following, but it failed:</p>
  
  <p>Save a list of my existing user packages:</p>
  
  <pre><code>&gt; save.pkg.list &lt;- installed.packages()[is.na(installed.packages()[ , "Priority"]), 1]
  &gt; save(save.pkg.list, file="pkglist.Rdata")
  </code></pre>
  
  <p>Remove user packages:</p>
  
  <pre><code>&gt; remove.packages(save.pkg.list)
  </code></pre>
  
  <p>Then, my idea was to install the packages from <code>save.pkg.list</code> into a folder under root. There was already what seemed to be a shared folder <code>/usr/share/R/library</code> which contained one package in my library path:</p>
  
  <pre><code>.libPaths() [1] "/home/ursus/R/x86_64-redhat-linux-gnu-library/3.1" "/usr/lib64/R/library" "/usr/share/R/library"
  </code></pre>
  
  <p>To test it out, I attempted to install one package into the shared folder and see if other users on the server could use it in their R instances. The installation failed, most probably because it is under root and I'm assuming I need to use sudo privileges (which I have) but not sure how to <em>pass</em> those to R for the package installation process:</p>
  
  <pre><code>install.packages("dlm", lib = "/usr/share/R/library") Warning in install.packages : 'lib = "/usr/share/R/library"' is not writable
  </code></pre>
  
  <p>Eventually, I'm assuming there need to be some changes to the <code>R_LIBS_SITE</code> and <code>R_LIBS_USER</code> environment variables or something like that to control the default package installation / loading behavior. But, I'm not there yet.</p>