Skip to main content

Overview

The setup_claw.sh script is an automated installer designed specifically for Android (non-rooted) environments running Termux. It handles all dependencies, environment configuration, and critical Android-specific patches required to run OpenClaw on mobile devices.
This script includes several workarounds for Android/Termux limitations that standard Linux systems don’t require. Do not use this script on traditional Linux distributions.

What the Script Does

The installer performs 6 major steps in sequence:
1

Install Dependencies & System Prep

Updates Termux packages and installs all required dependencies
2

Fix Environment Variables

Configures proper temp directory paths for Android
3

Apply Node-GYP Workaround

Prevents crashes during native module compilation
4

Install OpenClaw

Downloads and installs OpenClaw from npm
5

Patch Hardcoded Paths

CRITICAL: Replaces hardcoded /tmp paths with Termux-compatible paths
6

Configure Background Service

Sets up runit service for persistent operation

Step-by-Step Breakdown

Step 1: Dependencies & System Preparation

pkg update -y && pkg upgrade -y
pkg install -y nodejs-lts git build-essential python cmake clang \
  ninja pkg-config binutils termux-api termux-services proot tmux nano
What gets installed:
  • nodejs-lts: JavaScript runtime for OpenClaw
  • git: Version control (for future updates)
  • build-essential, python, cmake, clang, ninja: Compilation tools for native AI engine components
  • termux-api: Hardware access APIs
  • termux-services: Service management via runit
  • proot, tmux, nano: System utilities
This step can take 5-15 minutes depending on your device and network speed.

Step 2: Environment Variables

The Problem: Android doesn’t have /tmp. Apps that assume it exists will crash. The Solution:
mkdir -p "$PREFIX/tmp"
mkdir -p "$HOME/tmp"

# Add persistent exports to .bashrc
echo 'export TMPDIR="$PREFIX/tmp"' >> ~/.bashrc
echo 'export TMP="$PREFIX/tmp"' >> ~/.bashrc
echo 'export TEMP="$PREFIX/tmp"' >> ~/.bashrc

# Export for current session
export TMPDIR="$PREFIX/tmp"
export TMP="$PREFIX/tmp"
export TEMP="$PREFIX/tmp"
Why this matters:
  • $PREFIX in Termux resolves to /data/data/com.termux/files/usr
  • Creates writable temp directories within Termux’s sandboxed filesystem
  • Exports are added to .bashrc for persistence across sessions
  • Duplicates are cleaned before adding to prevent .bashrc pollution

Step 3: Node-GYP Workaround

The Problem: Node-GYP (used for compiling native modules) tries to find the Android NDK and crashes when it’s missing. The Solution:
mkdir -p ~/.gyp
echo "{'variables':{'android_ndk_path':''}}" > ~/.gyp/include.gypi
Why this works:
  • Creates a dummy GYP configuration file
  • Prevents Node-GYP from panicking when it can’t locate the NDK
  • Allows native module compilation to proceed without Android NDK errors
This is a known workaround for Node.js native addons on Termux. Without this, installation will fail during the npm install step.

Step 4: OpenClaw Installation

npm install -g openclaw@latest
Installs OpenClaw globally using npm. This step:
  • Downloads the latest version from the npm registry
  • Compiles native dependencies (if any)
  • Installs to $PREFIX/lib/node_modules/openclaw
  • Creates the openclaw command in $PREFIX/bin
This step can take 5-10 minutes. Do not interrupt the process.

Step 5: Path Patching (CRITICAL)

The Problem: OpenClaw’s compiled code contains hardcoded references to /tmp/openclaw, which doesn’t exist on Android. The Solution:
TARGET_FILE="$PREFIX/lib/node_modules/openclaw/dist/entry.js"

if [ -f "$TARGET_FILE" ]; then
    sed -i "s|/tmp/openclaw|$PREFIX/tmp/openclaw|g" "$TARGET_FILE"
    echo "Success: Patched entry.js"
else
    echo "WARNING: entry.js not found. Installation structure might have changed."
