Spotlight

Case Study Microsoft

How Microsoft scaled global content delivery

Find out how Microsoft used Gcore to strengthen delivery across regions.

case study ProSieben GNTM app TOPSHOT

How ProSieben scaled GNTM's app TOPSHOT

Explore how ProSieben brought real-time AI portraits to GNTM's audience.

case study Higgsfield

How Higgsfield scaled AI video generation

See how Gcore helped Higgsfield scale with GPUs and Managed Kubernetes.

case study Fawkes Games

How Fawkes Games stopped DDoS attacks

See how Gcore protected gaming servers from massive DDoS threats without disrupting gameplay.

We're hiring

Help build the next chapter of the web

We're not just filling seats. We're building a team that will write the next chapter of the internet.

  1. Home
  2. Learning
  3. How to Install R on Ubuntu

How to Install R on Ubuntu

  • September 1, 2023
  • 3 min read
How to Install R on Ubuntu

If you’re new to Ubuntu, installing R may seem overwhelming. However, with the right guidance, it can be a simple process. R is a widely used language for statistical analysis and data visualization, making it a crucial tool for both data professionals and enthusiasts. Regardless of your level of expertise, this guide offers a straightforward approach to installing R on your Ubuntu system.

What is the R programming language?

R is a programming language and free software environment tailored for statistical computing and graphics. Renowned for its rich ecosystem and versatile applications, R offers the following common features:

  1. Statistical Analysis. Provides extensive tools for regression, hypothesis testing, and data analysis.
  2. Graphics. Capable of producing high-quality and customizable plots and charts.
  3. Package Ecosystem. Over 15,000 packages on the Comprehensive R Archive Network (CRAN) extend R’s capabilities.
  4. Open Source. R is released under the GNU General Public License, meaning it’s free to use, and its codebase can be inspected, modified, and shared.
  5. Integration. R can integrate with many databases, and languages like C, C++, and Fortran. It can also interface with Python, allowing users to harness tools from both languages.
  6. Integrated Development Environments (IDEs). While R can be used from the command line, many users prefer using IDEs like RStudio for a more integrated and user-friendly coding experience.

In essence, R serves as a comprehensive toolkit for data analysis, visualization, and software development. In the next section, let’s take a look at how to set it up on Ubuntu.

Installing R on Ubuntu

Installing R on Ubuntu is a straightforward process, especially with the help of the command line. Here’s a step-by-step guide:

#1 Update System Packages

Before starting, it’s a good idea to update your system packages to their latest versions.

sudo apt updatesudo apt upgrade

The output will be a list of packages will be upgraded. After confirmation, ubuntu will upgrade the packages.

#2 Add R Repository

To ensure you get the latest version of R, add the CRAN repository to your sources list.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

Press Enter to continue. Then, ubuntu will add the CRAN repository to its list of repositories. Here’s a sample output below:

#3 Install R

With the repository added, you can install R.

sudo apt updatesudo apt install r-base

A list of packages that will be installed. Ubuntu will proceed to install R once you give confirmation.

#4 Verify Installation

To check if R was installed successfully, enter the R environment.

R

You will see an introduction message, followed by the R prompt. Exit the R environment by typing q() and pressing Enter.

#5 Optional: Install RStudio

For many, RStudio provides a more user-friendly interface for working with R. To install:

sudo apt install gdebi-corewget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-x.x.x-amd64.debsudo gdebi rstudio-x.x.x-amd64.deb

Ubuntu will install the gdebi-core package first, then download and install RStudio. The version number x.x.x should be replaced with the latest version number from the RStudio website.

Installing R package from CRAN

CRAN, which stands for the Comprehensive R Archive Network, is a network of servers around the world that store identical, up-to-date versions of code and documentation for R, as well as many extensions and related software.

Here’s a step-by-step guide on how to install an R package from CRAN:

#1 Launch R

First, you need to start R. You can do this by typing R in your terminal (for Linux/Unix/Mac) or by opening the R GUI if you’re on Windows.

#2 Use the install.packages Function

Once inside the R environment, use the install.packages function to install your desired package. For example, to install a package named “package_name1”, you’d use:

install.packages("package_name1")

Once you run this command, you’ll likely see a series of messages indicating the download and installation progress. This includes the download location, the unpacking of the package, and any additional dependencies that might also be installed.

#3 Load the Package

After installation, you can use the library function to load the package and start using its functions. Using our earlier example:

library(package_name1)

#4 Optional: Choose a CRAN Mirror

By default, install.packages might ask you to choose a CRAN mirror. This is essentially a server location from where the package will be downloaded. You can manually specify a mirror by using the repos argument:

install.packages("package_name1", repos="https://cloud.r-project.org/")

Choosing the cloud based CRAN mirror as shown above usually provides good speed and reliability.

#5 Verify Installation

To ensure the package has been successfully installed, you can list all installed packages and check if your package is in the list:

installed.packages()[,1]

That’s it, you have successfully installed R on Ubuntu. This powerful tool will enable you to perform statistical analysis and visualize data. With its vast libraries and packages, you can explore data in depth, making it a valuable asset whether you are conducting academic research, professional analysis, or personal projects. Kudos and happy coding!

Conclusion

Want to run Ubuntu in a virtual environment? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Ubuntu:

Choose an instance

Related articles

A glowing orange diagram illustrates data flow from client to edge, then to live processing, emphasizing security.
Running an MCP Server at the Edge

The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context and tools to LLMs. Think of it as a USB-C for AI — a universal interface that lets any LLM client communicate with any tool server witho

Diagram comparing Matchit and Regex for processing web requests, showing Matchit as faster and more efficient.
Routing with Matchit vs RegEx

Choosing the right routing strategy can make a significant difference in your FastEdge application's performance. This guide benchmarks three approaches on WASM.Approach 1: matchitmatchit is a Rust route-recognition library that uses a radi

Diagram showing a centralized KV data store connected to a web browser and global data centers.
Working with Edge KV Storage

This post covers Working with Edge KV Storage — a foundational pattern for stateful edge applications.How It WorksStore and retrieve key-value data at the edge. Perfect for config, feature flags, and session data distributed globally.Edge K

Network diagram illustrating secure data flow from client to edge and live processing.
WebSocket Proxying at the Edge

FastEdge workers aren't limited to just responding to incoming requests — they can also make outbound network requests to external services. This opens up a world of possibilities: aggregating data from multiple APIs, proxying requests to u

Diagram showing edge code securely accessing a secrets vault with authorized access control.
Using Environment Variables and Secrets

Security at the edge means threats are stopped before they reach your infrastructure. By implementing security logic in FastEdge workers, you can validate, filter, and block requests at the closest edge location to the user — providing the

Orange diagram shows data uploading, edge security, and S3 cloud storage.
Upload Files to S3 from the Edge

FastEdge provides distributed edge KV storage that lets you read and write data from any edge location worldwide. Unlike traditional centralized databases, edge KV stores data close to users — reads are served from the nearest PoP, making t

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.