> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup StarRocks FE development environment on IDEA

> How to set up the StarRocks FE development environment in IntelliJ IDEA on macOS Apple Silicon.

This tutorial is based on macOS and has been tested on Apple Chip(M1, M2).
Even if you are not using macOS, you can also refer to this tutorial.

## Requirements

### Thrift 0.13

There is no 0.13 version of Thrift in the official brew repository; one of our committers created a version in their repo to install.

```bash theme={null}
brew install alberttwong/thrift/thrift@0.13
```

After installing Thrift successfully, you can check by executing following command:

```bash theme={null}
$ thrift -version
Thrift version 0.13.0
```

### Protobuf

Just use the latest version v3, because the latest version of Protobuf is compatible with the v2 version of the Protobuf used in StarRocks.

```bash theme={null}
brew install protobuf
```

### Maven

```
brew install maven
```

### Openjdk 1.8 or 11

```bash theme={null}
brew install openjdk@11
```

### Python3

MacOS is already installed by default.

Everyone's Thrift and Protobuf installation directories may be different, you can use the brew list command to inspect:

```bash theme={null}
brew list thrift@0.13.0
brew list protobuf
```

## Configure the StarRocks

### Download the StarRocks

```
git clone https://github.com/StarRocks/starrocks.git
```

### Setup thirdparty directory

Create `installed/bin` directory in `thirdparty`.

```bash theme={null}
cd starrocks && mkdir -p thirdparty/installed/bin
```

Then create soft link for Thrift and Protobuf respectively.

```bash theme={null}
ln -s /opt/homebrew/bin/thrift thirdparty/installed/bin/thrift
ln -s /opt/homebrew/bin/protoc thirdparty/installed/bin/protoc
```

### Setting environment variables

```bash theme={null}
export JAVA_HOME="/opt/homebrew/Cellar/openjdk@11/11.0.15" # Caution: The jdk version may be different in you desktop
export PYTHON=/usr/bin/python3
export STARROCKS_THIRDPARTY=$(pwd)/thirdparty # Caution: Make sure you are in the starrocks directory
```

## Generate source code

Many source files in FE need to be generated manually, otherwise IDEA will report an error due to missing files.
Execute the following command to automatically generate:

```bash theme={null}
make -C gensrc script
./build.sh --be --configure-only
cmake --build be/build_Release --target be_proto_codegen be_thrift_codegen
```

The generated BE thrift/protobuf C++ files will appear under the active build directory, for example `be/build_Release/gensrc/gen_cpp`.

## Compile FE

Enter `fe` directory and use Maven to compile:

```bash theme={null}
cd fe
mvn install -DskipTests
```

## Open StarRocks in IDEA

1. Open the `StarRocks` directory in IDEA.

2. Add Coding style setting
   To standardize the coding style, you should import the `fe/starrocks_intellij_style.xml` code style file in IDEA.

   ![image-20220701193938856](https://mintcdn.com/mirrorship-docs/8gpPdHU-sBXASb5i/documents/images/085330aa269380f0a35836ab.png?fit=max\&auto=format\&n=8gpPdHU-sBXASb5i\&q=85\&s=cd2a3e06df4a1325d6f22def1eebb50c)

## Run StarRocks FE in MacOS

Use IDEA to open the `fe` directory.

If you execute the Main function directly in `StarRocksFE.java`, some errors will be reported. You only need to do some simple settings to run it smoothly.

**NOTICE:**  `StarRocksFE.java` is in the `fe/fe-core/src/main/java/com/starrocks` directory.

1. Copy the conf, bin and webroot directories from the StarRocks directory to `fe` directory:

```bash theme={null}
cp -r conf fe/conf
cp -r bin fe/bin
cp -r webroot fe/webroot
```

2. Enter the `fe` directory and create the log and meta folders under the `fe` directory:

```bash theme={null}
cd fe
mkdir log
mkdir meta
```

3. Set the environment variable, as shown in the following figure:

![image-20220701193938856](https://mintcdn.com/mirrorship-docs/sL46GVQByWEibCzI/documents/images/4de0fa5846a4ebc43f49c29c.png?fit=max\&auto=format\&n=sL46GVQByWEibCzI\&q=85\&s=0cffe5f9c1bf7b712531b143828a24d3)

```bash theme={null}
export PID_DIR=/Users/smith/Code/starrocks/fe/bin
export STARROCKS_HOME=/Users/smith/Code/starrocks/fe
export LOG_DIR=/Users/smith/Code/starrocks/fe/log
```

4. Modify the priority\_networks in `fe/conf/fe.conf` to `127.0.0.1/24` to prevent FE from using the current computer's LAN IP and cause the port fail to bind.

5. Then you have run StarRocks FE successfully.

## DEBUG StarRocks FE in MacOS

If you started the FE with the debug option, you can then attach the IDEA debugger to the FE process.

```
./start_fe.sh --debug
```

See [https://www.jetbrains.com/help/idea/attaching-to-local-process.html#attach-to-local](https://www.jetbrains.com/help/idea/attaching-to-local-process.html#attach-to-local).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.