# Installation

### Create Aliases

These aliases make interacting with `Besu` on the command line easier.

{% code fullWidth="true" %}

```bash
echo "alias besu-log='journalctl -f -u besu.service -o cat | ccze -A'" >> ~/.bashrc
echo "alias besu-start='sudo systemctl start besu.service'" >> ~/.bashrc
echo "alias besu-stop='sudo systemctl stop besu.service'" >> ~/.bashrc
echo "alias besu-restart='sudo systemctl restart besu.service'" >> ~/.bashrc
echo "alias besu-status='sudo systemctl status besu.service'" >> ~/.bashrc
echo "alias besu-version='sudo /usr/local/bin/besu/bin/besu --version'" >> ~/.bashrc
echo "alias besu-config='sudo vim /etc/systemd/system/besu.service'" >> ~/.bashrc
echo "alias besu-enable='sudo systemctl enable besu.service'" >> ~/.bashrc
echo "alias besu-disable='sudo systemctl disable besu.service'" >> ~/.bashrc
echo "alias besu-delete-data='sudo rm -rf /var/lib/besu; sudo mkdir -p /var/lib/besu; sudo chown -R besu:besu /var/lib/besu'" >> ~/.bashrc
echo "alias besu-update='~/besu-update.sh'" >> ~/.bashrc

source ~/.bashrc
```

{% endcode %}

### Firewall Configuration

Configure the firewall using generic Execution client UFW settings:[Execution Clients](/ethereum-dev/infrastructure/client-software/execution-clients.md#ufw)

### Dependency - Install Java

`Besu` requires version 17+ of Java: <https://besu.hyperledger.org/public-networks/get-started/install/binary-distribution#prerequisites-1>

```bash
sudo apt-get install openjdk-21-jre-headless openjdk-21-jdk -y

sudo apt-get install libsodium23 libnss3 -y
```

### Besu - Install

Build the latest version of `Besu`.

```bash
BESU_VERSION_COMMIT_HASH=        # e.g.3f907d6

cd ~
git clone --recursive https://github.com/hyperledger/besu
cd ~/besu
git checkout ${BESU_VERSION_COMMIT_HASH}
./gradlew build -x test
./gradlew clean installDist
```

Move the compiled `Besu` build to a new directory.

```bash
sudo cp -R ~/besu/build/install/besu /usr/local/bin
```

Check version.

```bash
/usr/local/bin/besu/bin/besu --version
```

Create `Besu` user and directory.

```bash
sudo useradd --no-create-home --shell /bin/false besu
sudo mkdir -p /var/lib/besu
```

JWT Secret is now shared between all clients on the same machine: [Execution Clients](/ethereum-dev/infrastructure/client-software/execution-clients.md#create-jwt-secret)

### Besu - Configure Service

Set permissions.

```bash
sudo chown -R besu:besu /var/lib/besu
```

Configure [Execution Clients](/ethereum-dev/infrastructure/client-software/execution-clients.md#execution-service-environment-variables).

Configure `Besu` service using the command line flags.

```bash
sudo vim /etc/systemd/system/besu.service
```

{% code title="/etc/systemd/system/besu.service" %}

```bash
[Unit]
Description=Besu Ethereum Client - Execution Node
After=network.target
Wants=network.target

[Service]
User=besu
Group=besu
Type=simple
Restart=always
RestartSec=5
TimeoutStopSec=1200

EnvironmentFile=/etc/default/execution-variables.env

ExecStart=/usr/local/bin/besu/bin/besu \
    --network=${NETWORK} \
    --sync-mode=SNAP \
    --engine-jwt-secret=/var/lib/jwtsecret \
    --data-path=/var/lib/besu \
    --data-storage-format=BONSAI \
    --p2p-port=${EXECUTION_P2P_PORT} \
    --max-peers=${EXECUTION_MAX_PEERS} \
    --engine-host-allowlist="*" \
    --host-allowlist="*" \
    \
    --metrics-enabled=true \
    --metrics-host=${EXECUTION_METRICS_ADDR} \
    --metrics-port=${EXECUTION_METRICS_PORT} \
    \
    --rpc-ws-enabled=true \
    --rpc-ws-api=ETH,NET,WEB3 \
    --rpc-ws-host=${EXECUTION_WS_ADDR} \
    --rpc-ws-port=${EXECUTION_WS_PORT} \
    \
    --rpc-http-enabled=true \
    --rpc-http-api=ETH,NET,WEB3 \
    --rpc-http-cors-origins="*" \
    --rpc-http-host=${EXECUTION_RPC_ADDR} \
    --rpc-http-port=${EXECUTION_RPC_PORT} \
    \
    --Xplugin-rocksdb-high-spec-enabled

[Install]
WantedBy=default.target
```

{% endcode %}

Start the service and check it's working as expected.

### Besu - Command Aliases

```bash
daemon-reload   # Reload any changes made to the besu.service
besu-enable     # Enable the besu.service
besu-start      # Start the besu.service
besu-status     # View the status of the besu.service

besu-log        # View the besu.service logs
```

### Besu - Update Scripts

Create `Besu` update script.

```bash
vim ~/besu-update.sh
```

{% code title="\~/besu-update.sh" %}

```bash
#!/bin/bash
set -e

while true; do
    read -p "Are you sure you want to update Besu? (Y/N) " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer Y or N.";;
    esac
done

read -p "Enter the commit hash you want to checkout: " commit_hash

# Delete existing besu directory to avoid commit mismatch errors
cd ~
sudo rm -rf besu
git clone --recursive https://github.com/hyperledger/besu
cd ~/besu
git checkout $commit_hash

echo
echo "**************"
echo "Making Besu..."
echo "**************"
./gradlew build -x test
./gradlew clean installDist

# Check if besu.service is running
service_was_running=0
if sudo systemctl is-active --quiet besu.service; then
    service_was_running=1
    echo "****************"
    echo "Stopping Besu..."
    sudo systemctl stop besu.service
fi

echo "Replacing previous version..."
sudo rm -rf /usr/local/bin/besu
sudo cp -R ~/besu/build/install/besu /usr/local/bin

# Only start besu.service if it was running originally
if [ $service_was_running -eq 1 ]; then
    echo "Restarting Besu..."
    echo "******************"
    sudo systemctl start besu.service
fi
```

{% endcode %}

Make the script executable.

```bash
chmod u+x ~/besu-update.sh
```


---

# 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.eridian.xyz/ethereum-dev/infrastructure/client-software/execution-clients/besu/installation.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.
