• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Install R On Ubuntu

Benjamin O'Donald

Published on: March 10, 2025

Categories: Linux Command Line 0

Table of Contents
  • What is R?
  • How to install R on Ubuntu using the CRAN repository
    • 1. Run an apt upgrade
    • 2. Adding helper packages for the CRAN repository:
    • 3. Add the public signing key for the CRAN repository
    • 3. Add the CRAN repository so we can then install the latest version of R
    • 4. Install R base and its dependencies:
    • 5. Verify the installation of R
  • How to install R using Ubuntu repository
    • 1. Run an apt upgrade
    • 2. Install R base and its dependencies:
    • 3. Verify the installation
  • Installing a package within the R control prompt
    • 1. Launch into the R console prompt
    • 2. Install a package using the install.packages function
  • Installing multiple packages within the R control prompt
  • Finding packages from the CRAN repository
  • Conclusion

What is R?

R is a popular statistical computing programming language commonly used by data scientists and software developers to manipulate data in various use cases.

With the use of R you are able to execute various tasks such as statistical calculations of data, data visualization through graphical sets or even hypothesis testing.

Another excellent aspect of the R programming language is that it is also open source and offers a wide range of packages within its libraries.

Within this article we’ll explain how you can install R on Ubuntu so you can begin to utilize it within your environments.

There are two methods which we will go over such as direct install from the Ubuntu repositories or from the CRAN repository which is slightly more involved but still relatively straightforward.

It is worth noting that using the CRAN repository for the installation of R is typically the best bet as then you can ensure you’re installing the most recent release of R on your Ubuntu machine.

How to install R on Ubuntu using the CRAN repository

As mentioned if we want to obtain the most recent release of R it would be best to install from the CRAN repository which we’ll go over in this section.

1. Run an apt upgrade

First we’re going to make sure all of our software packages are up to date on Ubuntu with the following command (use sudo apt update or upgrade if running as a sudo privileged user):

$ apt upgrade -y

2. Adding helper packages for the CRAN repository:

We will also add the following packages although they are not always needed but can be helpful:

$ apt install software-properties-common dirmngr -y

3. Add the public signing key for the CRAN repository

Now that all of our software packages are up to date we can proceed to add the needed repository so R can be installed.

First we will need to use ‘wget’ to obtain the a public signing key for the CRAN repo:

$ wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

3. Add the CRAN repository so we can then install the latest version of R

Now we can add the needed repository so R can be installed with the following command:

$ add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

If prompted with the below press ENTER to continue:

From the below screen shot we can see the repository was successfully installed so we’re ready to move forward:

4. Install R base and its dependencies:

Now that we’ve updated our Ubuntu system and added the needed repository to obtain the newest version of R we’re now ready to add it to our system.

In the following example we’re going to also add the r-base-dev package so users will be able to utilize a function in the R console to add new packages:

$ apt install r-base r-base-dev -y

This install may take a minute or so to finish but once complete we will be all set and ready to verify.

5. Verify the installation of R

Now we can verify with the following command and pressing ENTER to ensure everything was installed correctly:

$ R

From the below we see we’re launched into a command prompt within the R environment control prompt:

To exit the R control prompt we would just type in the following and press ENTER.

It will ask if we want to save any work completed before exiting which we can enter in Y for yes, N for no, or C for cancel and remain in the console:

Now we have successfully verified our installation of R and its dependencies were a success.

How to install R using Ubuntu repository

On the other hand we can also install R using the Ubuntu repositories and do not necessarily need to add another repo onto Ubuntu in order to do so.

In this example we will be installing R from the Ubuntu repository and it is a pretty straight forward process overall.

Most of the steps are the same except we won’t be needing to add a signing key or repo to our work station for the installation.

1. Run an apt upgrade

Just like in the other method when using the CRAN repository to install R, we’re going to first update our system packages (use sudo apt update or upgrade if running as a sudo privileged user):

$ apt upgrade -y

2. Install R base and its dependencies:

Now that everything is up to date lets install R and its dependencies such as in the other method we mentioned above:

$ apt install r-base r-base-dev -y

3. Verify the installation

Let’s verify everything was installed correctly by launching the R control prompt:

And if we need to exit we can use the following:

Everything appears to be launching correctly per the above after verifying our installation of R and its dependencies so now we can begin using the program.

Installing a package within the R control prompt

In the above two installation methods we also added r-base-dev during our install which allows users to install programs in the R console using this syntax with the following function:

install.packages('name_of_package')

1. Launch into the R console prompt

First we’re going to launch into the R console just by hitting R and pressing enter in our terminal:

2. Install a package using the install.packages function

Now lets say we would like to add the ‘readr’ package. To do so, we would just enter in the following based off our above examples which was:

install.packages('name_of_package')

So to install ‘readr’ we would use the following:

install.packages('readr')

The install may take a minute or so to complete but the above would add that specific package.

Installing multiple packages within the R control prompt

You can also install more than one package at a time using the following syntax with the install.packages function on the R console:

$ install.packages(c('example-package1', 'example-package2', 'example-package3'))

Notice how we’ve introduced the c() function in the above example. This will allow for us to add as many packages at a time that we would like.

Finding packages from the CRAN repository

If you’re unsure of what packages you need for a specific project you can also visit the CRAN Modules page which lists categories of tasks/topics and after selecting one the topics it will list R packages related to that topic.

Conclusion

R is a very popular programming language which allows you to manipulate data in various ways.

Most commonly used by software developer and statisticians, R allows for data visualization, hypothesis testing, and overall data manipulation.

Within this article we explain two methods for installing R on Ubuntu through different repositories.

As we mentioned you can install R using the Ubuntu repositories however if you want to ensure you’re installing the latest release of R it is typically best to install using the CRAN repository.

Related Posts

How to Use zsh Syntax Highlighting

In an earlier post, we discussed the basics of zsh, what it is, and how to get started. Today we’ll look at syntax highlighting in zsh, its meaning, and how to implement it. I’ll also explain why it doesn’t work well with bash, even though we can get it to work in a “hacky” way. […]

How to Prune Unused Images in Docker

In Docker, containers and images can build up over time, using up space and resources. Here's how to get rid of them.

Linux find with exec: + vs ;

The "find" command is often used with the "exec" command. Here are the two options you can use, and the difference between them.

Git Rebase vs Merge vs Cherry-Pick: When to Use Each

Git has many tools for merging branches and commits. Rebasing, merging, and cherry-picking all have their uses.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA