
Installing RStudio from Source
=============================================================================

This document describes how to build and install RStudio from the source
distribution. Information on obtaining the RStudio source code can be found
in the file SOURCE. Note that precompiled binaries are also available for
Windows, macOS, as well as recent versions of various Linux distributions.

Note, the target "Electron" should be used when building the Desktop IDE.
The "Desktop" target builds the legacy Qt application, is no longer 
supported, and will eventually be removed.

1) Installing Dependencies
----------------------------------------------------------------------------

Building RStudio requires a number of dependencies (including R itself).
There are platform-specific instructions for satisfying these dependencies
within the following directories

   dependencies
      linux
      osx
      windows

Please see the README file contained within the root of each platform's
directory for specific instructions.


2) Configuring the Build Environment
----------------------------------------------------------------------------

a) From the root of the RStudio tree create a build directory and then
   change to it:

   mkdir build
   cd build


b) Configure the build using cmake as appropriate, e.g.

   cmake .. -DRSTUDIO_TARGET=Server -DCMAKE_BUILD_TYPE=Release
   cmake .. -DRSTUDIO_TARGET=Electron -DRSTUDIO_PACKAGE_BUILD=1

   Variables that control configuration include:

   RSTUDIO_TARGET        Electron or Server

   RSTUDIO_PACKAGE_BUILD Electron: must be set to 1 for following cases:
                           "make install"
                           "make-package"

   CMAKE_BUILD_TYPE      Debug, Release, RelMinSize, or RelWithDebInfo

   CMAKE_INSTALL_PREFIX  Defaults:
                           Linux (Electron):    /usr/local/lib/rstudio
                           Linux (Server):      /usr/local/lib/rstudio-server
                           macOS:               /Applications/RStudio
                           Windows:             C:\Program Files\RStudio


c) There are additional considerations on Windows. First, RStudio Server
   is not supported on Windows so the configuration always defaults to
   Electron. Second, you need to add an extra -G parameter to specify the
   correct build toolchain, for example:

   cmake .. -G "Visual Studio 16 2019" -A Win64 -DCMAKE_BUILD_TYPE=Release

   To build on Windows:

   cmake --build . --config Release


3) Building and Installing
----------------------------------------------------------------------------

a) Acquire administrative rights (if necessary). If you have configured
   RStudio to be installed in a protected directory (the default on all
   platforms) then you need to run the build/install command as an
   administrator (e.g. "su -", "sudo sh", or running a console as an
   Administrator on Windows)


b) Change to the build directory where you configured RStudio


c) Run the "make install" command:

   Linux & macOS:  sudo make install        OR
   Windows:        cmake --build . --config Release --target install

   NOTE: For RStudio Desktop on Linux, make install automatically creates
   an entry in the Applications -> Programming menu for RStudio.


d) If you are installing RStudio Server some additional configuration
   steps are required to complete the installation. These steps are
   detailed in the section below.


4) RStudio Server Configuration
----------------------------------------------------------------------------

If you have installed RStudio Server from source there are a number of other
steps (some required, some optional) you should take to complete your
installation. Note that these steps are taken automatically by the DEB
and RPM pre-built binary distributions of RStudio Server.

a) Create an rstudio-server system user account (RStudio will automatically
   run under this account if it is present). You can do this with:

   sudo useradd -r rstudio-server


b) RStudio Server uses PAM to authenticate users. Some Unix systems (such
   as Debian and Ubuntu) use default PAM settings for applications which
   aren't explicitly registered with PAM, so don't require additional PAM
   configuration. If however your system requires explicit registration
   (i.e. Redhat, Fedora, openSUSE) then you need to add an
   /etc/pam.d/rstudio file to your configuration. You can find a default
   version of this file at:

   extras
      /pam
         rstudio


c) Register RStudio as a daemon using an init.d (for most systems) or
   systemd(for Ubuntu from 15.04, RHEL from 7) or upstart (for Ubuntu
   before 15.04) or launchd plist (for Mac OSX) script appropriate to your system.
   The rstudio/server/extras directory contains the following scripts:

   extras
      /init.d
         /debian
            rstudio-server
         /redhat
            rstudio-server
         /suse
            rstudio-server
      /systemd
            rstudio-server.redhat.service
            rstudio-server.service
      /upstart
            rstudio-server.redhat.conf
            rstudio-server.conf
      /launchd
            com.rstudio.launchd.rserver.plist

   NOTE: installation of init.d scripts require both copying them
   into /etc/init.d, making them executable (chmod +x), as well as
   executing a system dependent command to ensure that the service
   is registered with the appropriate runlevels. For example:

   Debian:      sudo update-rc.d rstudio-server defaults
   Redhat/SUSE: sudo /sbin/chkconfig --add rstudio-server


d) Create a soft link in /usr/sbin to the server administrative script

   sudo ln -f -s /usr/local/lib/rstudio-server/bin/rstudio-server /usr/sbin/rstudio-server

   Assuming you have previously installed an init.d or upstart script (as
   described above) then you should now be able start the server with the
   following command:

   sudo rstudio-server start

   Additional commands include stop, restart, offline, online, and others

e) Create /var directories required for RStudio to run. This can be done with:

   mkdir -p /var/log/rstudio/rstudio-server
   mkdir -p /var/lib/rstudio-server


