This guide will help you set up the Cosmopolitan toolchain and build the project.
- A modern Linux distribution (Ubuntu, Debian, Fedora, Arch, etc.)
- Basic build tools (typically already installed)
- wget or curl for downloading files
- WSL2 (Windows Subsystem for Linux) recommended
- Or use the binary directly (APE files run natively on Windows)
- Xcode Command Line Tools
- Homebrew (optional, for easier installation)
Download the pre-built Cosmopolitan toolchain:
# Create installation directory
sudo mkdir -p /opt/cosmo
cd /opt/cosmo
# Download the latest release
sudo wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
sudo unzip cosmocc.zip
sudo rm cosmocc.zip
# Make them executable
sudo chmod +x bin/cosmocc bin/cosmoar
# Add to PATH (optional)
echo 'export PATH="/opt/cosmo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcsudo mkdir -p /opt/cosmo
cd /opt/cosmo
# Download a specific version (e.g., 4.0.2)
sudo wget https://cosmo.zip/pub/cosmocc/cosmocc-4.0.2.zip
sudo unzip cosmocc-4.0.2.zip
sudo rm cosmocc-4.0.2.zip
sudo chmod +x bin/cosmocc bin/cosmoar
# Verify installation
/opt/cosmo/bin/cosmocc --versionIf you want the absolute latest version or need to customize:
# Clone the repository
git clone https://github.com/jart/cosmopolitan.git
cd cosmopolitan
# Build (this will take a while)
make -j$(nproc)
# Install to /opt/cosmo
sudo make install PREFIX=/opt/cosmoIf you prefer to install elsewhere:
# Install to your home directory
mkdir -p ~/local/cosmo
cd ~/local/cosmo
# Download and extract binaries
wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
unzip cosmocc.zip
rm cosmocc.zip
# Make them executable
chmod +x bin/cosmocc bin/cosmoar
# Set COSMO_DIR when building
export COSMO_DIR=~/local/cosmogit clone <repository-url>
cd <repository-name># If Cosmopolitan is in /opt/cosmo (default)
make
# If Cosmopolitan is elsewhere
make COSMO_DIR=/path/to/cosmo
# Or set environment variable
export COSMO_DIR=/path/to/cosmo
make./app.comThe .com extension is part of the Actually Portable Executable format. Despite the extension, this works on:
- Linux (x86_64, ARM64)
- Windows (x86_64)
- macOS (x86_64, ARM64)
- FreeBSD
- OpenBSD
- NetBSD
For quick development iterations without Cosmopolitan:
make dev
./appThis builds a standard Linux executable for faster compilation during development.
# Verify cosmocc is installed
/opt/cosmo/bin/cosmocc --version
# Or if in PATH
cosmocc --version# Clean build
make clean
make
# Should produce app.com
ls -lh app.com
# Test run
./app.comExpected output:
=== Cosmopolitan Web Application ===
Build: Nov 3 2025 07:10:02
Starting initialization...
Database initialized: app.db (stub)
Running database migrations (stub)
Router initialized
Board module initialized
...
Server ready!
Listening on: http://localhost:8080
Press Ctrl+C to stop
Solution 1: Ensure Cosmopolitan is installed:
ls -l /opt/cosmo/bin/cosmoccSolution 2: Set COSMO_DIR:
export COSMO_DIR=/path/to/your/cosmopolitan
makeSolution 3: Use development build:
make dev # Uses GCC insteadSolution: Make the binary executable:
chmod +x app.com
./app.comSolution 1: Try using curl instead of wget:
# Use curl to download
curl -O https://cosmo.zip/pub/cosmocc/cosmocc.zip
unzip cosmocc.zipSolution 2: Build from source (see Method 3 above)
Solution: Ensure you have a complete Cosmopolitan installation:
# Reinstall from the official zip
cd /opt/cosmo
sudo rm -rf *
sudo wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
sudo unzip cosmocc.zip
sudo rm cosmocc.zip
sudo chmod +x bin/cosmocc bin/cosmoarSolution: Windows users should use WSL2 for building. The resulting .com file will run natively on Windows without WSL.
Solution: On first run, macOS may block the executable:
# Allow the binary
xattr -d com.apple.quarantine app.com
./app.comEverything should work out of the box. Most distributions include all necessary dependencies.
Option 1: Build in WSL2, then run the .com file in Windows:
# In WSL2
make
cp app.com /mnt/c/Users/YourName/Desktop/
# In Windows (Command Prompt or PowerShell)
cd C:\Users\YourName\Desktop
app.comOption 2: Use pre-built binaries (if available)
On Apple Silicon (M1/M2/M3):
# Should work with Rosetta 2 or native ARM64 build
make
./app.comOn Intel Macs:
# Standard build process
make
./app.com# Install GNU make if needed
pkg install gmake # FreeBSD
pkg_add gmake # OpenBSD
pkgin install gmake # NetBSD
# Build with gmake
gmake
./app.comCosmopolitan binaries are naturally cross-platform, but if you need specific optimization:
# Build optimized for size
make CFLAGS="-Os -Wall -Wextra -std=c11 -Isrc"
# Build with debug symbols
make CFLAGS="-g -O0 -Wall -Wextra -std=c11 -Isrc"# Build with specific Cosmopolitan version
make COSMO_DIR=/opt/cosmo-v2.0
# Build with additional flags
make CFLAGS="-O3 -march=native -Wall -Wextra -std=c11 -Isrc"
# Build with custom target name
make TARGET=myapp.comAfter successful installation:
- Read README.md for project documentation
- Review CONTRIBUTING.md for development guidelines
- Start the server:
./app.com - Access the application at
http://localhost:8080
- Cosmopolitan Libc Documentation
- Cosmopolitan GitHub Repository
- Actually Portable Executable Format
- Project README
- Contributing Guidelines
If you encounter issues:
- Check this troubleshooting section
- Review Cosmopolitan documentation
- Search existing issues in the project repository
- Create a new issue with:
- Your OS and version
- Cosmopolitan version (
cosmocc --version) - Full error message
- Steps to reproduce