Overview
Thesetup_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.
What the Script Does
The installer performs 6 major steps in sequence:Step-by-Step Breakdown
Step 1: Dependencies & System Preparation
- 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:
$PREFIXin Termux resolves to/data/data/com.termux/files/usr- Creates writable temp directories within Termux’s sandboxed filesystem
- Exports are added to
.bashrcfor persistence across sessions - Duplicates are cleaned before adding to prevent
.bashrcpollution
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:- 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
- Downloads the latest version from the npm registry
- Compiles native dependencies (if any)
- Installs to
$PREFIX/lib/node_modules/openclaw - Creates the
openclawcommand in$PREFIX/bin
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:
- Without this patch, OpenClaw will fail at runtime when trying to write to
/tmp/openclaw - The
sedcommand replaces all occurrences of/tmp/openclawin 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 bytermux-services)
Creating the Service Directory
The Main Run Script
- Sets
PATHso runit can find thenodeandopenclawbinaries - Sets
TMPDIRto the correct Android-compatible path - Runs
openclaw gatewayas the main service process - Redirects both stdout and stderr to the logging system
The Log Script
- Uses
svlogd(runit’s log daemon) to capture service output - Stores logs in
$PREFIX/var/log/openclaw - Adds timestamps (
-ttflag) to log entries
Enabling the Service
- Termux-services can be unreliable immediately after installation
- Restarting the service daemon ensures runit is properly supervising
$SVDIR - The loop waits for the
supervise/okfile to exist before enabling sv-enablecreates a symlink that tells runit to manage the service
Post-Installation Steps
After the script completes, you must follow these steps:Acquire Wake Lock
This prevents Android from killing the background process when the screen turns off. Critical for persistent operation.
Troubleshooting
Script fails at package installation
”entry.js not found” warning
The OpenClaw package structure may have changed. Check the installation directory:Service won’t start
Check service status:Permission errors
Ensure run scripts are executable:Related Pages
- Update Script - Safely update OpenClaw while preserving configuration
- Service Management - Managing the OpenClaw background service
- Troubleshooting - Common Android-specific issues