# Software installation

Hands-on experience with Python coding is an essential part of mastering the skill of programming. 
To do this on your laptop, you will need to install the necessary software.

This page guides you through the installation steps for:

- Visual Studio Code (VS Code)
- Git
- Conda

When installing individual components, you always have to make sure to follow the **appropriate instructions** depending on the operating system of your laptop (Windows, macOS, or Linux). 

Where both textual and video instructions are available, we **recommend following the video ones**, as they include extra tips and tricks and are generally easier to follow.
Make sure to follow the **installation order** as presented in this book or in the installation guide playlist, which contains all the videos in the specific required sequence:

[**Windows installation and setup playlist**](https://www.youtube.com/playlist?list=PLU1ARaDkvyrM7C7a90OinMzrtt4K6VLyh)

[**macOS installation and setup playlist**](https://www.youtube.com/playlist?list=PLU1ARaDkvyrPC-VvFdyjQ4SuziKg_y02l)


## Visual Studio Code

To write Python code, you will use an integrated development environment (IDE) called [**Visual Studio Code**](https://code.visualstudio.com/) (VS Code), which you can use to write, test, and debug your code.
VS Code generally works well on various operating systems (Windows, macOS, Linux) and supports multiple programming languages besides Python, which may come in handy in the future should you decide to use another language.
Of course, there is a choice of available IDEs, so in the future you may also choose to use a different one (PyCharm and Spyder are popular choices).


`````{tab-set}

````{tab-item} Windows
```{video} https://www.youtube.com/embed/n4H3s8URX4o
```

**Installation steps:**

1.	Go to [Download Visual Studio Code](https://code.visualstudio.com/download).

2.	Download the `.exe` file for Windows.

3.	Follow the default settings.

4.	This will directly launch a VS Code window. If you notice a "release note" opened as a tab in VS code, you can close the tab.

You now have VS Code installed. We will go through its setup and basic usage on the next book page.

````

````{tab-item} macOS
```{video} https://www.youtube.com/embed/BugD92qMzPk
```

**Installation steps:**
1.	Navigate to [this website](https://code.visualstudio.com/download) and click on the Download icon for Mac. The download will happen either immediately, or you may need to press “Allow” when asked whether you want to allow the download.

```{figure} images/mac/VSCode_Mac_1.png
---
height: 300px
name: 
---
```

2.	Navigate to the downloaded file. The downloaded file will be either:
- A zip file: double-click on it to unzip it, and then open the unzipped VS Code application, or
- VS Code application: double-click on it to open it. 
If you’re asked whether you’re sure if you want to open this app, press “Open”. VS Code should then open and you should see the screen such as this:

```{figure} images/mac/VSCode_Mac_2.png
---
height: 300px
name: 
---
```

You now have VS Code installed. We will go through its setup and basic usage on the next book page.
````

````{tab-item} Linux
1. Go to [Download Visual Studio Code](https://code.visualstudio.com/download). Installation guide can be found [here](https://code.visualstudio.com/docs/setup/linux). Otherwise, you can follow the instructions below.

2. Select the `tar.gz` based on your Linux system.

3. Use your terminal to extract the tarball (`tar.gz`): `tar -xvf code-*.tar.gz`.
Navigate into the extracted folder (e.g., `cd VSCode-linux-x64`) and run the application using `./code`.

4. In general, once the installation is complete, you can launch Visual Studio Code by:
- Searching for "Visual Studio Code" in your application menu, or
- Typing `code` in the terminal. This should directly launch a VS Code window.

*Optional*: alternative steps 2 and 3.

*Option 1.* If you download `.deb` in step 2 (for Debian/Ubuntu), to install VS Code you need to open a terminal and use the `cd` command to navigate to the directory where the downloaded file is located (typically `~/Downloads/`). Then install the package using
`sudo dpkg -i code_*.deb`.
If there are dependency issues, run
`sudo apt-get install -f` .

*Option 2.* If you download `.rpm` in step 2 (for Fedora), to install VS Code you need to open the terminal and use the `cd` command to navigate to the directory where the downloaded file is located (typically `~/Downloads/`). Then install the package using
`sudo dnf install code-*.rpm`

````

`````

## Git

Git is a tool used for code management. 
It's a free and open-source version control system (see *Version Control System* in [Computer glossary](../chapter-01-introduction/computer-glossary.md)).
Git is incredibily useful (and therefore very widely used) for tracking changes in your code, for sharing code, and for collaborating on code with others. 
Any programming endeavours you may encounter at your future work will almost certainly include working with Git.

`````{tab-set}

````{tab-item} Windows
```{video} https://www.youtube.com/embed/goENAlQJO0s
```

**Installation steps:**
1. Go to [Git - Downloading Package](https://git-scm.com/downloads/win).
2. From the standalone installers, pick the Windows version your computer has and download.
3. Run the `.exe` file and stay with the default settings until you need to choose the default editor. Select "use VS code as Git’s default editor" from the drop-down menu.

````

````{tab-item} macOS
```{video} https://www.youtube.com/embed/pYSIkD3zIXE
```

**Installation steps:**
Open the Spotlight search by pressing `command` + `Space`, type in "Terminal", and open the Terminal application on you computer. 
Type in `git --version` and press `Enter`. 
Depending on the outcome of this action, you should follow scenario 1, 2, or 3.

*Scenario 1*

Running `git --version` in terminal displayed Git version, which looks like this: 

```{figure} images/mac/git1.png
---
height: 350px
name: 
---
```

Note that the exact version displayed may be different than 2.39.5 and that is alright. If a version was displayed, you're all set.

*Scenario 2*

Running `git --version` in terminal gave a longer message which mentions **XCode**, and a new window popped up prompting you to install it. In this case, **agree to install** and follow the installation instructions. Once it's done, go back to terminal and try running `git --version` again. This time, you should get the outcome shown in *Scenario 1*, and then you're all set.

*Scenario 3*

If even after installing XCode (*Scenario 2*) the terminal doesn't display Git version, i.e., if there is no Git on your computer, you can choose to either follow [these instructions](https://docs.gitlab.com/ee/topics/git/how_to_install_git/?tab=macOS) or install Homebrew first (see the Homebrew section just below in the book) and then install Git using Homebrew:

Install Git with Homebrew:
```bash
brew install git
```

After installation, verify that Git is installed by running:
```bash
git --version
```

````

````{tab-item} Linux

1. Open a terminal.

2. Run the appropriate command for your Linux distribution:

   **For Debian/Ubuntu**:
   ```bash
   sudo apt-get install git
   ```

   **For Fedora**:
   ```bash
   sudo dnf install git
   ```

3. After installation, verify that Git is installed by running:
   ```bash
   git --version
   ```
   This command will display the installed Git version.

````

`````

## Homebrew (optional)

[**Homebrew**](https://brew.sh/) is a package manager for macOS and Linux that simplifies the installation of software and tools. Think of it as an app store for command-line tools and applications. Instead of manually downloading and installing software, Homebrew automates the process with simple commands.

Homebrew is particularly useful for installing development tools, libraries, and utilities that aren't available through the standard macOS App Store or Linux package managers. For example, it can be used to install Git (if not already present), Python packages, and many other developer tools.

```{admonition} When do you need Homebrew?
:class: note, dropdown
Homebrew is optional for most users. You may need it if:
- Git installation via XCode doesn't work on macOS (scenario 3 above)
- You want an easier way to install and manage development tools
- You plan to install additional programming languages or tools in the future

If you're following the standard installation path and everything works, you can skip this section for now.
```

`````{tab-set}

````{tab-item} macOS

1. Open the Terminal application.

2. Copy and paste the following command into your terminal and press `Enter`:

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

3. Follow the on-screen instructions. You may be prompted to enter your password. Note that when typing your password in the Terminal, the characters will not be displayed for security reasons. Don’t worry — your input is still being registered, so just type your password as usual and press `Enter`.

4. Once installation is complete, verify that Homebrew is installed by running:

```bash
brew --version
```

This should display the installed Homebrew version.

````

````{tab-item} Linux

1. Open your terminal.

2. Copy and paste the following command into your terminal and press `Enter` (do not use `sudo`):

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

3. Follow the instructions displayed in the terminal during installation.

4. After installation completes, add Homebrew to your PATH by running these commands:

```bash
echo 'eval "$(~/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(~/.linuxbrew/bin/brew shellenv)"
```

5. Verify that Homebrew is installed correctly by running:

```bash
brew --version
```

This should display the installed Homebrew version.

````

`````

## Conda

Conda is a package and environment manager for Python. It also provides a minimal Python distribution, which comes with a few pre-installed packages, such as `pip`.

Before you start using Python, you need to install conda. We'll do this using [Miniforge](https://github.com/conda-forge/miniforge), a minimal, community-maintained installer for conda. We will also need a few packages that are not included by default; we will set this up on the next book page.

```{admonition} Why Miniforge instead of Anaconda/Miniconda?
:class: note, dropdown
The [licensing for Anaconda](https://www.anaconda.com/legal/terms/terms-of-service), distributed by Anaconda Inc., restricts free use of the Anaconda platform for some for-profit organizations. Because of this, your institution may not permit you to use the Anaconda distribution, Miniconda, or Anaconda's default package channels. An open source alternative is Miniforge, maintained by conda-forge. The Miniforge installer is [licensed under a BSD-3-Clause license](https://github.com/conda-forge/miniforge?tab=License-1-ov-file#), which is only minimally restricting.
```

```{admonition} What are packages?
:class: note, dropdown
Imagine you are working with a two-dimensional matrix filled with numbers, and using Python you wish to [transpose](https://en.wikipedia.org/wiki/Transpose) this matrix, i.e., switch its rows and columns.
As you can imagine, many people before you have wanted to do the same thing in Python.
To prevent programmers from reinventing the same pieces of code time and again, there are multiple Python packages available, each containing pre-made code which performs certain operations (such as matrix transposition). 
You can install and use these packages for free using your terminal.
```

`````{tab-set}

````{tab-item} Windows
<!-- TODO: record a Miniforge-specific installation walkthrough video to replace the old Miniconda video -->

**Installation steps:**
1. Go to the [Miniforge installer page](https://conda-forge.org/download/) and select the [Windows installation file](https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe) for download.

2. Run the `.exe` file to start the installation.

3. Follow the default settings; in the step when you can choose recommended settings, select those.

4. Open Miniforge Prompt which was installed with conda.

5. Type `conda` to see the possible commands.

6. Try the `conda list` command to see if the installation is successful. You should see a list of installed packages.

<!-- TODO: replace with a Miniforge-specific screenshot (was images/windows/miniconda1.png) -->

7. Make Conda available in Git Bash:

Since this course uses **Git Bash** to teach Unix-style commands (which are standard in scientific computing and bioinformatics), you need to make `conda` commands available in Git Bash. To do so, follow these steps:

- In the Miniforge Prompt window, run the following command: `conda init bash`
- Close all terminals. (Miniforge Prompt, Git Bash, etc.)
- Open Git Bash and verify that conda works by typing `conda --version`.

This step is **essential** for the rest of the course, as we will be using Git Bash terminal with Unix-style commands rather than Windows Command Prompt (CMD) or PowerShell.

````

````{tab-item} macOS
<!-- TODO: record a Miniforge-specific installation walkthrough video to replace the old Miniconda video -->

**Installation steps:**
1. Click on the Apple symbol in the top left corner of your screen and then click About This Mac. Take note of the type of processor/chip you have (Intel vs. M1/M2/M3); this will inform your choices in this installation.

2. Go to the [Miniforge installer page](https://conda-forge.org/download/).

3. Select the corresponding file from the list of options:
- [arm64 (Apple Silicon)](https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Darwin-arm64.sh) if your laptop has an M1, M2, or M3 chip. This will download a `.sh` file into your Downloads folder.
- [x86\_64 (Intel)](https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Darwin-x86_64.sh) file if your laptop has an Intel chip. This will download a `.sh` file into your Downloads folder.

4. Open your terminal (`⌘` + `Space` > type `terminal`). Type the command `bash ~/Downloads/Miniforge3-$(uname)-$(uname -m).sh`. This executes the `.sh` file and installs conda.

5. Accept the default / recommended settings during the installation process.

<!-- TODO: replace with a Miniforge-specific screenshot (was images/mac/Miniconda_Mac_1.png) -->

6. Let's verify whether the installation was successful: Open your terminal (`⌘` + `Space` > type `terminal`). Type `conda list` and press `Enter`. If your conda installation was successful, you will see a list of installed packages.

<!-- TODO: replace with a Miniforge-specific screenshot (was images/mac/Miniconda_Mac_2.png) -->

````

````{tab-item} Linux
Follow the [official installation guide from the Miniforge GitHub](https://github.com/conda-forge/miniforge?tab=readme-ov-file#unix-like-platforms-macos-linux--wsl) or follow the procedure below:

1. Open the terminal and run `uname -m` to see what CPU architecture your computer uses. Remember the output of this command for step 3.

2. Go to the [Miniforge installer page](https://conda-forge.org/download/).

3. Download the installer corresponding to the CPU architecture from step 1.

4. Open your terminal. Type the command `bash ~/Downloads/Miniforge3-$(uname)-$(uname -m).sh`. This executes the `.sh` file and installs conda.

5. Accept the default / recommended settings during the installation process.

6. Let's verify whether the installation was successful: Open your terminal. Type `conda list` and press `Enter`. If your conda installation was successful, you will see a list of installed packages (check the macOS tab in these instructions to see an example).

````

`````


