Question

How to upgrade R on ubuntu 20.04 server to latest version along with all packages.

There is no help I can find on how to upgrade R from 4.0 to 4.2 on DO Ubuntu 20.04? The important thing is my existing code and packages should not break. What is a good approach?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @sanjmeh,

There is never a 100% guarantee something won’t break when you update your server. Having said that, what could help is creating a backup prior to beginning the process. That way you can always revert back to a previous state. For this, I’ll recommend using the Snapshot product:

https://docs.digitalocean.com/products/images/snapshots/

As for the upgrade, you can try the following:

  1. # update indices
  2. sudo apt update -qq
  3. # install two helper packages we need
  4. sudo apt install --no-install-recommends software-properties-common dirmngr
  5. # add the signing key (by Michael Rutter) for these repos
  6. # To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
  7. # Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9
  8. wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
  9. # add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
  10. sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

If there are any problems you can’t solve after the update, you can now always revert back to the previous option with the Snapshot image you created.

Hi there,

There can’t really be any guarantees if your code will work with the newer version of R. What I would suggest is to make sure to take a backup of your Droplet before proceeding with the upgrade:

https://docs.digitalocean.com/products/images/backups/

That way you can revert to a working version in case that anything goes wrong.

Regarding the upgrade itself, I could suggest following the official R installation guide:

# update indices
sudo apt update -qq
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc 
# Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

Best,

Bobby