fi
Why this is critical:
  • Without this patch, OpenClaw will fail at runtime when trying to write to /tmp/openclaw
  • The sed command replaces all occurrences of /tmp/openclaw in the main entry point
  • This must be re-applied after every update (handled by update_claw.sh)
DO NOT SKIP THIS STEP. OpenClaw will not function on Android without this patch.

Step 6: Service Setup

The Problem: Android doesn’t support systemd. Background processes need alternative service management. The Solution: Use runit (provided by termux-services)

Creating the Service Directory

SERVICE_DIR="$PREFIX/var/service/openclaw"
LOG_DIR="$PREFIX/var/log/openclaw"

mkdir -p "$SERVICE_DIR/log"
mkdir -p "$LOG_DIR"

The Main Run Script

cat <<EOF > "$SERVICE_DIR/run"
#!/data/data/com.termux/files/usr/bin/sh
# Explicitly set PATH so the service finds 'node'
export PATH=$PREFIX/bin:\$PATH
# Explicitly set TMPDIR so it can write files
export TMPDIR=$PREFIX/tmp
# Start the gateway
exec openclaw gateway 2>&1
EOF

chmod +x "$SERVICE_DIR/run"
What this does:
  • Sets PATH so runit can find the node and openclaw binaries
  • Sets TMPDIR to the correct Android-compatible path
  • Runs openclaw gateway as the main service process
  • Redirects both stdout and stderr to the logging system

The Log Script

cat <<EOF > "$SERVICE_DIR/log/run"
#!/data/data/com.termux/files/usr/bin/sh
exec svlogd -tt $LOG_DIR
EOF

chmod +x "$SERVICE_DIR/log/run"
What this does:
  • Uses svlogd (runit’s log daemon) to capture service output
  • Stores logs in $PREFIX/var/log/openclaw
  • Adds timestamps (-tt flag) to log entries

Enabling the Service

# Ensure SVDIR is set
export SVDIR="$PREFIX/var/service"
echo 'export SVDIR="$PREFIX/var/service"' >> ~/.bashrc

# Start/restart the service daemon
service-daemon stop >/dev/null 2>&1 || true
service-daemon start >/dev/null 2>&1 || true

# Wait for supervise to be ready
for i in 1 2 3 4 5; do
  [ -e "$PREFIX/var/service/openclaw/supervise/ok" ] && break
  sleep 1
done

sv-enable openclaw
Why this dance is necessary:
  • Termux-services can be unreliable immediately after installation
  • Restarting the service daemon ensures runit is properly supervising $SVDIR
  • The loop waits for the supervise/ok file to exist before enabling
  • sv-enable creates a symlink that tells runit to manage the service

Post-Installation Steps

After the script completes, you must follow these steps:
1

Run Onboarding

openclaw onboard
When asked to install a daemon/service during onboarding: SAY NO / SKIP.The script has already configured the service manually. Android doesn’t support systemd, so the automatic installer will fail.
2

Reload Shell Environment

source ~/.bashrc
This loads the environment variables into your current session.
3

Start the Service

sv up openclaw
Starts the OpenClaw gateway in the background.
4

Acquire Wake Lock

termux-wake-lock
This prevents Android from killing the background process when the screen turns off. Critical for persistent operation.
5

Access the UI

Open your browser to:
http://localhost:18789

Troubleshooting

Script fails at package installation

pkg update
pkg upgrade
# Then re-run setup_claw.sh

”entry.js not found” warning

The OpenClaw package structure may have changed. Check the installation directory:
ls -la $PREFIX/lib/node_modules/openclaw/dist/
If the main entry point has a different name, you’ll need to manually patch it.

Service won’t start

Check service status:
sv status openclaw
Check logs:
cat $PREFIX/var/log/openclaw/current

Permission errors

Ensure run scripts are executable:
chmod +x $PREFIX/var/service/openclaw/run
chmod +x $PREFIX/var/service/openclaw/log/run

Build docs developers (and LLMs) love