Perhaps a more accurate title would be: "How to switch from in-place (EPEL) R to side-by-side (version-specific) R installation on Linux (Red Hat/CentOS)?
A (possibly typical) upgrading R on Linux story...
History:
At some point in the past, I updated the version of R on our RHEL/CentOS 7 server using the default version pulled down by the yum package manager at that time. For example, sudo yum install R to version 3.5.2 at some point in early 2019. By default, this installs R at /usr/lib64/R for all users and completely replaces the 3.4.x version that had previously been installed there. Shiny Server was already installed, configured to run as user shiny, and it picked up the new version of R without a hitch.
Situation:
A year later, it is now time to bite the bullet and update the version of R that is running on the Linux server. Running yum check-upgrade R I find that the version available is 3.6.0. I actually want to install 3.6.3 AND I don't want to break all of my apps that are running on 3.5.2, so I need to use a different method. Following the instructions found at https://docs.rstudio.com/resources/install-r/, I download the 3.6.3 .rpm file and install it. By default, this installs R at /opt/R/3.6.3/, leaving the 3.5.2 version as is. However, as soon as I complete the Create a symlink to R step, none of my shiny apps work:
sudo ln -s /opt/R/3.6.3/bin/R /usr/local/bin/R
sudo ln -s /opt/R/3.6.3/bin/Rscript /usr/local/bin/Rscript
This should not be surprising. My shiny apps all rely upon several R packages that have not yet been installed for this new version of R. I can quickly get my apps working again on the previous version (3.5.2) by removing these symlinks until after I've installed the necessary packages in the new version:
sudo rm /usr/local/bin/R
sudo rm /usr/local/bin/Rscript
Error messages in my shiny app log files (at /var/log/shiny-server/<app name>-<user>-<datetime>.log) confirm that the apps had failed to launch due to missing packages. To update the R packages in the shared library folder, I need to run the new version of R as sudo: sudo -i /opt/R/3.6.3/bin/R and install the necessary packages, e.g., install.packages(c("shiny","devtools","rmarkdown","shinydashboard","tidyverse")) in R.
Now that the R packages are installed, I can re-create the symlinks:
sudo ln -s /opt/R/3.6.3/bin/R /usr/local/bin/R
sudo ln -s /opt/R/3.6.3/bin/Rscript /usr/local/bin/Rscript
I verify that my apps are working with the new version of R.
Now I have some questions:
Question 1: After completing these steps, R --version still returns the old version (3.5.2). But when I logged back in the following day, it opens 3.6.3. Why? Do I need to run a terminal command to get R --version to return the new version immediately or is opening a new terminal window the only way to achieve this?
Question 2: Running sudo R --version always returns the old version (3.5.2). Running sudo which R returns /bin/R. Running more /bin/R reveals contents which state that it is "Shell wrapper for R executable." and has the "/usr/lib64/R" path hard-coded. I don't think I need this wrapper at this point. What is the recommended way to get these sudo commands to point to the new version?
I can make a backup copy of this file in my home directory (e.g., cp /bin/R ~/binR.backup) just in case, and then:
- Delete /bin/R?
- Replace /bin/R with a symlink to the new version (e.g.,
sudo ln -s /opt/R/3.6.3/bin/R /bin/R)? - Re-install the 'old' version into
/opt/R/3.5.2/using a .rpm the same way I installed 3.6.3, install packages there, and then remove the/usr/lib64/Rversion (e.g.,sudo yum remove R)?
Links to similar questions that I looked at but didn't answer my questions: