How to install R on Ubuntu 22.04

R is an open-source, free environment and programming language that is primarily utilized to analyze data and perform statistical calculations. This language offers various graphical and statistical methodologies that comprises classical statistical tests, time series analysis, and linear/non-linear modeling. R language also supports a lot of user-generated packages for specific areas of interest. That’s another reason why the R language is more applicable to multiple fields.

This blog will demonstrate the method to install the R language in Ubuntu 22.04. So, let’s start!

Installing R programming language on Ubuntu 22.04

For the purpose of R programming language installation on Ubuntu 22.04, follow the below-given instructions.

Step 1: Update and Upgrade the Ubuntu 22.04

To update and upgrade packages on Ubuntu 22.04, firstly, open up the terminal by pressing “CTRL+ALT+T” and execute the following command:

$ sudo apt update

Now, upgrade the system packages with the help of the following command:

$ sudo apt upgrade

Step 2: Add dependencies

Now, on your Ubuntu 22.04 system, download and install required dependencies. These dependencies are used to execute the R on Ubuntu 22.04. Run the following command for the specified purpose:

$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

Now, move to the next instruction.

Step 3: Authenticate the packages

Authenticate the installed packages by writing out the following command:

$ sudo apt-key adv --keyserver --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

Step 4: Import GPG key

Next, import the GPG key in your system through below command:

$ wget -O- | sudo gpg --dearmor | sudo tee /usr/share/keyrings/cran.gpg

Step 5: Add CRAN repository

After importing the GPG key, you need to add the CRAN repository that is highly recommended for R installation:

$ echo deb [signed-by=/usr/share/keyrings/cran.gpg] $(lsb_release -cs)-cran40/ | sudo tee /etc/apt/sources.list.d/cran.list

Once the repository is imported, refresh the APT repository list by using the update command:

$ sudo apt update

Step 6: Install R through CRAN repository

Now, your Ubuntu 22.04 system is ready to install the R language from the CRAN repository. To do so, type the following command:

$ sudo apt install r-base

Now “R” exists on our Ubuntu 22.04 system.

Step 7: Check R version

After installing the R language on Ubuntu 22.04, verify its existence by checking the build version:

$ R --version

The below-given output signifies that we have successfully installed R version “4.2.0” on our system:

Step 8: Run R

Next, run the R environment first by using “R” command in the terminal:

$ sudo R

After executing the “Rcommand, the R environment will be activated in the current terminal. You can also separately activate and use the R environment by searching it manually in the “Applications” menu:

Step 9: Terminate R

After using the R language, you want to terminate the activated shell environment. To do so,use the “q()” command and press “y” from your keyboard:


How to remove R from Ubuntu 22.04

You can remove “R” from your Ubuntu 22.04 system by utilizing the given-below command:

$ sudo apt-get remove r-base

That was all essential information related to the procedure of installing the R language on Ubuntu 22.04. You can further explore as required.


To install the R language on Ubuntu 22.04, firstly, update your system packages. Then, install the required packages and authenticate them. Next, import the GPG key and after that, add the CRAN repository to Ubuntu 22.04. Lastly, execute the “$ sudo apt install r-base” command for the installation of the R language and check the installed version with the “$ R –version” command. This blog demonstrated the method to install R on Ubuntu 22.04.