echo $SHELLLab 1: R, Quarto, RStudio/Positron, Git, SSH Keys, and Reproducing Course Materials
Biostat 203B
This tutorial goes through the process of installing the software environment (R, Quarto, RStudio, Git, SSH) for reproducing 203B course materials.
1 R, Quarto, and RStudio
- Download and install R v4.5.2 or later at https://cran.rstudio.com.
Mac users be aware that R-x.x.x-arm64.pkg is for Apple Silicon CPUs (M1/M2/M3) and R-x.x.x-x86_64.pkg is for Intel CPUs.
Windows users also need to install the Rtools.
Download and install Quarto CLI v1.8.26 or later at https://quarto.org/docs/get-started/.
Download and install RStudio Desktop v2025.09 or later at https://posit.co/download/rstudio-desktop/.
You will thank me for this suggestion. First enable GitHub Copilot in your GitHub account (Student Developer Pack). It may take a couple of days for GitHub to verify your student status. Then in RStudio Desktop, go to Tools -> Global Options... -> Copilot -> Enable GitHub Copilot -> Apply.
In RStudio Desktop, go to Tools -> Global Options... -> General -> Basic tab -> Untick Restore .RData into workspace at startup: and set Save workspace to .RData on exit: to Never.
Adventurous ones are encouraged to try out Positron, which is a free and open-source IDE for R and Python developed by Posit (formerly RStudio). It has built-in support for Quarto and Git. The user interface is similar to RStudio Desktop.
2 Terminal and Bash shell
Open the
Terminalapp. You can findTerminalfromLaunchPad->Other, or fromSpotlight Search(typeTerminal). For convenience, you can pin the Terminal program to the Dock.Check that current shell is Bash
- The default
zshshell on MacOS is mostly compatible with the Bash shell, and can be used interchangeably for this course. If necessary, you can change default shell to Bash by the following command in Terminal. Then close the Terminal window and reopen it.
chsh -s /bin/bashOur first lectures and homework depend heavily on Linux. It is recommended to install the WSL (Windows Subsystem for Linux) program, which is a complete Linux solution for Windows users.
Install WSL2 and create a user account and password for the newly installed Ubuntu following instructions.
A standalone Ubuntu system (v24.04 Noble) is available after WSL installation. Look for icon
.
WSL is a full Linux system. It has its own Linux file system, separate from the Windows file system. The user home is at
/home/[USERNAME]within the Linux file system.Within WSL, it is easy to access the files in Windows file system, which is mounted at
/mnt/con WSL. For example, the file/c/Users/[USERNAME]/filein Windows is available within WSL at/mnt/c/Users/[USERNAME]/file.Within Windows, it is easy to access the files in the WSL file system from the Linux tab in File Explorer.
For Homework 1 (extensive Linux exercises), it is recommended to use RStudio Server within WSL. Follow the instructions here (choose Ubuntu 24) to install R (v4.4.2 at time of writing) and RStudio Server on WSL2 Ubuntu v24.04.
Install Quarto CLI on WSL2 Ubuntu:
wget https://github.com/quarto-dev/quarto-cli/releases/download/v1.8.26/quarto-1.8.26-linux-amd64.deb
sudo gdebi quarto-1.8.26-linux-amd64.deb- In Windows, point your browser to http://localhost:8787 to access RStudio Server. The default username and the password is the same as your Ubuntu login credential.
Occasionally we need to lunch, restart, or stop RStudio Server on WSL2 Ubuntu. The Bash commands are
sudo rstudio-server start
sudo rstudio-server restart
sudo rstudio-server stopDownload and install
Git for Windowsv2.47 or later. Accept the default settings during the installation process.Git Bashprogram is available as a component ofGit for Windows. It provides a basic Bash shell and packages many commonly used Linux programs.Instruct RStudio to use
Git Bashas terminal:Tools->Global Options...->Terminal->New terminals open with->Git Bash.Note that
Git Bashis not a Linux system. It’s a Windows program that emulates a Bash shell, but lacks many Linux commands.Git Bashdoes not have a separate Linux file system. It piggybacks on the Windows file system, thus cannot do Linux-style file permission control. The user home ofGit Bashis same as the user home on Windows, e.g.,/c/Users/[USERNAME].
3 Git and GitHub
- Check whether
gitcommand is available in Terminal.
If git is not available, follow the instructions Installing on macOS section to install it.
git is included in either Git Bash or WSL Ubuntu.
4 SSH and keys
4.1 SSH client
SSH client should be available in Terminal (Mac Terminal, Windows Git Bash, or Windows WSL) by default.
In Terminal, the command to connect to a Linux machine is
ssh [USERNAME]@[IP_ADDRESS]Replace [USERNAME] in the command by your actual user name on the Linux machine you are connecting to. If you cannot connect, you may not have an account. For example, to connect to my account on the Hoffman2 cluster at UCLA
ssh huazhou@hoffman2.idre.ucla.edu4.2 SSH keys
- First check whether you already have keys on your local machine. If you don’t have
~/.sshfolder, that means you have never used SSH before.
ls -al ~/.ssh- If no SSH keys yet, generate a pair of RSA keys
- Method 1: Use RStudio to generate keys.
Tools->Global Options...->Git/SVN->Create SSH Key. - Method 2: Generate keys on Terminal, following the instructions in lecture notes.
~/.ssh/ - Method 1: Use RStudio to generate keys.
Make sure the permission for the key files are correct.
The permission for the
~/.sshfolder should be700 (drwx------).The permission for the private key
~/.ssh/id_rsashould be600 (-rw-------).The permission for the public key
~/.ssh/id_rsa.pubshould be644 (-rw-r--r--).
The permission for the
~/.sshfolder should be700 (drwx------).The permission for the private key
~/.ssh/id_rsashould be600 (-rw-------).The permission for the public key
~/.ssh/id_rsa.pubshould be644 (-rw-r--r--).
The permission for the
~/.sshfolder can be755 (drwxr-xr-x).The permission for the private key
~/.ssh/id_rsacan be644 (-rw-r--r--).The permission for the public key
~/.ssh/id_rsa.pubcan be644 (-rw-r--r--).
- Upload the public SSH key to GitHub.com: Click the user Avatar on top right corner ->
Settings->SSH and GPG keys->New SSH key.
In your local machine terminal, you may copy the public key to the clipboard by following command.
pbcopy ~/.ssh/id_rsa.pubclip < ~/.ssh/id_rsa.pubIf the xclip and xsel are installed, then we can use
xclip -selection clipboard ~/.ssh/id_rsa.pubOn local machine, instruct RStudio to use the public key just generated:
Tools->Global Options...->Git/SVN->SSH key:.After setting up SSH key, you can
git pushyour local commits to GitHub repo seamlessly without passwords.
5 Obtain and reproduce course materials
You can use RStudio to git clone the https://github.com/ucla-biostat-203b/2026winter repository to your local machine: File -> New Project... -> Version Control -> Git -> input Repository URL:, Project directory name: 203b-lecture.
In RStudio, navigate to the slides folder, open and render qmd files.
- In Terminal (Mac Terminal, Windows WSL, or Windows Git Bash), you can
git clonea copy of course materials by
git clone git@github.com:ucla-biostat-203b/2026winter.git ~/203b-lectureThis command clones the GitHub repository to a folder called 203b-lecture under your home directory. You can clone multiple copies to different locations on the same machine if you want. Since this GitHub repository is frequently updated, we frequently sync the local copy on your computer with the repository on GitHub by running
git pullwithin the 203b-lecture folder.
Navigate to the
203b-lecturefolder, double click the2026winter.Rprojfile to open the project in RStudio. Within RStudio, you can navigate to theslidesfolder to open and renderqmdfiles.The first time you install R packages in Ubuntu, there might be lots of error messages. This is due to lack of some system dependencies. Read the error messages carefully, and install the missing Ubuntu packages, e.g.,
sudo apt-get install build-essentialto install the GCC compiler.
6 Docker and Hoffman2
There are more ways to run the course materials.
You can use Docker to run the course materials on your local machine. See Lab 3 for instructions.
You can also use Hoffman2 cluster at UCLA to run the course materials. See Hoffman2 documentation for instructions.
Please note this RStudio Server container image lacks many tools such as SSH and Quarto. You need to install them by yourself.