Ubuntu

Installation notes

If you have already installed Git, LaTeX, or any of the R packages, you should be OK. However, if you have difficulty with Homework or Labs, we may ask you to uninstall and try again.

In order to be able to support you effectively and minimize setup issues and software conflicts, we suggest you install the required software as specified below.

Ubuntu software settings

To ensure that you are installing the right version of the software in this guide, open “Software & Updates” and make sure that the boxes in the screenshot are checked (this is the default configuration).

GitHub

In Stat 406 we will use the publicly available GitHub.com. If you do not already have an account, please sign up for one at GitHub.com

Sign up for a free account at GitHub.com if you don’t have one already.

Git

We will be using the command line version of Git as well as Git through RStudio. Some of the Git commands we will use are only available since Git 2.23, so if your Git is older than this version, so if your Git is older than this version, we ask you to update it using the following commands:

sudo apt update
sudo apt install git

You can check your git version with the following command:

git --version
Note

If you run into trouble, please see the Install Git Linux section from Happy Git and GitHub for the useR for additional help or strategies for Git installation.

Configuring Git user info

Next, we need to configure Git by telling it your name and email. To do this, type the following into the terminal (replacing Jane Doe and janedoe@example.com, with your name and email that you used to sign up for GitHub, respectively):

git config --global user.name "Jane Doe"
git config --global user.email janedoe@example.com
Note

To ensure that you haven’t made a typo in any of the above, you can view your global Git configurations by either opening the configuration file in a text editor (e.g. via the command nano ~/.gitconfig) or by typing git config --list --global).

If you have never used Git before, we recommend also setting the default editor:

git config --global core.editor nano

If you prefer VScode (and know how to set it up) or something else, feel free.

R, XQuartz, and RStudio

R is the only language that we will be using in this course. We will generally (always?) use R in RStudio.

R

The version of R available in the default Ubuntu repositories is older than the one we will be using in this course. To obtain the latest R packages, we need to add a new repository which is maintained directly by the r-project. To do this, first add the key for this repository by typing the following:

wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Then add the URL to the repository:

sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

Next, install r-base and r-base-dev (useful for compiling R packages from source):

sudo apt install r-base r-base-dev

After installation, type the following in a new terminal window:

R --version

You should see something like this if you were successful:

R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin23.4.0

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.
Note

See this page for additional instructions if you run into trouble while installing R.

Although it is possible to install R through conda, we highly recommend not doing so. In case you have already installed R using conda you can remove it by executing conda uninstall r-base.

Important

This course requires R version 4.2 or higher. You may need to update.

The course package will error on install if this is not the case.

RStudio

Download the Ubuntu 18/Debian 10 Desktop version (not Pro) of RStudio Preview from https://posit.co/download/rstudio-desktop/. Open the file and follow the installer instructions.

Installing R packages

The tidyverse R package (and some others) have external dependencies on Ubuntu outside of R. We need to install these first before we install such R packages:

sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev

Next, install the key R packages needed for the course by opening up RStudio and typing the following into the R console inside RStudio:

install.packages("remotes")
remotes::install_github("ubc-stat/stat-406-rpackage", dependencies = TRUE)

With luck, that will install everything you need.

LaTeX

It is possible you already have this installed.

First try the following check in RStudio

Stat406::test_latex_installation()

If you see Green checkmarks, then you’re good.

Even if it fails, follow the instructions, and try it again.

If it still fails, proceed with the instructions


We will install the lightest possible version of LaTeX and its necessary packages as possible so that we can render Jupyter notebooks and R Markdown documents to html and PDF. If you have previously installed LaTeX, please uninstall it before proceeding with these instructions.

First, run the following command to make sure that /usr/local/bin is writable:

sudo chown -R $(whoami):admin /usr/local/bin
Note

You might be asked to enter your password during installation.

Now open RStudio and run the following commands to install the tinytex package and setup tinytex:

tinytex::install_tinytex()

You can check that the installation is working by opening a terminal and asking for the version of latex:

latex --version

You should see something like this if you were successful:

pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2022/dev)
kpathsea version 6.3.4/dev
Copyright 2021 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.03

Github PAT

You’re probably familiar with 2-factor authentication for your UBC account or other accounts which is a very secure way to protect sensitive information (in case your password gets exposed). Github uses a Personal Access Token (PAT) for the Command Line Interface (CLI) and RStudio. This is different from the password you use to log in with a web browser. You will have to create one. There are some nice R functions that will help you along, and I find that easiest.

Complete instructions are in Chapter 9 of Happy Git With R. Here’s the quick version (you need the usethis and gitcreds libraries, which you can install with install.packages(c("usethis", "gitcreds"))):

  1. In the RStudio Console, call usethis::create_github_token() This should open a webbrowser. In the Note field, write what you like, perhaps “Stat 406 token”. Then update the Expiration to any date after December 15. (“No expiration” is fine, though not very secure). Make sure that everything in repo is checked. Leave all other checks as is. Scroll to the bottom and click the green “Generate Token” button.
  2. This should now give you a long string to Copy. It often looks like ghp_0asfjhlasdfhlkasjdfhlksajdhf9234u. Copy that. (You would use this instead of the browser password in RStudio when it asks for a password).
  3. To store the PAT permanently in R (so you’ll never have to do this again, hopefully) call gitcreds::gitcreds_set() and paste the thing you copied there.

Post-installation notes

You have completed the installation instructions, well done 🙌!

Attributions

The DSCI 310 Teaching Team, notably, Anmol Jawandha, Tomas Beuzen, Rodolfo Lourenzutti, Joel Ostblom, Arman Seyed-Ahmadi, Florencia D’Andrea, and Tiffany Timbers.