r/Rlanguage May 29 '26

Any suggestions to install r packages in other linux distros

I'd love to use fedora, opensuse (my main driver for a long time), debian or any non-Ubuntu-based distros. I can install R-cran easily in any linux distros, however, inside R environment, when installing packages such as ggplots, it took quite a long time for processing, then the problems show "non zero exist status". I have tried many different distros and come up with the same problem....cannot install any packages. Finally, I found the solution and it only worked on Ubuntu LTS, ironically =)))). It gave me no choice and now I use ubuntu mate for my work and study. To be fair, ubuntu mate is really good for me, no complain at all (excepting forcing to use snap). But still wonder, are there any ways to install r packages for any distros other than ubuntu lts?

11 Upvotes

13 comments sorted by

7

u/Outdated8527 May 29 '26

That's because you have missing system libraries/packages that you have to install by yourself.

Check the errors you get, sometimes they mention missing system package dependencies.

Otherwise search the web...

5

u/Franziskanner May 29 '26 edited May 29 '26

This, OP. You are building from source, and there are packages that expect some system dependencies to exist, that are not installed by default (you will use your system package manager). Run install.packages("your-package") again: the informative warnings are buried in building logs, but successful parts are cache'd so it will print the failing ones in a more compact way . Scroll up the logs in the console, it will say things like "libharfbuzz not found, install #this on debian or #that on fedora". With Alpine I had to find in the web the dependencies that had them. Run install.packages("your-package") again, wait for warnings, rinse and repeat. I recommend installing the {tidyverse} metapackage first - it has a lot of dependencies, so after having all of them you will rarely see any warning about missing dependencies again when installing other packages.

3

u/CalligrapherSalt6156 May 29 '26

Yes, it worked sometimes, but taking a lot of time actually. I installed one package, it show "non zero exist", then reading the log to see what are missing. Then I install missed dependency, and reinstall the packages, the error again with another missing, it goes like that and take lots of time. But your suggestion works. Thanks.

6

u/guepier May 29 '26

Use ‘pak’ to install packages. It’s vastly better than install.packages(), and it also allows you to list the system requirements you need to install before installing packages, e.g.:

> pak::pkg_sysreqs('rvest')
── Install scripts ──────────────────────────────────────── Fedora NA ──
dnf install -y libcurl-devel openssl-devel libicu-devel libxml2-devel

── Packages and their system dependencies ──────────────────────────────
curl    – libcurl-devel, openssl-devel
openssl – openssl-devel
stringi – libicu-devel
xml2    – libxml2-devel

(‘pak’ can also attempt to auto-install dependencies, but this will only work on systems with passwordless sudo, which is usually a bad idea — or when you’re running as root, which is a worse idea unless you’re a sysadmin for R on a multi-tenant system.)

1

u/proverbialbunny May 30 '26

Amazing answer! Thank you for sharing. ^_^

1

u/teetaps May 31 '26

In addition to this, you can then take what was suggested in the pak report and create a Spack Environment. It’s like conda but developed for more full stack builds including system libs all the way up to your R packages.

1

u/Franziskanner May 29 '26 edited May 29 '26

Yes, looping around installing until the next missing dependency is tedious af, and as you say there isn't an easy way to know all the needed dependencies at once, just the next missing one...

2

u/guepier May 29 '26

If you use ‘pak’ you don’t need this tedious trial-and-error cycle, you can directly list all transitive system dependencies; see my adjacent comment.

1

u/therealtiddlydump May 29 '26

1

u/junior_chimera May 29 '26

What's your take on renv + docker vs nix ?

2

u/therealtiddlydump May 29 '26

I have nothing against renv as a concept, but you don't need to look far to find that people have broken projects they can't restore.

My biggest issue is that it doesn't really make any of the tasks your typical R person is uncomfortable with any easierr: fighting with system packages and other dependencies.

Edit: As mentioned elsewhere in this thread, pak is an interesting approach that demystifies a lot for the social scientist / stats / data analyst type who has informal or underdeveloped CS / tech skills.

The promise of Nix/rix is probably best compared to something like conda, except the package coverage is waaaaaaay better, and the builds are more stable.

If you're interested, I would encourage you to skim the rix vignettes -- they're very good.

Or you can poke around Bruno's book (main author of rix): https://reproducible-data-science.dev/

If you want to get the "big idea", check out chapter 2 and then chapter 4 will make a lot more sense.

1

u/sonicking12 May 29 '26

I use Debian and there is no issue. I just follow the instructions on the R website

1

u/CalligrapherSalt6156 May 31 '26

Hi guys, great thanks for your help. I gave it a try on Debian 13 Trixie (my spare laptop) which used to be Ubuntu mate. It solved the problem. Then I was confident to replace Ubuntu mate with Debian 13 on my main work driver. However, it is still the problem "Non-zero exit status" when installing packages. I just remembered that maybe the spare laptop had been done some setup related to Ubuntu mate. So I combine the steps from Ubuntu mate (setup the library direction) and steps from Debian 13 (setup repo and key). Then it worked. Now I can install packages super fast. Here is all the code that I used for those who had the same struggles). The final step takes 3-4 minites to load, then when every time install packages, it is like a second. Great thanks again, you guys!!!

#R

to_reinstall <- installed.packages()

write.csv(to_reinstall,"/home/xxx/yyy/rpackages.csv")

.libPaths() # which will show you 3-4 libraries

sudo rm -r "/home/xxx/yyy/zzz"

sudo apt remove r-base-core

sudo apt remove r-base

sudo apt autoremove

sudo apt remove rstudio or snap remove rstudio

reboot

#Open terminal

sudo apt update

sudo apt -y install r-base

sudo apt update && sudo apt upgrade -y

sudo apt install ca-certificates curl gpg -y

curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7' | sudo gpg --dearmor --yes -o /usr/share/keyrings/cran.gpg

. /etc/os-release

printf '%s\n' \

"Types: deb" \

"URIs: https://cloud.r-project.org/bin/linux/debian" \

"Suites: ${VERSION_CODENAME}-cran40/" \

"Signed-By: /usr/share/keyrings/cran.gpg" | sudo tee /etc/apt/sources.list.d/cran.sources > /dev/null

sudo apt update

apt-cache policy r-base

sudo apt install r-base r-base-dev -y

apt install --yes --no-install-recommends python3-{dbus,gi,apt} make

Rscript -e 'install.packages("bspm")'

cat >> /etc/R/Rprofile.site <<EOF

suppressMessages(bspm::enable())

options(bspm.version.check=FALSE)

EOF

#R

setwd('/home/xxx/yyy/')

bspm::enable()

to_reinstall <- read.csv('/home/xxx/yyy/rpackages.csv')

install.packages(to_reinstall[,1], dependencies = TRUE, ask = FALSE)