In this article, we will see how to install rterm or r terminal on Ubuntu or Debian based linux system. R terminal, often referred to as Rterm, is a command-line interface used for running the R programming environment. It provides a text-based way to interact with R, allowing users to execute R commands and scripts directly from a command-line shell. When you start Rterm, you enter an interactive environment specifically designed for statistical computing and graphics in R.
In Rterm, users can perform a variety of tasks such as data analysis, running statistical models, creating plots, and writing and executing R scripts. It's a powerful tool for users who prefer working in a command-line interface or who are running R on a remote server or in an environment where a graphical user interface is not available. Here we will see how to install Rterm (R terminal) on Ubuntu or Debian. You may also like How to Install R Programming on Ubuntu 20.04 LTS (Focal Fossa).
How to Install Rterm (R terminal) on Ubuntu or Debian
Also Read: How to Install add-apt-repository on Ubuntu 22.04
Step 1: Prerequisites
a) You should have a running Ubuntu
or Debian
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility available in your Server.
Step 2: Update Your Server
It is always recommended to install all the latest security patches and updates available from default Ubuntu repo using sudo apt update && sudo apt upgrade
command before installing any new packages in the system.
itsfosslinux@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for itsfosslinux:
Hit:1 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Hit:4 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:5 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
Hit:6 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Ign:7 https://pkg.jenkins.io/debian-stable binary/ InRelease
Hit:8 https://pkg.jenkins.io/debian-stable binary/ Release
Hit:9 https://dl.google.com/linux/chrome/deb stable InRelease
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:11 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease
...................................................
Step 3: Install Rterm
In the next step, you can install rterm by using sudo apt install r-base
command as shown below. This will download and install the package along with all its dependencies from default ubuntu repo.
itsfosslinux@ubuntu:~$ sudo apt install r-base Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: bzip2-doc gfortran gfortran-9 libblas-dev libblas3 libbz2-dev libgfortran-9-dev libgfortran5 liblapack-dev liblapack3 liblzma-dev libncurses-dev libncurses5-dev libreadline-dev libtcl8.6 libtk8.6 r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-recommended Suggested packages: gfortran-multilib gfortran-doc gfortran-9-multilib gfortran-9-doc libcoarrays-dev liblapack-doc liblzma-doc ncurses-doc readline-doc tcl8.6 tk8.6 elpa-ess r-doc-info | r-doc-pdf r-mathlib texlive-base texlive-latex-base texlive-plain-generic texlive-fonts-recommended texlive-fonts-extra texlive-extra-utils texlive-latex-recommended texlive-latex-extra texinfo The following NEW packages will be installed: bzip2-doc gfortran gfortran-9 libblas-dev libblas3 libbz2-dev libgfortran-9-dev libgfortran5 liblapack-dev liblapack3 liblzma-dev libncurses-dev libncurses5-dev libreadline-dev libtcl8.6 libtk8.6 r-base r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-recommended 0 upgraded, 37 newly installed, 0 to remove and 2 not upgraded. Need to get 64.6 MB of archives. After this operation, 151 MB of additional disk space will be used. Do you want to continue? [Y/n] y ....................................................
Step 4: Check Version
After successful installation, you can check R terminal version by using R --version
command as shown below.
itsfosslinux@ubuntu:~$ R --version R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/.
Step 5: Launch Rterm
Then to launch terminal, you just have to type sudo R
as shown below. It will launch the terminal and give you a prompt to enter commands to perform an operation.
itsfosslinux@ubuntu:~$ sudo R R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
Step 6: Install a package
Now that R terminal is launched, let's install a package through this terminal using install.packages(<package_name>)
command. For example, here we are installing a package called readxl
using install.packages("readxl")
command as shown below.
> install.packages("readxl")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘cli’, ‘glue’, ‘utf8’, ‘rematch’, ‘fansi’, ‘lifecycle’, ‘magrittr’, ‘pillar’, ‘pkgconfig’, ‘rlang’, ‘vctrs’, ‘crayon’, ‘hms’, ‘prettyunits’, ‘R6’, ‘cellranger’, ‘tibble’, ‘cpp11’, ‘progress’
trying URL 'https://cloud.r-project.org/src/contrib/cli_3.6.2.tar.gz'
Content type 'application/x-gzip' length 569771 bytes (556 KB)
==================================================
downloaded 556 KB
trying URL 'https://cloud.r-project.org/src/contrib/glue_1.6.2.tar.gz'
Content type 'application/x-gzip' length 106510 bytes (104 KB)
==================================================
downloaded 104 KB
trying URL 'https://cloud.r-project.org/src/contrib/utf8_1.2.4.tar.gz'
Content type 'application/x-gzip' length 241081 bytes (235 KB)
==================================================
downloaded 235 KB
trying URL 'https://cloud.r-project.org/src/contrib/rematch_2.0.0.tar.gz'
Content type 'application/x-gzip' length 4781 bytes
==================================================
downloaded 4781 bytes
..................................................
Step 7: Remove a package
Similarly, if you want to remove a package then you have to use remove.packages("<package_name>")
command. For example, here we are removing a package called readxl
using remove.packages("readxl")
command as shown below.
> remove.packages("readxl") Removing package from ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified)
Step 8: Exit Rterm
To exit R terminal, you have to use q()
command as shown below. If you want to save the workspace then press y
to save and exit.
> q() Save workspace image? [y/n/c]: y itsfosslinux@ubuntu:~$
Step 9: Check all available options
If you are looking to check all the options available with R command then you have to use R --help
command as shown below.
itsfosslinux@ubuntu:~$ R --help
Usage: R [options] [< infile] [> outfile]
or: R CMD command [arguments]
Start R, a system for statistical computation and graphics, with the
specified options, or invoke an R tool via the 'R CMD' interface.
Options:
-h, --help Print short help message and exit
--version Print version info and exit
--encoding=ENC Specify encoding to be used for stdin
--encoding ENC
RHOME Print path to R home directory and exit
--save Do save workspace at the end of the session
--no-save Don't save it
--no-environ Don't read the site and user environment files
--no-site-file Don't read the site-wide Rprofile
--no-init-file Don't read the user R profile
--restore Do restore previously saved objects at startup
--no-restore-data Don't restore previously saved objects
..................................................
Step 10: Uninstall Rterm
If you are looking to r terminal from your system then you have to run sudo apt remove r-base
command as shown below. If you are looking to remove all dependent packages as well then you have to use --auto-remove
option with below command.
itsfosslinux@ubuntu:~$ sudo apt remove r-base Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libblas-dev libblas3 libbz2-dev liblapack-dev liblapack3 liblzma-dev libncurses-dev libncurses5-dev libreadline-dev libtcl8.6 libtk8.6 r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-recommended Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: r-base 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 62.5 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 275385 files and directories currently installed.) Removing r-base (3.6.3-2) ...