RStudio Server on Mac OS X

In an earlier post, I have a link to an approach to installing RStudio Server on Mac OS X suggested by Matt Furia.

A more streamlined approach (though essentially that suggested by Matt) builds on MacPorts or Homebrew. The following assumes you have this (and its dependencies) installed.

1. Install Git

sudo port install git

2. Install other requirements from MacPorts

(Thanks to Peter Hagedorn for pointing out the need for apache-ant. Note that qt4-mac no longer seems necessary.

sudo port install cmake apache-ant

3. Get RStudio Server source code

 git clone https://github.com/rstudio/rstudio.git

4. Install dependencies provided by RStudio

cd rstudio/dependencies/osx/
sudo ./install-dependencies-osx
cd ../.. # Go back to rstudio directory

4. Build RStudio Server

mkdir build
cd build
cmake -DRSTUDIO_TARGET=Server -DCMAKE_BUILD_TYPE=Release ..
sudo make install

5. Configure the Server to Start at Boot
OS X uses launchd for managing daemons. To configure the RStudio daemon, create the file /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.rstudio.launchd.rstudio</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/lib/rstudio-server/bin/rserver</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>

6. Start the server and (a recent change) ensure that it starts up when you launch the computer.

sudo defaults write /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist Disabled -bool false
sudo launchctl load /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist

7. Test the server.
Open up a browser on the machine you installed it on and head to http://localhost:8787

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

63 Responses to RStudio Server on Mac OS X

  1. Pingback: RStudio Server on a Mac | iangow

  2. beatsnpeace says:

    Thanx for the post…. One question though: in order to manage users accounts/credential for remote log in into RStudio, do you go about it the usual way: Apple/system preference/accounts and the create a standard account?

    Thanx in advance

  3. Dulani says:

    I just used your instructions to install RStudio Server on my new corporate Mac with Mountain Lion. Thank you SO much for posting these updated and simplified instructions. Also thanks to Matt Furia! (I used his original post to do an install on my previous machine but was never able to find an email address or comment block to thank him.)

    Putting RStudio Server on my laptop allows me to get LOTS of work done on my laptop without lugging it around. This is so much more superior than some of my other non-laptop lugging solutions which have involved: 1) Running R via the command line on the remote machine via Terminal, 2) using VNC to the remote machine to run RStudio desktop, 3) running RStudio desktop locally but with the remote drives mapped locally, and 4) lugging around a flash/hard drive with a local version of my data and code.

    I’ve got one remaining question. In steps 5 & 6 above, you suggest making the plist file in /System/Library/LaunchDaemons, but then the terminal commands are pointed at /Library/LaunchDaemons, is that correct? I usually start the server by hand so I’m not familiar with the daemon approach.

    • iangow says:

      I run RStudio Server on my desktops, which would be even more painful to lug around. (I end up only running R on my laptop when I don’t have internet access; i.e., almost never.) Another wrinkle for me is that I keep almost all my data in a PostgreSQL database. So RStudio Server provides a nice way for me to access those data from a browser anywhere.

      I believe that we are pulling a development version of RStudio Server from Github and I have one or twice had small bugs with a new installation that were addressed by installing again (presumably with a later version). But generally I have had little issue running RStudio Server on OS X.

      Regarding the location of the launch daemon, it should be in /Library. I think Matt Furia had it in /System/Library/.., but my understanding is that that directory is for Apple, not users. I guess it might be nice to get access to the various ways of starting and stopping the server available in Linux (see here). But that is beyond my copy-and-paste knowledge of these things.

  4. ejjunju says:

    Everything went well until
    emmamac:LaunchDaemons jjunju$ sudo defaults write /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist Disabled -bool false
    emmamac:LaunchDaemons jjunju$ sudo launchctl load /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist
    launchctl: no plist was returned for: /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist
    nothing found to load
    emmamac:LaunchDaemons jjunju$

    Thjen when i tried http://localhost:8787 in safari i got “Safari cant connect to the server” and it chrome “Oops! Google Chrome could not connect to localhost:8787”.

    What could be wrong?

    • ejjunju says:

      Thank you very much for the instructions. I managed to finally install and successfully test my server. Earlier on i just copied the plist file contents into vim and for some reason the first line wasn’t being properly pasted. So i manually typed it and all worked like magic.

      I hope that updating will happen equally easily!! Thank you.
      p.s. can i remotely install packages?

      • Davish says:

        I am getting the same error about nothing to load, but typing in the first line did not work. Does anyone have an updated solution?

      • iangow says:

        @Davish: Do you have a file at /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist?

        A guess: the location may be important. In your later comment, you have put it under your user directory.

      • Davish says:

        @iangow I forgot to mention the macbook pro runs on Mavericks. I put the code into vim and saved in a file called: /Users/myname/Library/LaunchDaemons/org.rstudio.launchd.rserver.plist I typed the first line in manually like @ejjunju, but still got the error.

  5. Pingback: Installing RStudio Server on Mac OS X Mavericks | RNA.dk

  6. This did not work for me unfortunately (MacBook Pro late 2011).

    I get the following error when calling “sudo make install”

    [ 90%] Building CXX object src/cpp/session/CMakeFiles/rsession.dir/SessionAddins.cpp.o
    [ 90%] Building CXX object src/cpp/session/CMakeFiles/rsession.dir/http/SessionPosixHttpConnectionListener.cpp.o
    [ 90%] Building CXX object src/cpp/session/CMakeFiles/rsession.dir/modules/SessionCrypto.cpp.o
    [ 91%] Building CXX object src/cpp/session/CMakeFiles/rsession.dir/SessionModuleContext.mm.o
    Linking CXX executable rsession
    Undefined symbols for architecture x86_64:
    “boost::from_8_bit(std::string const&, std::codecvt const&)”, referenced from:
    core::string_utils::utf8ToWide(std::string const&, std::string const&) in librstudio-core.a(PosixStringUtils.cpp.o)
    “boost::match_results<__gnu_cxx::__normal_iterator, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator > > > const&)”, referenced from:
    boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator > >, boost::regex_traits<char, boost::cpp_regex_traits > >::match_match() in SessionConsoleProcess.cpp.o



    construction vtable for std::__1::basic_iostream<char, std::__1::char_traits >-in-std::__1::basic_stringstream<char, std::__1::char_traits, std::__1::allocator > in libboost_program_options.a(options_description.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [src/cpp/session/rsession] Error 1
    make[1]: *** [src/cpp/session/CMakeFiles/rsession.dir/all] Error 2
    make: *** [all] Error 2

    Has anyone faced the same issue? How to overcome it?

  7. Pingback: RStudio Server on Mac OS X | Ingrid Richter

  8. Pingback: RStudio Server: New Account | Ingrid Richter

  9. jichaohe says:

    Thank you so much! Everything works like a charm, except for the following warning:

    Warning message:
    Character set is not UTF-8; please change your locale

    I get above message after running first command after start-up each time, due to all locale = “C”.

    > sessionInfo()
    R version 3.1.1 (2014-07-10)
    Platform: x86_64-apple-darwin10.8.0 (64-bit)

    locale:
    [1] C

    attached base packages:
    [1] stats graphics grDevices utils datasets methods base

    loaded via a namespace (and not attached):
    [1] tools_3.1.1

    I have tried to set locale in .Rprofile but it doesn’t work. Anybody else gets the same warning?

    • iangow says:

      I’ve never managed to make that message go away. At the same time, I’ve never really encountered any issues related to it (perhaps because I set almost everything to UTF-8 in .Rprofile). I think there is something that is hard-coded in the compilation that causes this message.

  10. kjhong says:

    Thank you very much!
    Do you know how to change port number?
    can`t apply this.
    https://support.rstudio.com/hc/en-us/articles/200552316-Configuring-the-Server

  11. dpbisme says:

    Thanks for the great post!

    I was able to get RStudio Server up and running, but I’m having some issues adding users and generally managing the server. This is normally done using the ‘rstudio-server’ utility which installs in the /usr/local/lib directory after following your instructions, but it’s not clear to me how one uses this to carry out the various ‘sudo rstudio-server ‘?

    This is probably more of a general unix or sysadmin issue (I’m a novice at both), but I’d appreciate your thoughts.

    Best,

    DB

    • iangow says:

      I just create accounts using the GUI in OS X. That is, the users are OS X users who use the same ID and password to access RStudio Server.

      • dpbisme says:

        Ahh, that makes sense. I just added a user via my systems prefs, and the Rstudio server recognizes the username and password I set up for them.

        Thanks again.

      • Sebastian says:

        Hm I’ve done the same, however RStudio Server doesn’t recognize my existing users… But when I (re)start the server, the user starting the server is already logged in, even if I access the studio from remote

      • iangow says:

        Are you perhaps putting the .plist file in a user’s directory (~/Library) instead of /Library?

      • Sebastian says:

        Sorry, I can not answer to your comment directly.

        I did not use plists at all, I used the home-brew script mentioned here. After I simply start rstudio-server …

      • iangow says:

        I think you’d have to ask the producer of that homebrew gem about that (he left a comment above, I believe). You might be able to work out what’s going on by reading the gem script itself.

  12. KrasPten says:

    I am happy to add that this method also works with homebrew, at least in Yosemite.
    git is already there, no need to install.
    in step 2, use:
    brew install cmake ant

  13. Dom says:

    Thanks a bunch. The “mkdir build / cd build / cmake …” series of commands didn’t work for me. I just called cmake from the rstudio directory and it worked like a charm.

  14. Pax says:

    Thanks for this. I’m having trouble with steps 5 and 6: I create the p-list file as requested, but once I run line 1 of Step 6, it replaces writes over the p-list with:

    bplist00�^A^BXDisabled^H^H^K^T^@^@^@^@^@^@^A^A^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^$

    When I then run line 2 of Step 6, I then get this output:

    launchctl: no plist was returned for: /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist
    nothing found to load

    I’ve tried the suggestions mentioned above, but none of them worked. Server runs on OS X 10.8. Any help or suggestions you could give would be great!

    • iangow says:

      You do have the file in the right place (`ls /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist`)? That the `.plist` file gets tweaked into something non-text happens to me too (I guess Xcode might be able to read it).

  15. Zhiqiu says:

    Hi iangow,
    Thanks for sharing the instruction.

    I followed the instruction on Yosemite, everything works fine for me except for the last command, which suggesting
    /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist: Invalid or missing service identifier

    I used the vim to create the “/Library/LaunchDaemons/org.rstudio.launchd.rserver.plist” file, with the contents in step 5.

    Before I went to the step 6, I checked the plist, and it looks fine. After run the first command in the step 6. The content of file was changed to :
    bplist00Ñ^A^BXDisabled^H^H^K^T^@^@^@^@^@^@^A^A^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^U

    Then as I run the second command in step 6, I got the very first error message, which saying

    /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist: Invalid or missing service identifier

    Any suggestions for this error? Thanks.

    • iangow says:

      What do the file permissions look like?

      igows-mac-pro:personality igow$ ls -hlt /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist
      -rw------- 1 root wheel 181B Nov 20 08:59 /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist

      • Zhiqiu says:

        freds-mac-pro:bin zqhu1$ ls -hlt /Library/LaunchDaemons//org.rstudio.launchd.rserver.plist
        -rw——- 1 root wheel 56B 23 Mar 13:50 /Library/LaunchDaemons//org.rstudio.launchd.rserver.plist
        freds-mac-pro:bin zqhu1$ ls /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist
        /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist

      • Zhiqiu says:

        Since your /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist file is 181bit in size, while mine is only 56B. Could it be the cause for the error?

    • iangow says:

      Note that the code for the plist file seems to have become scrambled by WordPress at some point (HTML entities appeared). I think I’ve fixed it now.

      • Zhiqiu says:

        Yes, your are right. With the new plist file, it worked like a charm now. Thank you very much for the excellent work.

  16. Randy Lai says:

    I have created a rstudio-server formula for homebrew. For now, you just have to
    brew install homebrew/science/rstudio-server

    • Zhiqiu says:

      That is a great news to me. Thank you very much for making it easier.

    • Sebastian says:

      Hi Randy, I have a problem with the user auth. I installed the rstudio-server with your formula (thanks for that !!), but then I am not able to login with existing users into the studio. However, when I start the server, the current user is initially logged in. DO you have an idea what is to be fixed in order to get the login working?

      • Randy Lai says:

        I guess you didn’t launch `rstudio-server` as a root user. You should either do the “Launch Daemons” or launch it via `sudo rstudio-server`.

  17. SimonW says:

    Hi, thanks for your tutorial. I’m trying to install RStudio Server on Mac OS X Yosemite and I can see that /Library/LaunchDaemons are now /Library/LaunchAgents. All your code run very smoothly until step 6 for which I got an error “Invalid or missing service identifier”. I know this problem has been previously addressed however I tried to check the contents of /Library/LaunchAgents and everything seems fine:
    sw-MacBook-Pro:~ sw$ ls -hlt /Library/LaunchAgents/org.rstudio.launchd.rserver.plist
    -rw——- 1 root wheel 56B 7 Jul 16:29 /Library/LaunchAgents/org.rstudio.launchd.rserver.plist
    sw-MacBook-Pro:~ sw$ ls /Library/LaunchAgents/org.rstudio.launchd.rserver.plist
    /Library/LaunchAgents/org.rstudio.launchd.rserver.plist

    Any idea what may be wrong?
    Thanks for your help.
    Simon

    • iangow says:

      I’ve found recently that some versions don’t compile. So in after cloning the code, I checkout a particular version (within the `rstudio` directory, I can type `git checkout v0.99.473` … this particular version compiled fine for me).

  18. watdo says:

    This worked great for me. Best rstudio-server install tutorial for Mac OS. I’m on 10.8.5.

    However, I was getting the dreaded “Invalid username/password” issue. After hours and hours of digging and fscking with config I finally cracked it. Turns out the pam auth backend wasn’t configured right. This is listed as an additional step according to the install directions here:

    https://github.com/rstudio/rstudio/blob/master/INSTALL

    I tried copying the default extras/pam/rstudio file to /etc/pam.d but it didn’t work. DL’d, installed, and ran pamtester. Then I just copied the sshd pam config file to rstudio

    cp /etc/pam.d/sshd /etc/pam.d/rstudio

    And it worked!

    just fyi in case somebody else has this issue.

  19. dschneiderch says:

    @watdo ‘s solution didn’t work for me. instead try
    sudo /usr/local/lib/rstudio-server/bin/rserver –auth-minimum-user-id 500

  20. adanis says:

    Hi, thank you very much for posting this great tutorial on how to install RStudio Server. All the steps worked fine for on my Mac (I’m running El Capitan), so it seems that the install worked. Then, I open http://localhost:8787/ in the browser, and enter the credentials of a new user I have created on my Mac. Unfortunately, I get the “Invalid username/password” error message.

    I have already tried the command “cp /etc/pam.d/sshd /etc/pam.d/rstudio”, as suggested by watdo.

    Also, I have tried the command “sudo /usr/local/lib/rstudio-server/bin/rserver –auth-minimum-user-id 500”, as suggested by dschneiderch.

    Unfortunately, none of these fixes worked. I really don’t know what else I can do. Do you have any ideas?

    Thank you very much in advance!

    • iangow says:

      I solved this by changing the ID numbers of the affected users to appropriate values. A bit of work, but feasible. For setting up a completely new user, it might be easier.

      • adanis says:

        Thanks a lot for the quick response! What would be an example of an acceptable value?
        I’m sorry but I’m completely new to RStudio Server.

  21. Hi all,

    Thanks for the tutorial and all useful hints that have been posted here. When trying to build the latest RStudio on El Captain, I also get the infamous username/password error. Unfortunately, none of the solutions posted so far have helped. I ended up going back to v0.99.473, which has been working ok so far .

    However, after upgrading R to v3.3.0 a couple of days ago, I now receive the following message when remotely accessing my machine:

    “Warning messages:
    1: R graphics engine version 11 is not supported by this version of RStudio. The Plots tab will be disabled until a newer version of RStudio is installed.”

    and actually no plot is produced on the window.

    Has anyone successfully used recent versions of RStudio on El Capitain? I wonder if there is any specific revision that does not have the user/pass error?

    It is a pity that RStudio is not officially supported for OS X and, therefore, that we can not get any help from the discussion forums.

    Cheers guys!

    • iangow says:

      I followed the instructions [here](https://www.inteller.net/notes/change-user-id-on-snow-leopard) and changed the affected user’s ID to something over 1000. Then it worked. Clearly this is a pain if you have many affected users.

      The other approach (changing the minimum user ID) did not work for me for some reason.

      • Thanks for the feedback; I much appreciate it.

        I just compiled an updated RStudio and ended up solving the “invalid username” issue. Instead of changing the user ID, I reduced the ID requirements by using the following command: “rstudio-server –auth-minimum-user-id 500”, which I got from here: https://github.com/Homebrew/homebrew-science/issues/3335

        I am now able to connect to my remote machine. Thanks for your hints!

      • iangow says:

        Good to hear. I guess you must be running the Homebrew installation. I’m sticking with MacPorts because it would be too costly to switch for other packages (and they don’t live well together in my experience).

        Note that I actually have a minimal installation of Homebrew consisting of one package (openssl) to address another issue I was having with the MacPorts installation. It seems the path to the Homebrew openssl library is hard-coded in the RStudio installation code.

  22. No, actually I also use MacPorts – I need many packages that are not available on Homebrew. One can confidently follow your tutorial to build the latest RStudio and then just run the command to reduce the username ID requirements. In fact I had to provide the full path to the executable: sudo /usr/local/lib/rstudio-server/bin/rserver –auth-minimum-user-id 500.

    I guess it was just a coincidence that I found the answer on a homebrew Git. It works fine following your tutorial.

    • iangow says:

      Thanks for clarifying. So I guess one could embed this into the /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist file so that it is taken care of when the computer starts.

      • Nice catch – that would probably be a good idea.

      • FYI, I’ve tried this fix as well, but get an error that there are “too many positional arguments” whatever that means, e.g.:

        $ sudo /usr/local/lib/rstudio-server/bin/rserver –auth-minimum-user-id 500
        Password:
        too many positional options have been specified on the command line

        Since I’m new to MacOS X, I’m not sure why that would be occurring.

  23. I am also getting the invalid user error, but when I’ve tried start rserver by re-specifying the auth-minimum-user-id I get and error regarding having too many positional options, e.g.:

    $ sudo /usr/local/lib/rstudio-server/bin/rserver –auth-minimum-user-id 500
    Password:
    too many positional options have been specified on the command line

    Since I’m new to MacOS (have been Ubuntu for the past 10 years), I’m not sure why this is happening.

  24. Just a quick follow-up. Today I updated my studio server and I confirm that the “user id” trick still works. Thus, I’ve updated the /Library/LaunchDaemons/org.rstudio.launchd.rserver.plist file to reflect the addition of the “user id” argument. This is what the updated file looks like:

    Label
    com.rstudio.launchd.rstudio
    ProgramArguments

    /usr/local/lib/rstudio-server/bin/rserver
    –auth-minimum-user-id=500

    RunAtLoad

    Note that I added the “auth minimum user id” argument right after the call to rserver.

  25. thomasgeo says:

    What version of RStudio Server are we actually talking about, free or commercial license?
    At https://support.rstudio.com/hc/en-us/articles/200717203-RStudio-Server-Log-in-and-User-Authentication-Problems it is said that the open-source RStudio Server does not support the PAM Session API.

    I had the problem that I couldn’t login, was playing around with the plist file (as suggested by Thiago) and also with the studio file in PAM.

    Currently my Mac isn’t able to connect to localhost or 127.0.0.1 and I have no idea on how to at least get that fixed.

    I went the way described above to install RStudio Server from source (not using the Homebrew formula of Randy Lai) on El Capitan.

    I created a standard user named studio-server in addition but nothing works.

    Any suggestions on how to get my localhost back, and maybe get RStudio Server to work?

    • iangow says:

      I installed from GitHub last week using my instructions above.

      I think I must have done `v0.99.1269` to check out a specific version to be installed. I used the .plist file linked to below and found that I needed to restart to get things to work.

      igows-mac-pro:rstudio igow$ cd ~/rstudio/
      igows-mac-pro:rstudio igow$ git status
      HEAD detached at v0.99.1269
      nothing to commit, working tree clean

      I used this .plist file.

      • thomasgeo says:

        Beat me…the only thing I did now was to copy the plist file you linked to, and to invoke the last two lines from your instructions above.
        Then I restarted the machine and used the rstudio-server account to login in.

        WORKS! 😀

        Thanks a lot!

  26. vahid says:

    Hi,
    Many thanks for the guidelines. I did all the steps and everything worked smoothly except the last one. I receive the Invalid or missing service identifier error! I used all the suggestions above and none works for me. I am not a computer scientist and I almost know anything about coding. I just copy and paste the scripts :s
    when I checked to see if I can connect to the server or no I receive the error of unable to connect to service! I will enormously appreciate your help to make it work!
    I use a mac pro el capitan machine.

    impatiently look forward to your help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s