Installing Git for Windows
What is Git for Windows?
- Since Bash is not the default shell on Windows (unlike macOS), it must be installed. One way is by downloading Git for Windows, which comes with Git Bash.
- “Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system.”
- Specifically, this installation comes with executables that RStudio can find and use to make it possible to run Git and Bash commands in an RMarkdown code chunk.
Steps to install:
- Download Git for Windows and run the installer
- You’ll be going with the default option for most steps except one step towards the end as described later
- One of the first screens you’ll see in the setup process is the location where Git will be installed (e.g.,
C:\Program Files\Git). Leave it as default but just make a note of this path in case we need it later for troubleshooting purposes.
- In the screen below, you can optionally select to install a shortcut to Git Bash on your Desktop for easier access.
- When you get to the step shown below about Adjusting your PATH environment, make sure to select Use Git and optional Unix tools from the Command Prompt. If you do not, you may run into the issue described in the troubleshooting section below.
- After you finish the installation process, check that Git Bash is your default terminal in RStudio by going under
Global Options... (
Terminal tab). You may need to restart RStudio for changes to be reflected.
PATH environment variable:
- If you are not able to run Bash in an RMarkdown code chunk after installing Git for Windows, it may be because RStudio is not able to locate the necessary executables since its directory is not in your
PATH environment variable
PATH] specifies the directories in which executable programs are located on the machine that can be started without knowing and typing the whole path to the file on the command line.”
PATH on Windows:
- You can run R code to check if the Bash executable is in your
Sys.which('bash'): Path to your Bash executable (e.g.,
PATH environment variable containing list of paths separated by
; that your machine knows to look for
- If the path to your Bash executable is not part of your
PATH, you can add it
- One way to do it is by running the R command
Sys.setenv() seen here, but this only modifies the
PATH for your current R session
- Instead, you can follow these steps to add
C:\Program Files\Git\bin to your