Skip to content

Instantly share code, notes, and snippets.

@dschaehi
Last active October 28, 2024 15:06
Show Gist options
  • Save dschaehi/5c7260b3f014b16b4ed71618238a2078 to your computer and use it in GitHub Desktop.
Save dschaehi/5c7260b3f014b16b4ed71618238a2078 to your computer and use it in GitHub Desktop.
A script for updating ollama manually installed without the sudo privilige
#!/usr/bin/env sh
client_version=$(ollama -v | grep -oP 'version is \K[0-9.]+')
latest_version=$(git ls-remote --tags --sort="v:refname" https://github.com/ollama/ollama.git | grep -E 'refs/tags/v?[0-9]+\.[0-9]+\.[0-9]+$' | tail -n1 | sed 's/.*\/v*//')
echo Client version is $client_version
echo Latest version is $latest_version
if [ "$(printf '%s\n' "$client_version" "$latest_version" | sort -V | head -n1)" != "$latest_version" ]; then
OLLAMA_CACHE="$XDG_CACHE_HOME/ollama"
OLLAMA="$XDG_OPT_HOME/ollama"
mkdir -p $OLLAMA_CACHE
mkdir -p $OLLAMA
# https://github.com/ollama/ollama/blob/main/docs/linux.md#manual-install
echo "Update available: Latest version is $latest_version, but client version is $client_version."
curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o $OLLAMA_CACHE/ollama-linux-amd64.tgz
tar -C $OLLAMA -xzf $OLLAMA_CACHE/ollama-linux-amd64.tgz
rm $OLLAMA_CACHE/ollama-linux-amd64.tgz
# symlink ollama to ~/.local/bin
rm $XDG_BIN_HOME/ollama
ln -s $OLLAMA/bin/ollama $XDG_BIN_HOME/
else
echo "Client is up-to-date with version $client_version."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment