ollama - 💡(How to fix) Fix Windows BAT script for installing/deleting GGUF models (CLI wrapper utility) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15742Fetched 2026-04-23 07:23:29
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Error Message

@echo off setlocal enabledelayedexpansion

:: Use filename as model name set "MODEL_NAME=%~n0" set "MODEL_FILE=%MODEL_NAME%.gguf" set "TEMP_MODELF=Modelfile_%MODEL_NAME%"

:MENU cls echo ============================================ echo Ollama Manager - Model: %MODEL_NAME% echo ============================================ echo 1. Install/Update model echo 2. Delete model echo 3. Exit echo ============================================ set /p "choice=Choose option (1-3): "

if "%choice%"=="1" goto INSTALL if "%choice%"=="2" goto DELETE if "%choice%"=="3" goto :EOF goto MENU

:INSTALL echo. echo [1/3] Checking for %MODEL_FILE%...

if not exist "%MODEL_FILE%" ( echo ERROR: "%MODEL_FILE%" not found in this folder. pause goto MENU )

if exist "%TEMP_MODELF%" del "%TEMP_MODELF%" >nul 2>&1

echo [2/3] Creating Modelfile... ( echo FROM "./%MODEL_FILE%" echo # Optional: TEMPLATE / PARAMETER lines ) > "%TEMP_MODELF%"

echo [3/3] Installing into Ollama... ollama create "%MODEL_NAME%" -f "%TEMP_MODELF%" set RESULT=%errorlevel%

del "%TEMP_MODELF%" >nul 2>&1

if not "%RESULT%"=="0" ( echo. echo ERROR: Failed to create model. Ensure Ollama is running. ) else ( echo. echo SUCCESS: Model "%MODEL_NAME%" is ready! )

pause goto MENU

:DELETE echo. echo Checking for existing model...

ollama list | findstr /i "%MODEL_NAME%" >nul if errorlevel 1 ( echo Model "%MODEL_NAME%" is not currently installed. pause goto MENU )

echo. echo WARNING: This will permanently delete "%MODEL_NAME%". set /p "confirm=Are you sure? (Y/N): "

if /i not "%confirm%"=="Y" ( echo Deletion cancelled. pause goto MENU )

echo Deleting... ollama rm %MODEL_NAME%

if errorlevel 1 ( echo ERROR: Failed to remove model. ) else ( echo Model "%MODEL_NAME%" removed successfully. )

pause goto MENU

Code Example

@echo off
setlocal enabledelayedexpansion

:: Use filename as model name
set "MODEL_NAME=%~n0"
set "MODEL_FILE=%MODEL_NAME%.gguf"
set "TEMP_MODELF=Modelfile_%MODEL_NAME%"

:MENU
cls
echo ============================================
echo   Ollama Manager - Model: %MODEL_NAME%
echo ============================================
echo  1. Install/Update model
echo  2. Delete model
echo  3. Exit
echo ============================================
set /p "choice=Choose option (1-3): "

if "%choice%"=="1" goto INSTALL
if "%choice%"=="2" goto DELETE
if "%choice%"=="3" goto :EOF
goto MENU

:INSTALL
echo.
echo [1/3] Checking for %MODEL_FILE%...

if not exist "%MODEL_FILE%" (
    echo ERROR: "%MODEL_FILE%" not found in this folder.
    pause
    goto MENU
)

if exist "%TEMP_MODELF%" del "%TEMP_MODELF%" >nul 2>&1

echo [2/3] Creating Modelfile...
(
    echo FROM "./%MODEL_FILE%"
    echo # Optional: TEMPLATE / PARAMETER lines
) > "%TEMP_MODELF%"

echo [3/3] Installing into Ollama...
ollama create "%MODEL_NAME%" -f "%TEMP_MODELF%"
set RESULT=%errorlevel%

del "%TEMP_MODELF%" >nul 2>&1

if not "%RESULT%"=="0" (
    echo.
    echo ERROR: Failed to create model. Ensure Ollama is running.
) else (
    echo.
    echo SUCCESS: Model "%MODEL_NAME%" is ready!
)

pause
goto MENU

:DELETE
echo.
echo Checking for existing model...

ollama list | findstr /i "%MODEL_NAME%" >nul
if errorlevel 1 (
    echo Model "%MODEL_NAME%" is not currently installed.
    pause
    goto MENU
)

echo.
echo WARNING: This will permanently delete "%MODEL_NAME%".
set /p "confirm=Are you sure? (Y/N): "

if /i not "%confirm%"=="Y" (
    echo Deletion cancelled.
    pause
    goto MENU
)

echo Deleting...
ollama rm %MODEL_NAME%

if errorlevel 1 (
    echo ERROR: Failed to remove model.
) else (
    echo Model "%MODEL_NAME%" removed successfully.
)

pause
goto MENU
RAW_BUFFERClick to expand / collapse

This is a simple Windows batch utility that wraps Ollama CLI commands for managing GGUF-based models.

@echo off
setlocal enabledelayedexpansion

:: Use filename as model name
set "MODEL_NAME=%~n0"
set "MODEL_FILE=%MODEL_NAME%.gguf"
set "TEMP_MODELF=Modelfile_%MODEL_NAME%"

:MENU
cls
echo ============================================
echo   Ollama Manager - Model: %MODEL_NAME%
echo ============================================
echo  1. Install/Update model
echo  2. Delete model
echo  3. Exit
echo ============================================
set /p "choice=Choose option (1-3): "

if "%choice%"=="1" goto INSTALL
if "%choice%"=="2" goto DELETE
if "%choice%"=="3" goto :EOF
goto MENU

:INSTALL
echo.
echo [1/3] Checking for %MODEL_FILE%...

if not exist "%MODEL_FILE%" (
    echo ERROR: "%MODEL_FILE%" not found in this folder.
    pause
    goto MENU
)

if exist "%TEMP_MODELF%" del "%TEMP_MODELF%" >nul 2>&1

echo [2/3] Creating Modelfile...
(
    echo FROM "./%MODEL_FILE%"
    echo # Optional: TEMPLATE / PARAMETER lines
) > "%TEMP_MODELF%"

echo [3/3] Installing into Ollama...
ollama create "%MODEL_NAME%" -f "%TEMP_MODELF%"
set RESULT=%errorlevel%

del "%TEMP_MODELF%" >nul 2>&1

if not "%RESULT%"=="0" (
    echo.
    echo ERROR: Failed to create model. Ensure Ollama is running.
) else (
    echo.
    echo SUCCESS: Model "%MODEL_NAME%" is ready!
)

pause
goto MENU

:DELETE
echo.
echo Checking for existing model...

ollama list | findstr /i "%MODEL_NAME%" >nul
if errorlevel 1 (
    echo Model "%MODEL_NAME%" is not currently installed.
    pause
    goto MENU
)

echo.
echo WARNING: This will permanently delete "%MODEL_NAME%".
set /p "confirm=Are you sure? (Y/N): "

if /i not "%confirm%"=="Y" (
    echo Deletion cancelled.
    pause
    goto MENU
)

echo Deleting...
ollama rm %MODEL_NAME%

if errorlevel 1 (
    echo ERROR: Failed to remove model.
) else (
    echo Model "%MODEL_NAME%" removed successfully.
)

pause
goto MENU

Purpose:

  • Install a local GGUF model into Ollama using a double-click BAT file
  • Delete installed models safely with confirmation
  • Avoid manual CLI usage for basic model management on Windows

How it works:

  • Uses filename as model name (example: model.bat + model.gguf)
  • Creates temporary Modelfile internally
  • Runs: ollama create / ollama rm
  • Provides install/delete menu interface

Limitations:

  • Requires Ollama installed and available in PATH
  • Assumes .gguf filename matches model name
  • Does not integrate with Ollama UI or API
  • Pure CLI wrapper (Windows BAT only)

This is shared as a lightweight utility for Windows users who manage local GGUF models manually.

If not appropriate for the main repo, feel free to close or redirect to a more suitable place.

extent analysis

TL;DR

To improve the utility, consider adding error handling for cases where the Ollama CLI commands fail due to reasons other than the model not being installed or the command not being recognized.

Guidance

  • Verify that the Ollama CLI is properly installed and available in the system's PATH to ensure the ollama commands work as expected.
  • Consider adding a check to ensure the .gguf file is a valid GGUF model before attempting to install it.
  • Implement more robust error handling for the ollama create and ollama rm commands to provide informative error messages instead of generic failure notifications.
  • Review the script's assumptions about the model name and file name matching, and consider adding flexibility or validation to handle potential discrepancies.

Example

:INSTALL
...
if not "%RESULT%"=="0" (
    echo.
    echo ERROR: Failed to create model. Ensure Ollama is running and the model file is valid.
    echo Error code: %RESULT%
)

Notes

The provided script seems to be a straightforward wrapper around Ollama CLI commands. However, its reliability and user experience could be improved with more comprehensive error handling and validation.

Recommendation

Apply workaround: Enhance the script with additional error handling and validation checks to make it more robust and user-friendly. This approach allows for a more reliable and informative experience when managing GGUF models with the utility.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING