Cannot install any package

Hi all,

I just installed Rstudio on Ubuntu 20.04 by following these instructions: https://linuxconfig.org/how-to-install-rstudio-on-ubuntu-20-04-focal-fossa-linux

However, I do not seem to be able to install any packages. I keep getting the following error, which seems to have something to do with pyenv and anaconda (I am mainly a python user). This doesn't make much sense to me. Can anyone help?

This is the error I get when I run install.packages("learnr"). It is very similar if I try installing any other package.

> install.packages("learnr")
Installing package into ‘/home/brendan/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
also installing the dependency ‘rappdirs’

trying URL 'https://cloud.r-project.org/src/contrib/rappdirs_0.3.3.tar.gz'
Content type 'application/x-gzip' length 12288 bytes (12 KB)
==================================================
downloaded 12 KB

trying URL 'https://cloud.r-project.org/src/contrib/learnr_0.10.1.tar.gz'
Content type 'application/x-gzip' length 1787789 bytes (1.7 MB)
==================================================
downloaded 1.7 MB

* installing *source* package ‘rappdirs’ ...
** package ‘rappdirs’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-jbaK_j/r-base-3.6.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-jbaK_j/r-base-3.6.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c win-path.c -o win-path.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o rappdirs.so init.o win-path.o -L/usr/lib/R/lib -lR
installing to /home/brendan/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-rappdirs/00new/rappdirs/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
pyenv: patchelf: command not found

The `patchelf' command exists in these Python versions:
  anaconda3-2020.02

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.
Error in system(paste("patchelf --print-rpath", shQuote(l)), intern = TRUE) : 
  error in running command
* removing ‘/home/brendan/R/x86_64-pc-linux-gnu-library/3.6/rappdirs’
Warning in install.packages :
  installation of package ‘rappdirs’ had non-zero exit status
ERROR: dependency ‘rappdirs’ is not available for package ‘learnr’
* removing ‘/home/brendan/R/x86_64-pc-linux-gnu-library/3.6/learnr’
Warning in install.packages :
  installation of package ‘learnr’ had non-zero exit status

Thank you in advance!

I am basically guessing but it looks like you need either to install Python or upgrade your version of it.

I have Python 3.9.5 installed on my Ubuntu 25.04.

Hi, thanks for the reply!

I do have python installed (version 3.7.3) through anaconda.

I am a bit unclear on why it would be necessary to have a specific version of python installed (or any version of python, for that matter) in order to install packages in Rstudio? Is this a documented dependency?

I am not sure if is but in some cases either R or RStudio may be calling on a function in Python or C++ (?) etc that did not exist in an order version.

Probably somewhere but outside the developers environment I don't know where .

Can you run R in a terminal? If so, try

install.packages("learnr") 

in the terminal.

If that does not work we may have a write permission problem on the directory.

It did work! However, it appears that I have two versions of R on my system, one in '/home/brendan/anaconda3/lib/R' and one in '/home/brendan/R'. The terminal has successfully installed the package into the anaconda installation, whereas Rstudio is trying to install to the latter and failing for some reason.

Is there any way I can tell Rstudio to use the other installation of R on my system?

Yes but it's beyond my knowledge. I'd suggest starting a new question. I have never dealt with anaconda (snake phobia) so I have no idea what it does.

It is possible that you have a write permission problem with '/home/brendan/R'. You might want to try saving something to '/home/brendan/R' and see what happens.

Good luck.

I looked into it, and it appears that using the anaconda installation of R would require installing Rstudio through anaconda, and using anaconda to manage packages. I would prefer to use a standalone installation of Rstudio, as opposed to through anaconda.

I tried running install.packages("learnr) through the terminal with the '/home/brendan/R' installation, and I get the same error as above.

I did try creating a dummy file in '/home/brendan/R', and had no issues.

Blast.

Beyond my level of competence. Personally I'd purge both versions of R and Rstudio and reinstall everything without using anaconda but that may be a bit drastic.