#!/bin/sh # This script installs Ollama on Linux. # It detects the current operating system architecture and installs the appropriate version of Ollama. set -eu status() { echo ">>> $*" >&2; } error() { echo "ERROR $*"; exit 1; } warning() { echo "WARNING: $*"; } TEMP_DIR=$(mktemp -d) cleanup() { rm -rf $TEMP_DIR; } trap cleanup EXIT available() { command -v $1 >/dev/null; } require() { local MISSING='' for TOOL in $*; do if ! available $TOOL; then MISSING="$MISSING $TOOL" fi done echo $MISSING } [ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.' ARCH=arm64 KERN=$(uname -r) case "$KERN" in *icrosoft*WSL2 | *icrosoft*wsl2) ;; *icrosoft) error "Microsoft WSL1 is not currently supported. Please upgrade to WSL2 with 'wsl --set-version 2'" ;; *) ;; esac VER_PARAM="${OLLAMA_VERSION:+?version=$OLLAMA_VERSION}" SUDO="sudo" NEEDS=$(require curl awk grep sed tee xargs) if [ -n "$NEEDS" ]; then status "ERROR: The following tools are required but missing:" for NEED in $NEEDS; do echo " - $NEED" done exit 1 fi status "Downloading ollama..." curl --fail --show-error --location --progress-bar -o $TEMP_DIR/ollama "https://ollama.com/download/ollama-linux-${ARCH}${VER_PARAM}" for BINDIR in /usr/local/bin /usr/bin /bin; do echo $PATH | grep -q $BINDIR && break || continue done status "Installing ollama to $BINDIR..." $SUDO install -o0 -g0 -m755 -d $BINDIR $SUDO install -o0 -g0 -m755 $TEMP_DIR/ollama $BINDIR/ollama install_success() { status 'The Ollama API is now available at 127.0.0.1:11434.' status 'Install complete. Run "ollama" from the command line.' } trap install_success EXIT