R Environment Installation
R's development environment itself includes a graphical development environment, which differs from many other engineering languages. Therefore, it is best to install the development environment on an operating system designed for desktop personal computers (such as Windows, macOS, or Ubuntu Desktop).
First, we need to download the R language environment installer:
Windows
- Official Address:https://cloud.r-project.org/bin/windows/base/
- USTC mirror:https://mirrors.ustc.edu.cn/CRAN/bin/windows/base/
- TUNA mirror:https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/base/
Linux
- Official Address:https://cloud.r-project.org/bin/linux/
- USTC mirror:https://mirrors.ustc.edu.cn/CRAN/bin/linux/
- TUNA mirror:https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/linux/
macOS
- Official Address:https://cloud.r-project.org/bin/macosx/
- USTC mirror:https://mirrors.ustc.edu.cn/CRAN/bin/macosx/
- TUNA mirror:https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/macosx/
The versions above may be outdated; if you need the latest version, you can visit:
- Tsinghua University source: https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/
- Official site:https://cloud.r-project.org/bin/
Windows operating system
Installing on Windows is simple: after downloading the installer, double-click it to start the installation wizard:



**Note:** The operating system used here is 64-bit, but a small number of computers still use a 32-bit operating system. If your OS is 32-bit, select the "32-bit User Installation" option at this step.


When we enter the following code in the interactive command window:
print("Hello, world")
The output is:
"Hello, world"
Linux
Ubuntu installation
Run the following command to install the R runtime environment:
# sudo apt update
# sudo apt -y upgrade
# sudo apt -y install r-base
After a successful installation, running the R command brings you to the interactive programming window:

CentOS installation
# sudo yum install R
Enter the following command to view the installed version:
# R --version
You can exit the interactive session by entering q():
> q()
Save workspace image? [y/n/c]: y
macOS Installation
Installing the R language environment on macOS is similar to Windows: download the pkg installer, double-click to open it, and then follow the installation wizard:




After a successful installation, running the R command brings you to the interactive programming window:

You can exit the interactive session by entering q():
> q()
Save workspace image? [y/n/c]: y

Script execution
In R, you can use the Rscript command at the command line to execute R script files.
The Rscript command allows you to run R scripts directly from the command line without opening the R console.
To execute an R script file with the Rscript command, you can follow these steps:
Create an R script file containing the R code to be executed. For example, save the following code as script.R File:
script.R file code:
script.R
x
<-
1
:
10
y
<-
x
^
2
(
y
)
Open a terminal or command line interface and navigate to the directory where the current file script.R is located, then use the Rscript command at the command line to execute the script file:
Rscript script.R
After running the above command, the R script file will be read and executed by the Rscript interpreter.