Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/moonrepo/moon/llms.txt

Use this file to discover all available pages before exploring further.

The moon teardown command, as its name infers, will teardown and clean the current environment, opposite the setup command. It achieves this by doing the following:
  • Uninstalling all configured toolchains
  • Removing any download or temporary files/folders
$ moon teardown
Output:
▪▪▪▪ Tearing down and uninstalling toolchains...
✓ Toolchains have been torn down!

How It Works

The teardown command:
  1. Identifies toolchains - Reads configured toolchains from .moon/toolchains.*
  2. Calls teardown hooks - Executes teardown logic for each toolchain plugin
  3. Uninstalls versions - Removes installed toolchain versions via proto
  4. Cleans artifacts - Removes temporary files and downloads

What Gets Removed

Toolchain Installations

Removes installed versions from ~/.proto/tools/:
  • Node.js installations and npm/yarn/pnpm
  • Rust installations and cargo
  • Go installations
  • Python installations
  • Deno installations
  • Bun installations
  • Custom toolchains

Temporary Files

Cleans up:
  • Download caches
  • Temporary build files
  • Installation artifacts
  • Shim/wrapper scripts

What Gets Kept

Workspace Cache

The teardown command does NOT remove:
  • .moon/cache/ directory
  • Task outputs and artifacts
  • Hash manifests
  • Workspace state
Use moon clean to remove cache.

Configuration

All configuration files remain:
  • .moon/toolchains.yml
  • .moon/workspace.yml
  • Project moon.yml files

Source Code

Your source code and dependencies are untouched:
  • node_modules/
  • Cargo.lock / target/
  • Project files

When to Use

Use moon teardown when you want to:

Clean Development Environment

# Remove all toolchains
$ moon teardown

# Start fresh
$ moon setup

Switch Toolchain Versions

# Remove old versions
$ moon teardown

# Update .moon/toolchains.yml
# Then reinstall
$ moon setup

Troubleshoot Installation Issues

# Clean slate
$ moon teardown

# Try again
$ moon setup

Free Disk Space

# Uninstall toolchains
$ moon teardown

# Clean cache too
$ moon clean --all

CI/CD Usage

In CI environments, teardown is rarely needed since:
  • Runners are typically ephemeral
  • Toolchains are installed fresh each run
  • Cleanup happens automatically
However, for persistent runners:
# GitHub Actions self-hosted runner
jobs:
  build:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup
        run: moon setup
      
      - name: Build
        run: moon run build
      
      - name: Cleanup
        if: always()
        run: moon teardown

Comparison with Other Commands

moon teardown vs moon clean

  • moon teardown - Uninstalls toolchains, removes binaries
  • moon clean - Removes workspace cache, task outputs
Use both for complete cleanup:
$ moon teardown && moon clean --all

moon teardown vs moon setup

  • moon teardown - Removes toolchains
  • moon setup - Installs toolchains
They are opposite operations:
# Uninstall
$ moon teardown

# Reinstall
$ moon setup

System vs Managed Toolchains

If you use system-installed toolchains:
# .moon/toolchains.yml
node:
  version: 'system'
Then moon teardown:
  • Will NOT uninstall system toolchains
  • Only cleans moon-managed installations
  • System Node.js, Rust, etc. remain untouched

Examples

Basic teardown

$ moon teardown

Complete cleanup

# Remove toolchains and cache
$ moon teardown
$ moon clean --all

Reset and reinstall

# Clean everything
$ moon teardown

# Reinstall toolchains
$ moon setup

# Verify
$ moon check --all

CI cleanup job

# .github/workflows/cleanup.yml
name: Weekly Cleanup

on:
  schedule:
    - cron: '0 0 * * 0' # Every Sunday

jobs:
  cleanup:
    runs-on: self-hosted
    steps:
      - name: Teardown
        run: moon teardown
      
      - name: Clean cache
        run: moon clean --all

Safety

The teardown command is safe to run:
  • Does not affect system installations
  • Does not remove configuration
  • Does not delete source code
  • Does not remove dependencies (node_modules, etc.)
You can always reinstall with moon setup.

Troubleshooting

Teardown Fails

If teardown fails:
  1. Check if processes are using the toolchains
  2. Close editors, terminals, running tasks
  3. Try manual cleanup:
    rm -rf ~/.proto/tools/*
    
  4. Check file permissions

Partial Teardown

If some toolchains fail to uninstall:
  • Other toolchains are still removed
  • Check error messages
  • May need manual intervention
  • System toolchains require manual removal

Configuration

See Also