> For the complete documentation index, see [llms.txt](https://docs.neurochain.ai/nc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neurochain.ai/nc/neurochainai-guides/development/environment-setup.md).

# Environment Setup

Complete guide for setting up your NCN Network development environment.

***

## Prerequisites

### Required Software

| Software   | Version | Purpose          |
| ---------- | ------- | ---------------- |
| **Rust**   | 1.70+   | Core services    |
| **Python** | 3.8+    | Model execution  |
| **Git**    | 2.0+    | Version control  |
| **protoc** | 3.0+    | Protocol buffers |

### Optional Software

| Software    | Version | Purpose                    |
| ----------- | ------- | -------------------------- |
| **Docker**  | 20.10+  | Containerized deployment   |
| **Foundry** | Latest  | Smart contract development |
| **Node.js** | 18+     | Client SDK development     |

***

## Install Rust

### Linux/macOS

```bash
# Install Rust via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Follow the prompts, then reload your shell
source $HOME/.cargo/env

# Verify installation
rustc --version
cargo --version
```

### Windows

Download and run [rustup-init.exe](https://win.rustup.rs/).

### Additional Components

```bash
# Add clippy for linting
rustup component add clippy

# Add rustfmt for formatting
rustup component add rustfmt
```

***

## Install Python

### Linux (Ubuntu/Debian)

```bash
sudo apt update
sudo apt install python3 python3-pip python3-venv
```

### macOS

```bash
# Using Homebrew
brew install python@3.11

# Or use pyenv for version management
brew install pyenv
pyenv install 3.11
pyenv global 3.11
```

### Python Dependencies

```bash
# Create virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate

# Install ML dependencies
pip install torch transformers numpy scipy
```

***

## Install Protocol Buffers

### Linux (Ubuntu/Debian)

```bash
sudo apt install protobuf-compiler libprotobuf-dev
```

### macOS

```bash
brew install protobuf
```

### Verify Installation

```bash
protoc --version
# Should output: libprotoc 3.x.x or higher
```

***

## Install System Dependencies

### Linux (Ubuntu/Debian)

```bash
# Build essentials
sudo apt install build-essential pkg-config

# OpenSSL development headers
sudo apt install libssl-dev

# Additional dependencies
sudo apt install cmake clang
```

### macOS

```bash
# Xcode command line tools
xcode-select --install

# OpenSSL (if needed)
brew install openssl
```

***

## Clone the Repository

```bash
# Clone the repository
git clone https://github.com/neurochainai/ncn-network-v2-rs.git
cd ncn-network-v2-rs
```

***

## Build the Project

```bash
# Build all components in debug mode
cargo build

# Build all components in release mode
cargo build --release

# Build specific component
cargo build -p gateway_node
cargo build -p compute_node
cargo build -p p2p_registry_node
cargo build -p test_client
```

### Expected Output

```
   Compiling common_types v0.1.0
   Compiling p2p_registry_node v0.1.0
   Compiling gateway_node v0.1.0
   Compiling compute_node v0.1.0
   Compiling test_client v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in X.XXs
```

***

## Verify Installation

### Run Tests

```bash
# Run all tests
cargo test --all

# Run tests with output
cargo test --all -- --nocapture
```

### Check Linting

```bash
# Run clippy
cargo clippy --all

# Run format check
cargo fmt --all -- --check
```

***

## Optional: Docker Setup

### Install Docker

```bash
# Linux
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER

# macOS
brew install --cask docker
```

### Build Docker Images

```bash
# Build all images
docker-compose build

# Or build individual images
docker build -t ncn-gateway -f gateway_node/Dockerfile .
docker build -t ncn-compute -f compute_node/Dockerfile .
docker build -t ncn-registry -f p2p_registry_node/Dockerfile .
```

***

## Optional: Foundry Setup

For smart contract development:

```bash
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

# Verify
forge --version
cast --version
anvil --version
```

***

## IDE Setup

### VS Code

Recommended extensions:

```json
{
  "recommendations": [
    "rust-lang.rust-analyzer",
    "tamasfe.even-better-toml",
    "serayuzgur.crates",
    "vadimcn.vscode-lldb",
    "ms-python.python"
  ]
}
```

### JetBrains (IntelliJ/CLion)

* Install Rust plugin
* Install Python plugin
* Configure Cargo toolchain

***

## Environment Variables

Create a `.env` file or export variables:

```bash
# Logging
export RUST_LOG=info
export RUST_BACKTRACE=1

# Development mode
export REQUIRE_PAYMENT=false
export SANDBOX_MODE=disabled

# Network (local development)
export RPC_URL=http://127.0.0.1:8545
```

***

## Troubleshooting

### "linker not found"

```bash
# Install build essentials
sudo apt install build-essential
```

### "protoc not found"

```bash
# Install protobuf compiler
sudo apt install protobuf-compiler
```

### "OpenSSL not found"

```bash
# Linux
sudo apt install libssl-dev pkg-config

# macOS
brew install openssl
export OPENSSL_DIR=$(brew --prefix openssl)
```

### "Python not found" during build

```bash
# Ensure Python is in PATH
which python3

# Or set explicitly
export PYTHON_SYS_EXECUTABLE=$(which python3)
```

***

## Next Steps

* [Building](/nc/neurochainai-guides/development/building.md) - Detailed build instructions
* [Running Locally](/nc/neurochainai-guides/development/running-locally.md) - Start local development
* [Testing](/nc/neurochainai-guides/development/testing.md) - Run the test suite
