Skip to content

Instantly share code, notes, and snippets.

@magic-lantern
Created May 18, 2022 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magic-lantern/614218df6ea3510f0e1923a1e132c66b to your computer and use it in GitHub Desktop.
Save magic-lantern/614218df6ea3510f0e1923a1e132c66b to your computer and use it in GitHub Desktop.
How to hold packages from updating on Ubuntu 20.04

How to hold back or keep specific R version on Ubuntu

See https://askubuntu.com/questions/18654/how-to-prevent-updating-of-a-specific-package for additional details on package holding.

You have all system R packages as you want them:

If so, run the following:

apt-mark hold r-base r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-doc-info r-recommended

Or

dpkg --get-selections | grep '^r-' | awk '{print $1}' | xargs apt-mark hold

You don't already have the right version of R packages installed:

If you don't yet have the right versions of all R packages, first check which R packages you have and that you want to remove all of them:

dpkg --get-selections | grep '^r-' | awk '{print $1}' | xargs apt remove --dry-run

If you don't like the list, tweak the grep filter. If everything looks good, run the following:

dpkg --get-selections | grep '^r-' | awk '{print $1}' | xargs apt remove

Verify everything has been removed - you may find some left over configuration files. In my case I needed to:

dpkg --purge r-base-core

Now install the desired version of R packages you want such as:

apt install r-base=4.1.3-1.2004.0 r-base-core=4.1.3-1.2004.0 r-base-dev=4.1.3-1.2004.0 r-base-html=4.1.3-1.2004.0 r-cran-boot=1.3-28-1cran1.2004.0 r-cran-class=7.3-20-1.2004.0 r-cran-cluster=2.1.3-1.2004.0 r-cran-codetools=0.2-18-1cran1.2004.0 r-cran-foreign=0.8.82-1.2004.0 r-cran-kernsmooth=2.23-20-1cran1.2004.0 r-cran-lattice=0.20-45-1.2004.0 r-cran-mass=7.3-56-1.2004.0 r-cran-matrix=1.4-1-1.2004.0 r-cran-mgcv=1.8-40-1cran1.2004.0 r-cran-nlme=3.1.157-1.2004.0 r-cran-nnet=7.3-17-1.2004.0 r-cran-rpart=4.1.16-1.2004.0 r-cran-spatial=7.3-11-2focal0 r-cran-survival=3.2-13-1cran1.2004.0 r-doc-html=4.1.3-1.2004.0 r-doc-info=4.1.3-1.2004.0 r-recommended=4.1.3-1.2004.0

Then mark all R packages as hold:

dpkg --get-selections | grep '^r-' | awk '{print $1}' | xargs apt-mark hold

Or

apt-mark hold r-base r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-doc-info r-recommended

And verify with:

sudo apt-mark showhold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment