I have R version 3.4.2, trying to install ggplot2, ran install.packages("ggplot2", dependencies = TRUE) in RStudio. It eventually tells me it exited with non-zero exit status and the errors are hard to read because the message is so long, but I see that in the process Matrix was a dependency which also failed to install, so I try to directly install that, and here's what I see in the error message for that:

/usr/bin/ld: cannot find -llapack
/usr/bin/ld: cannot find -lblas
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
/usr/share/R/share/make/shlib.mk:6: recipe for target 'Matrix.so' failed
make: *** [Matrix.so] Error 1
ERROR: compilation failed for package ‘Matrix’
* removing ‘/usr/local/lib/R/site-library/Matrix’

I'm not clear on what ld is at all and if I need to research that to solve this problem. It looks like it might alternately have something to do with Matrix.so.

  • You should not install R-packages system-wide. User per-user folders instead.
    – N0rbert
    Jul 19, 2018 at 8:40
  • @user68186: The answers to the linked duplicate question recommend the installation of r-base-dev among others. This package depends on the packages that provide the development files for the missing libraries. It's a duplicate indeed. Jul 19, 2018 at 16:34
  • Make sure that package is using g++ or gcc and have the same version of fortran installed. gcc --version g++ --version and gfortran --version sudo apt install gfortran-8 My package used gcc. I have version 8.4.0 Jan 13, 2021 at 12:36

1 Answer 1


You need to install these build-dependencies for R-package:

sudo apt-get install r-base-dev

And then install R-packages to your home folder (that is ~/R/x86_64-pc-linux-gnu-library). You do not need to run RStudio as root.

  • 1
    I installed r-base-dev and opened RStudio, then used install.packages and it works! Thanks! I wasn't really clear on how to install the packages to my home folder--I don't see a destination option. But I'm guessing it does this by default? Anyway, since it worked, I'm guessing it's fine.
    – Addem
    Jul 19, 2018 at 14:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.