Written and maintained by CASRAI Editorial Board
Last updated
To install an R package from CRAN, run install.packages("name") in the R console, then load it with library(name) in each session that needs it. Packages from Bioconductor go through BiocManager::install(), and packages hosted on GitHub install with pak::pkg_install("owner/repo"). This guide covers all three routes, where the files end up on disk, and why compiled packages sometimes fail to install.
What installing packages is used for in research
Base R ships with a core set of functions; most statistical methods, plotting systems and field-specific tools arrive as add-on packages. Installing a package downloads it once to a library folder on your machine. Loading it with library() is a separate step you repeat each session. Recording which packages and versions an analysis used is a reproducibility matter, covered in the renv guide; for the wider language context see what R is used for.
Install or access (official sources only)
You need R itself first. The R manual “R Installation and Administration” states that for most users calling install.packages() is enough, and that it also fetches the essential dependencies a package declares. An editor such as RStudio is optional; see how to use RStudio or RStudio in the cloud if you prefer a browser.
Step-by-step: install a package from CRAN
- Open R (or the RStudio console).
- Run
install.packages("tibble"), replacingtibblewith the package name. Thepkgsargument is a character vector, so several packages can be installed at once:install.packages(c("tibble", "readr")). - Wait for the download and any dependencies to finish. By default dependencies are the packages listed under Depends, Imports and LinkingTo.
- Load the package in every session where you use it:
library(tibble).
If you call install.packages() with no package names in an interactive session, R shows a list to choose from instead.
Install from Bioconductor
Bioconductor packages are installed through the BiocManager package rather than directly. The Bioconductor install page gives this sequence:
if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager")BiocManager::install(version = "3.23")to set up the release that matches your R. As of 2026-10-29 the page states that Bioconductor 3.23 works with R 4.6.0.BiocManager::install(c("GenomicFeatures", "AnnotationDbi")), replacing the names with the packages you need.
Install from GitHub and other sources
The pak package installs from CRAN, Bioconductor, GitHub, URLs, git repositories, local files and directories. Install pak once with install.packages("pak"), then:
- CRAN:
pak::pkg_install("tibble") - GitHub (owner/repo form):
pak::pkg_install("tidyverse/tibble")
To install from a local file, install.packages() accepts repos = NULL, which installs from local files or URLs instead of a repository. On Unix-alikes, a source package can also be installed from the terminal with R CMD INSTALL.
Where packages are installed
If you do not give a lib argument, packages go into the first directory returned by .libPaths(). Run .libPaths() to see where that is on your machine. If that folder is not writable, then in interactive use R offers to create a personal library, which is the first element of Sys.getenv("R_LIBS_USER"). The R manual notes that on Windows, detecting whether a folder is writable is not always reliable. Library lists in the environment variables R_LIBS_USER and R_LIBS_SITE are separated by colons, or by semicolons on Windows.
Output and how to read it
A successful install prints download and installation messages for the package and any dependencies, and returns you to the prompt. The practical test is whether library(name) runs without an error. A message that a package was installed to a personal library means the system folder was not writable, which is normal on shared machines.
Troubleshooting
Why compiled packages fail to install
Packages containing C, C++ or Fortran code need a toolchain when installed from source. According to the R manual: on Windows, binary packages are preferred when available, and source packages with compiled code need Rtools; on macOS, source packages with C, C++ or Fortran code need matching compilers. Most binary packages with compiled code are tied to an R release series (for example 4.5.x), so after upgrading R to a new series you reinstall them.
The library is not writable
Accept the personal-library prompt in an interactive session, or point lib at a folder you own. Check the result with .libPaths().
A package is “not available”
The package may live on Bioconductor or GitHub rather than CRAN; use the matching route above.
Free alternatives (table)
| Tool | Installs from | Example |
|---|---|---|
install.packages() |
Repositories such as CRAN; local files and URLs with repos = NULL |
install.packages("tibble") |
BiocManager::install() |
Bioconductor | BiocManager::install("AnnotationDbi") |
pak::pkg_install() |
CRAN, Bioconductor, GitHub, URLs, git repositories, local files | pak::pkg_install("tidyverse/tibble") |
R CMD INSTALL |
A source package, from the terminal (Unix-alikes) | See the R manual |
For a wider view of free tools, see the free statistical software guide.
FAQ
Do I need to install a package every time I use R?
No. Install once; run library(name) in each new session.
Can I install several packages at once?
Yes. Pass a character vector: install.packages(c("tibble", "readr")).
How do I install a package that is not on CRAN?
Use BiocManager::install() for Bioconductor or pak::pkg_install("owner/repo") for GitHub.
Sources (official docs)
- R documentation, install.packages (utils package), checked 2026-10-29.
- R Core Team, R Installation and Administration, checked 2026-10-29.
- Bioconductor, Install, checked 2026-10-29.
- CRAN, pak README, checked 2026-10-29.







