#!/usr/bin/env bash # Inside The Machine · one-command install: Mem0 # A memory layer for agents that can run fully local with Ollama and Qdrant. # Page: https://insidethemachine.ai/setups/mem0 Agent doc: https://insidethemachine.ai/install/mem0.md # Run status: Not run: commands checked against the official docs only. Commands checked against the official docs on 2026-10-15. Not run end to end. # This script: The wrapper scripts are generated from the site data. Every .sh passed bash -n and shellcheck and ran in plan mode on Linux (Debian 13). Every .ps1 passed the PowerShell parser and chat.ps1 ran in plan, verify and rollback mode under PowerShell 7 on Linux with Windows calls mocked. Not run on macOS or real Windows. # # Read it first: curl -fsSL https://insidethemachine.ai/install/mem0.sh | less # curl -fsSL https://insidethemachine.ai/install/mem0.sh | bash install, then check # curl -fsSL https://insidethemachine.ai/install/mem0.sh | bash -s -- plan print every step, run nothing # curl -fsSL https://insidethemachine.ai/install/mem0.sh | bash -s -- verify only the checks # curl -fsSL https://insidethemachine.ai/install/mem0.sh | bash -s -- rollback --yes undo it (without --yes it only prints) # Options: ITM_RAM=32 (memory in GB instead of detecting it) # Lines marked YOU RUN are left to you: servers that keep running, interactive apps, your own files. # shellcheck disable=SC2016,SC1090 set -u main() { ACT="${ITM_ACTION:-install}"; YES="${ITM_YES:-}" for a in "$@"; do case "$a" in --yes|-y) YES=1 ;; install|plan|verify|rollback) ACT="$a" ;; *) echo "unknown option: $a (use install, plan, verify or rollback)" >&2; exit 2 ;; esac; done START="$(pwd)"; FAILS=0; NEXT="" case "$(uname -s)" in Darwin) P=mac ;; Linux) P=linux ;; *) P=other ;; esac say() { printf '\n== %s\n' "$1"; } note() { printf ' # %s\n' "$1"; } die() { printf '\nSTOP: %s\nHelp: %s\n' "$1" 'https://insidethemachine.ai/setups/mem0' >&2; exit 1; } run() { printf ' $ %s\n' "$1"; [ "$ACT" = plan ] && return 0; eval "$1" || die "this step failed: $1"; } mac() { if [ "$P" != mac ]; then printf ' (macOS only, skipped: use your package manager) %s\n' "$1"; return 0; fi case "$1" in xcode-select*) printf ' $ %s\n' "$1"; [ "$ACT" = plan ] || xcode-select -p >/dev/null 2>&1 || die "install Apple's command line tools first: run xcode-select --install, finish the window, then run this again"; return 0 ;; brew*) [ "$ACT" = plan ] || command -v brew >/dev/null 2>&1 || die "needs Homebrew first: https://brew.sh" ;; esac run "$1"; } you() { printf ' YOU RUN: %s\n' "$1"; [ -n "$2" ] && printf ' (%s)\n' "$2"; NEXT="$NEXT $1\n"; } undo() { if [ "${2:-}" = mac ] && [ "$P" != mac ]; then return 0; fi; printf ' $ %s\n' "$1"; if [ "$ACT" = rollback ] && [ -n "$YES" ]; then eval "$1" || echo " (failed, carrying on)"; fi; } check() { printf ' ? %s\n expect: %s\n' "$1" "$2"; [ "$ACT" = plan ] && return 0; if out=$(eval "$1" 2>&1) && ! printf '%s' "$out" | grep -q '^{"error"'; then echo " PASS"; else echo " FAIL"; FAILS=$((FAILS + 1)); fi; [ -n "$out" ] && printf '%s\n' "$out" | head -n 3 | sed 's/^/ | /'; return 0; } need_ollama() { [ "$ACT" = plan ] && return 0; ollama list >/dev/null 2>&1 && return 0; echo " starting 'ollama serve' in the background (log: /tmp/itm-ollama.log)"; nohup ollama serve >/tmp/itm-ollama.log 2>&1 & i=0; while [ $i -lt 30 ]; do sleep 1; ollama list >/dev/null 2>&1 && return 0; i=$((i + 1)); done; die "Ollama is not running. Open the Ollama app, then run this again."; } [ "$P" = other ] && die "this script is for macOS and Linux." install_mac() { say '1. Install Mem0' run 'python3 -m venv ~/.venvs/mem0 && source ~/.venvs/mem0/bin/activate' run 'pip install mem0ai' need_ollama run 'ollama pull llama3.1:latest && ollama pull nomic-embed-text:latest' you 'docker run -d -p 6333:6333 --name qdrant qdrant/qdrant' 'needs Docker; starts a container' say '2. Configure (your choices)' you 'cat > mem0_local.py <<'\''EOF'\'' from mem0 import Memory config = { "vector_store": {"provider": "qdrant", "config": {"collection_name": "test", "host": "localhost", "port": 6333, "embedding_model_dims": 768}}, "llm": {"provider": "ollama", "config": {"model": "llama3.1:latest", "temperature": 0, "max_tokens": 2000, "ollama_base_url": "http://localhost:11434"}}, "embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text:latest", "ollama_base_url": "http://localhost:11434"}}, } m = Memory.from_config(config) m.add("I'\''m visiting Paris", user_id="john") print(m.get_all(filters={"user_id": "john"})) EOF' 'config adapted verbatim from Mem0'\''s '\''Self-Hosted AI Companion'\'' cookbook' } verify_mac() { say 'Check' you 'python mem0_local.py' 'check by hand: prints a results list containing a memory about visiting Paris' } rollback_mac() { say 'Rollback' undo 'pip uninstall -y mem0ai' undo 'docker rm -f qdrant' undo 'rm mem0_local.py' } install_linux() { say '1. Linux: same steps as macOS' note 'Our data lists Linux as supported but has no separate Linux steps, so these are the macOS steps. brew lines are skipped; install those tools with your package manager.' say '2. Install Mem0' run 'python3 -m venv ~/.venvs/mem0 && source ~/.venvs/mem0/bin/activate' run 'pip install mem0ai' need_ollama run 'ollama pull llama3.1:latest && ollama pull nomic-embed-text:latest' you 'docker run -d -p 6333:6333 --name qdrant qdrant/qdrant' 'needs Docker; starts a container' say '3. Configure (your choices)' you 'cat > mem0_local.py <<'\''EOF'\'' from mem0 import Memory config = { "vector_store": {"provider": "qdrant", "config": {"collection_name": "test", "host": "localhost", "port": 6333, "embedding_model_dims": 768}}, "llm": {"provider": "ollama", "config": {"model": "llama3.1:latest", "temperature": 0, "max_tokens": 2000, "ollama_base_url": "http://localhost:11434"}}, "embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text:latest", "ollama_base_url": "http://localhost:11434"}}, } m = Memory.from_config(config) m.add("I'\''m visiting Paris", user_id="john") print(m.get_all(filters={"user_id": "john"})) EOF' 'config adapted verbatim from Mem0'\''s '\''Self-Hosted AI Companion'\'' cookbook' } verify_linux() { say 'Check' you 'python mem0_local.py' 'check by hand: prints a results list containing a memory about visiting Paris' } rollback_linux() { say 'Rollback' undo 'pip uninstall -y mem0ai' undo 'docker rm -f qdrant' undo 'rm mem0_local.py' } act() { [ -f ~/.venvs/mem0/bin/activate ] && . ~/.venvs/mem0/bin/activate; return 0; } inwd() { return 0; } V=$P printf 'Inside The Machine · Mem0 · %s · %s%s\n' "$ACT" "$P" "" case "$ACT" in install|plan) "install_$V"; cd "$START" || exit 1; act; inwd; "verify_$V"; cd "$START" || exit 1; [ "$ACT" = plan ] && "rollback_$V" ;; verify) act; inwd; "verify_$V" ;; rollback) [ -n "$YES" ] || note 'print only: add --yes to run these'; act; "rollback_$V" ;; esac if [ -n "$NEXT" ]; then say 'Now you run these (in order)'; printf '%b' "$NEXT"; fi [ "$ACT" = install ] && printf '\nDone. %s check(s) failed. Next steps and fixes: %s\n' "$FAILS" 'https://insidethemachine.ai/setups/mem0' [ "$FAILS" -eq 0 ] } main "$@"