# Building on macOS

**Note:**

* If you encounter any issues, have a look at [Troubleshooting](https://github.com/AppFlowy-IO/appflowy/wiki/Troubleshooting) first. If your issue is not included in the page, please create an [issue](https://github.com/AppFlowy-IO/appflowy/issues/new/choose) or ask on [Discord](https://discord.gg/9Q2xaN37tV).

## **Step 1: Get the source code**

{% hint style="warning" %}
You should fork the code instead if you wish to submit code to AppFlowy. You'll find information on that in [Setting Up Your Repositories](/docs/documentation/software-contributions/submitting-code/setting-up-your-repositories.md)
{% endhint %}

```shell
git clone https://github.com/AppFlowy-IO/AppFlowy.git
```

## **Step 2: Install Flutter**

{% hint style="info" %}
Skip this if flutter is already installed on your system.
{% endhint %}

* Follow the instructions [here](https://flutter.dev/docs/get-started/install) to install Flutter.
  * It will ask you to run `flutter doctor` to check any dependencies you need to install to complete the setup.
    * It is not necessary to install Android toolchain and Android studio to run AppFlowy.
    * However, CocoaPods and VS Code are required.
* Make sure you also install the [Flutter](https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter) & [Dart](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code) extensions in VS Code.

## **Step 3: Install your build environment**

* Run the setup script from the base directory
  * It will guide you through to install Rust, which is required by AppFlowy

```bash
./frontend/scripts/install_dev_env/install_macos.sh
```

> FYI, AppFlowy uses <https://github.com/sagiegurari/cargo-make> to construct the build scripts. It is important that you add (dart) `pub` to $PATH, otherwise VS Code may error out. Add the following to your `.bashrc` or `.zshrc` in `$HOME`:
>
> ```
> export PATH="$PATH":"$HOME/.pub-cache/bin"
> ```
>
> Make sure to restart your terminal and VS Code

## **Step 4: Edit and run the application**

1. Open the `frontend` folder located at `xx/AppFlowy/frontend` with VS Code. It is important *not* to open the root folder, as that will not give access to the appropriate debug commands.
2. Open `xx/AppFlowy/frontend/appflowy_flutter/lib/main.dart` and then check the device selection: ![device](https://user-images.githubusercontent.com/86001920/144546864-cebbf0c0-4eef-424e-93c7-e1e6b3a59669.png)
3. Go to the Run and Debug tab and then click AF-desktop: Clean + Rebuild All for the first time running.

![img.png](/files/7zs8H6S4foEwJEXiskVG)

If you encounter any issues, have a look at [Troubleshooting](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/environment-setup/trouble-shotting) first. If your issue is not included in the page, please create an [issue](https://github.com/AppFlowy-IO/appflowy/issues/new/choose) or ask on [Discord](https://discord.gg/9Q2xaN37tV).

## Building in release mode

1. Go to the AppFlowy/frontend/ directory.
2. Run the following command to build the binary depending on your architecture.

{% tabs %}
{% tab title="x86" %}

```shell
cargo make --profile production-mac-x86_64 appflowy
```

{% endtab %}

{% tab title="arm64" %}

```shell
cargo make --profile production-mac-arm64 appflowy
```

{% endtab %}
{% endtabs %}

The scripts are located in the AppFlowy/frontend/Makefile.toml file.

The resulting binary file is located in `AppFlowy/frontend/appflowy_flutter/product/x.x.x/[OS]/Release/AppFlowy/`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appflowy.io/docs/documentation/appflowy/from-source/environment-setup/building-on-macos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
