How to Install R Packages from CRAN, Bioconductor and GitHub (and Fix Install Errors)
By Dr. Zubair Khalid, DVM, MS, PhD ·

R ships with a small set of base packages, and almost everything useful for modern data analysis lives outside that set. Installing those add-on packages is the first real skill you need in RStudio, because a script that calls library(tidyverse) will fail on any machine where tidyverse was never installed. The three main sources you will meet in a life science lab are CRAN (general purpose packages), Bioconductor (genomics and high-throughput biology), and GitHub (development versions and packages that are not on either repository).
This guide walks through each source in turn, using RStudio's Console. By the end you will be able to install packages from all three, load them correctly, update them after an R upgrade, remove packages you no longer need, and diagnose the handful of errors that account for most failed installs. Commands are written for R 4.6.1 and Bioconductor 3.23, which were current as of October 2026. Check the R download page and bioconductor.org/install for the current releases before you start.
Quick Answer
- CRAN:
install.packages("tidyverse")in the Console, thenlibrary(tidyverse)in each session. - Bioconductor: install BiocManager first, then
BiocManager::install("DESeq2"). Never useinstall.packages()for Bioconductor packages. - GitHub:
install.packages("remotes"), thenremotes::install_github("r-lib/conflicted"). - Install once, load every session.
install.packages()writes files to disk;library()attaches the package for the current session only. - If an install fails, read the first ERROR line above the final message. Missing compilers and leftover lock folders are common causes.
- After upgrading R, run
update.packages(checkBuilt = TRUE, ask = FALSE)so packages built under the old R version are refreshed.
Step 1: Understand What Installing Actually Does
An R package is a folder of code, documentation and sometimes compiled C, C++ or Fortran libraries. install.packages() downloads that folder from a repository and unpacks it into a library directory on your computer [1]. A library is just a folder R searches at startup. library(tidyverse) does something different: it loads an already installed package into the current session and attaches it to the search path [9]. That distinction explains a common beginner error. Installing a package in one session does not make it available in the next session until you call library() again. Installation is permanent; loading is per session.
You can see which libraries R is searching with:
.libPaths()
By default, install.packages() installs into the first library in .libPaths() [1][2]. On a shared lab machine that may be a system library you cannot write to. In interactive use, R notices this and offers to create a personal library instead, using the first element of Sys.getenv("R_LIBS_USER") [2]. Personal libraries are version specific: Linux uses ~/R/x86_64-pc-linux-gnu-library/4.6, macOS uses ~/Library/R/arm64/4.6/library, and Windows uses %LOCALAPPDATA%/R/win-library/4.6 [1]. Those paths are used only if they exist, which is why a fresh R install sometimes has no personal library yet.
Step 2: Install from CRAN
CRAN is the default repository, and install.packages() is the standard way to install from it [1]. Every CRAN package installs the same way:
install.packages("ggplot2")
You can pass several names at once as a character vector:
install.packages(c("ggplot2", "readr"))
Dependencies are handled for you. The dependencies argument defaults to NA, which expands to c("Depends", "Imports", "LinkingTo"), so required packages are installed automatically [2]. That matters because tidyverse, for example, is a meta-package: installing it pulls in the whole collection, and library(tidyverse) attaches nine core packages including dplyr, ggplot2 and tidyr [9]. If you only need plotting, install.packages("ggplot2") is lighter.
Operating systems differ in what they download. Windows looks for binary packages first and offers source packages with compiled code only if make is available. CRAN's macOS builds default to type = "both", meaning binary if available and current, otherwise source. Linux and other Unix-alikes download and install source packages by default [1]. The type argument accepts "source" and "binary" as well, and whether R compiles from source under "both" is controlled by getOption("install.packages.compile.from.source") [2].
If you have a downloaded source tarball and no repository access, set repos = NULL and point at the file:
install.packages("path/to/pkg_1.0.tar.gz", repos = NULL, type = "source")
When installing several source packages, Ncpus sets the number of parallel processes [2].
Step 3: Install from Bioconductor
Bioconductor is an open-source, R-based project of interoperable packages for high-throughput genomic data, with formal package review and continuous automated testing [10]. It releases on its own six-month cycle, separate from R, which is why install.packages() is the wrong tool. Use BiocManager instead [4]:
if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager")
BiocManager::install(version = "3.23")
Bioconductor 3.23 works with R 4.6 [4]. Install specific packages with a character vector:
BiocManager::install(c("GenomicFeatures", "AnnotationDbi"))
Useful checks: BiocManager::version() shows the Bioconductor version in use, BiocManager::available() lists available packages and accepts a pattern such as "^org", and BiocManager::install() with no arguments updates installed packages [4]. BiocManager::valid() reports out_of_date and too_new packages [5]. To move to a different release, pass the version number, or "devel" for the development branch [5]. A Bioconductor release paired with a mismatched R version is not guaranteed to work and is not supported [5]. In practice, updating Bioconductor to a new release usually means upgrading R first, since 3.23 requires R 4.6 [4][5].
Step 4: Install from GitHub
GitHub hosts development versions, unpublished packages and lab-specific tools. The remotes package handles these [6]:
install.packages("remotes")
remotes::install_github("r-lib/conflicted")
You can pin a specific branch, tag or commit with @ref, for example @v2.0.0, point at a subdirectory by adding a path after the repo, or use @*release for the latest release [6]. remotes reads the GITHUB_PAT environment variable as your GitHub personal access token, which helps with private repositories and API rate limits. Packages with compiled code still need build tools [6]. The same package also offers install_bioc() and install_cran() if you prefer one interface.
An alternative is pak, which supports CRAN, Bioconductor and GitHub in a single function, resolves dependencies, downloads in parallel and caches results [7]:
install.packages("pak")
pak::pkg_install("tibble")
pak::pkg_install("tidyverse/tibble")
The first call installs from CRAN; the second, with a slash, installs from GitHub [7].
Step 5: Load, Update and Remove Packages
Loading is per session:
library(tidyverse)
packageVersion("ggplot2")
packageVersion() confirms which version is installed, which is useful when a collaborator reports different behavior. For tidyverse specifically, tidyverse_update() checks for updates [9]. For everything at once, update.packages() finds installed packages with newer versions on your repositories and offers to update them [1]. After upgrading R, add checkBuilt = TRUE so packages built under an older R version are treated as out of date [1]:
update.packages(checkBuilt = TRUE, ask = FALSE)
To uninstall, use remove.packages("pkgname") [1]. Removing a package does not remove its dependencies, so a cleanup after a large install may take several calls.
Step 6: Know When Compilation Is Needed
Compilation tools are required only for source packages containing C, C++, or Fortran code [1]. On Windows that means Rtools, which R finds automatically when installed with its own installer. On macOS you need Xcode Command Line Tools plus matching compilers, and a Fortran compiler for packages that use Fortran [1]. On Ubuntu, anyone compiling R packages from source, including through install.packages(), should also install r-base-dev [3]:
sudo apt-get install r-base-dev
Ubuntu's prebuilt r-cran-* apt packages are updated with Ubuntu releases only, so they lag CRAN. CRAN points Ubuntu users to the r2u project for thousands of CRAN packages as Ubuntu binaries [3]. If you are on Windows or macOS and R asks whether to compile from source because the binary lags a new source release, answering no generally installs the slightly older binary, which is usually the safer choice in a working lab environment.
Worked Example
Run these in the RStudio Console on R 4.6.x. CRAN first:
install.packages("tidyverse")
library(tidyverse)
packageVersion("ggplot2")
Bioconductor next:
if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager")
BiocManager::install(version = "3.23")
BiocManager::install("DESeq2")
library(DESeq2)
BiocManager::valid()
citation("DESeq2")
citation("DESeq2") should return Love MI, Huber W, Anders S (2014) "Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2", Genome Biology 15:550, doi 10.1186/s13059-014-0550-8. That is a good habit to build: citation("pkgname") gives the package citation, and print(citation("pkgname"), bibtex = TRUE) or toBibtex(citation("pkgname")) gives BibTeX [8]. R's documentation asks users to give credit where credit is due [8]. If you need a formatted reference quickly, the site's Citation Generator can help.
GitHub and cleanup:
install.packages("remotes")
remotes::install_github("r-lib/conflicted")
remove.packages("conflicted")
After a later R upgrade:
update.packages(checkBuilt = TRUE, ask = FALSE)
Common Mistakes and How to Fix Them
Error in library(x) : there is no package called 'x': the package is not installed in any library on.libPaths()[1]. Install it, or run.libPaths()to check whether it was installed under a different R version.package 'xyz' is not available (for R version x.y.z): the package is not on the repositories you are using, or not available for your R version [2]. Check spelling, check that yourreposoption points where you think it does, and confirm the package exists for your R version.installation of package had non-zero exit status: the build failed. Scroll up to the first ERROR line, not the last. Missing compilers (Rtools, Xcode Command Line Tools,r-base-dev) are a common documented cause for source packages [1][3].- Leftover
00LOCKerror after an interrupted install: for source installs the library is locked by creating a00LOCKdirectory inside it, which prevents concurrent installs and keeps the previous version to restore on error [2]. Close other R sessions, delete the00LOCKor00LOCK-pkgnamefolder in the library shown by.libPaths(), and reinstall. Alternatively,install.packages("pkg", INSTALL_opts = "--no-lock")skips locking [2]. - Bioconductor package "not available": the name may be misspelled (names are case-sensitive) or the package may not exist for your Bioconductor version. Check
https://bioconductor.org/packages/<version>/<package>[5]. - Multiple BiocVersion installs: call
remove.packages("BiocVersion")repeatedly until all copies are gone, then reinstall [5]. - Large downloads timing out: raise the limit with
options(timeout = 600)[5]. - Package installs but
library()fails in a new session: you installed into a different library than the one R searches at startup. Compare.libPaths()across sessions.
Limitations
Package versions move. R 4.6.1 and Bioconductor 3.23 were current as of October 2026, and Bioconductor's six-month cycle means the next release may appear around October or November 2026. Check bioconductor.org/install before you publish or share code. CRAN binary packages for a new source release can lag, so Windows and macOS users may be prompted to compile from source; declining generally installs the older binary. Bioconductor packages are not guaranteed to work with a mismatched R version, and that combination is not supported [5]. Installing from GitHub gives you whatever state the repository is in, which may be less tested than a CRAN release. Finally, install.packages() cannot fix a broken system toolchain, and no amount of retrying will substitute for a missing compiler.
Frequently Asked Questions
How do I install packages in RStudio?
Open the Console and run install.packages("pkgname") for CRAN packages, BiocManager::install("pkgname") for Bioconductor, or remotes::install_github("user/repo") for GitHub. Then load with library(pkgname) in each session where you need it. RStudio's Packages pane shows what is installed but the Console is the reliable path.
How do I install tidyverse in RStudio?
Run install.packages("tidyverse"), then library(tidyverse). The install pulls in the whole tidyverse, and the library() call attaches nine core packages including dplyr, ggplot2 and tidyr [9]. To check for updates later, run tidyverse_update() [9].
How do I install ggplot2 in R?
install.packages("ggplot2") installs it from CRAN, and library(ggplot2) loads it. If you already installed tidyverse, ggplot2 is present and you can load it directly. Confirm the version with packageVersion("ggplot2").
How do I install Bioconductor in R?
Install BiocManager from CRAN, then use it to install the Bioconductor release: if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") followed by BiocManager::install(version = "3.23") [4]. Individual packages go through BiocManager::install() as well. To update Bioconductor later, you usually need to upgrade R to the matching version first [4][5].
How do I uninstall or update an R package?
remove.packages("pkgname") uninstalls a package [1]. update.packages() checks your repositories for newer versions and offers to update them, and after an R upgrade you should add checkBuilt = TRUE [1]. For Bioconductor packages, BiocManager::install() with no arguments updates installed packages [4].
References
- R Core Team. R Installation and Administration, section 6: Add-on packages (R 4.6.1)
- R documentation: install.packages {utils}
- CRAN: Ubuntu packages for R, full README
- Bioconductor: Install Bioconductor packages
- BiocManager vignette: Installing and Managing Bioconductor Packages
- remotes package documentation
- pak package documentation
- R documentation: citation {utils}
- R for Data Science (2e), Introduction: Prerequisites
- Huber W, et al. Orchestrating high-throughput genomic analysis with Bioconductor. Nat Methods. 2015;12(2):115-121
- Wickham H, et al. Welcome to the Tidyverse. J Open Source Softw. 2019;4(43):1686
Related Articles
- How to Run DESeq2 for Differential Expression Analysis: A Step-by-Step Tutorial in R
- Reproducible Research in R: A Practical Guide for Life Scientists
- How to Perform Gene Ontology (GO) Enrichment Analysis in R: A Step-by-Step Tutorial Using clusterProfiler
- Differential Gene Expression Analysis in R: A Practical Guide
- How to Install R and RStudio on Windows, Mac and Linux
- ggplot2 Tutorial for Beginners: Publication-Ready Plots for Lab Data