How to get RStudio IDE to use the correct terminal path in Mac OS X?

I am using a MacBook Pro with Apple silicon. To take advantage of the programs that can use this natively, homebrew creates a new directory (/opt/homebrew) that is functionally the same as /usr/local except that it holds the packages that are native to R rewritten for Apple silicon.

Thus, in Terminal in Mac OS X, echo $PATH correctly returns

/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

And I am able to use installed homebrew commands from the Terminal in Mac OS X.

But in RStudio IDE, system("echo $PATH") returns

usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/RStudio.app/Contents/MacOS

Note the missing "/opt/homebrew/bin:/opt/homebrew/sbin".

The same issue occurs if I open a new terminal window in RStudio IDE (Note: different than Terminal in Mac OS X) and type echo $PATH (the homebrew directories are missing.)

How do I permanently modify the PATH that RStudio uses to add "/opt/homebrew/bin:/opt/homebrew/sbin"?

Thank you!

(Please don't refer me to random StackOverflow articles—I have been through them and none of those options work. The RStudio application apparently does not look to the .bash_profile or the .zshrc profile when setting PATH. I even tried editing the Info.plist in RStudio.app directory to set the PATH there, but that did not work either.)

I'm having exactly same issue, went through the entire internet, no solutions so far. It's quite inconvenient since R packages need to be compiled on M1 - but this will throw an error if a package requires other tools installed via homebrew (e.g. cmake or libpng). So far I've resorted to launching rstudio from terminal ("open -na rstudio") which makes it inherit $PATH from zsh.

I've found that the advice about 1/3 of the way down on Transitioning from x86 to arm64 on macOS - experiences of an R user worked for me.

In short:

  1. In R, install package startup
  2. In a terminal:
mkdir -p ~/.Renviron.d/sysname=Darwin,machine=arm64
cd ~/.Renviron.d/sysname=Darwin,machine=arm64
echo 'PATH="/opt/homebrew/bin:/opt/homebrew/sbin:${PATH}"' > path
  1. Add
startup::startup()

to the file ~/.Rprofile

The result in Rstudio:

system("echo $PATH")
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Little Snitch.app/Contents/Components:/opt/X11/bin:/Applications/RStudio.app/Contents/MacOS/postback
1 Like

Great resource, thanks for sharing! Wish I'd stumbled on that article much earlier, would've saved me plenty of suffering when configuring gfortran.

I managed to solve the issue a bit differently, admittedly covered in Homebrew FAQ, by running:

 sudo launchctl config user path "${PATH}"

After rebooting, RStudio now uses same $PATH as my zsh. As a side note, turns out I didn't need to compile most of the packages, most of my issues stemmed from the fact that I used Homebrew-compiled version (brew install r) which is incompatible with CRAN binaries..

After reinstalling R with brew install --cask r I can use binaries.

Seems related to RStudio uses different path to application (e.g., `rsync`, `ffmpeg`, ...) · Issue #10551 · rstudio/rstudio · GitHub which we're looking at improving for next release (Spotted Wakerobin)

Apologies for this, this does appear to be a bug on RStudio Desktop for Mac, and we are actively working on a fix but do not have resolution yet. I suggest to follow the linked Github issue above, and keep an eye out for subsequent RStudio releases for a long-term fix. However, in the meantime, a temporary workaround is to create or modify the ~/.Renviron file, setting PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Little Snitch.app/Contents/Components:/opt/X11/bin:/Applications/RStudio.app/Contents/MacOS/postback" or whatever the desired value of your PATH variable should be. The PATH should show correctly if you run R directly from your Terminal, and so you can run Sys.getenv("PATH") in R directly (not RStudio) to get the desired value of the PATH to paste into your ~/.Renviron file. We are working to resolve this issue.

Another temporary workaround that should work in the meantime -- if you double click the RStudio app icon to open the application, it will load with the incorrect PATH variable. If however, you launch RStudio from your Terminal (open /Applications/RStudio.app) the PATH variable should be correct when running Sys.getenv("PATH") in your RStudio console. Again, you can save that PATH to your ~/.Renviron file if you don't want to have to remember to launch from the terminal each time. We hope this workaround helps until a fix is released.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.