Take Windows system as an example, the models pulled by Ollama are stored in C disk by default, if you need to pull more than one model, the C disk will be full, which affects the storage space of C disk.
Therefore, this section describes how you can customize the Ollama The location where the model is stored.
Windows (computer)
If no additional action is taken when downloading Ollama, the model will be downloaded by default to the
C:\Users\\.ollama\models
If you don't want to put it on the C drive, at this point we create the folder where the custom model will be downloaded and copy the path, such as
D:\Ollama\Models
Note: Paths should be created in advance and contain no Chinese characters or spaces.
For different situations, the following strategies can be adopted 👀
Before installing Ollama for the first time, manually set the model download path.
II. Modifying system environment variables (recommended)
III. Migration of existing model documents
I. Manually set the model download path when installing Ollama for the first time.
Customized installation path (on first installation)
. \OllamaSetup.exe /DIR="D:\Ollama\Models"
strike (on the keyboard) Install
After that, you can see that the software is installed in the custom path folder, and the model will be downloaded to the custom folder by default.
II. Modifying system environment variables (recommended)
Scenario: It is recommended to change the storage location of the model directly after the installation of Ollama is completed or you want the newly downloaded model to be stored directly in the new location.
- Setting environment variables
Win + S
→ Enter "Environment Variables" → Select "Edit System Environment Variables" → Click the "Environment Variables" button.- system variable → newly built → Input:
- variable name ::
OLLAMA_MODELS
- variable value : Customized paths (e.g.
D:\Ollama\Models
)
- reopen Ollama go into effect
- Restart the Ollama service (right-click icon in the taskbar →
Quit Ollama
(and then reboot)
III. Migration of existing model documents
Downloaded models need to be moved to a new location
- cessation Ollama step
Finding the process IDtasklist | findstr ollama
Termination of processes
taskkill /F /IM ollama.exe
- Migration model files
- commander-in-chief (military)
C:\Users\\.ollama\models
folder to a new location (e.g.D:\Ollama\Models
) and free up storage space - ❗ Backup Data : Recommended backups before migration
C:\Users\\.ollama
file (paper)
- Creating Environment Variables
- Setting by Method 2
OLLAMA_MODELS
Points to a new path (e.g.D:\Ollama\Models
)
- Setting by Method 2
- reopen Ollama go into effect
Check the list of models, if it shows models that have been downloaded, then the model migration was successful 🎉ollama list
Linux
On Linux systems, models pulled by Ollama are stored by default in the .ollama/models folder in the user's home directory, usually at the path ~/.ollama/models. If you wish to store the models in a different location, you can do so in several ways.
I. Manually set the model download path
Scenario: First time installation
On Linux systems, Ollama is usually installed via a package manager or a script. If you need to specify the storage path of the model during installation, you can do so by setting an environment variable.
- Setting environment variables: Before installing Ollama, set the
OLLAMA_MODELS
environment variable that specifies the storage path for the model. Open a terminal and enter the following command:
export OLLAMA_MODELS=/path/to/your/custom/models
commander-in-chief (military) /path/to/your/custom/models
Replace the path with the one you want, e.g. /home/username/Ollama/Models
The
- Installing Ollama: Follow the normal procedure for installing Ollama. once the installation is complete, the model will be automatically downloaded to the specified custom path.
II. Modifying system environment variables (recommended)
Scenario: After the installation of Ollama is completed, you want to change the storage location of the model directly, or you want to store the newly downloaded model in a new location.
- Setting Environment Variables Edit
~/.bashrc
maybe~/.zshrc
file (depending on the shell you are using), add the following:
export OLLAMA_MODELS=/path/to/your/custom/models
Replace /path/to/your/custom/models with the path you want, e.g. /home/username/Ollama/Models.
- Save the file and reload the configuration:
source ~/.bashrc
maybe
source ~/.zshrc
- Restarting the Ollama Service
If Ollama is already started, the service can be restarted with the following command:
ollama quit
ollama start
III. Migration of existing model documents
Scenario: downloaded models need to be migrated to a new location
- Close Ollama
- Migration modeling files: to be
~/.ollama/models
folder to a new location (e.g./home/username/Ollama/Models
) and free up storage space:
mv ~/.ollama/models /path/to/your/custom/models
commander-in-chief (military) /path/to/your/custom/models
Replace it with your target path.
❗ Backup data: It is recommended to backup the ~/.ollama folder before migration.
- Setting environment variables: follow method 2
OLLAMA_MODELS
Pointing to new paths. - Restart Ollama Service: Start Ollama and check the model list to confirm that the model migration was successful:
ollama start
ollama list
With the above methods, you can flexibly customize the storage location of Ollama models on Linux systems to avoid taking up too much default storage space.
MacOS
The default download model location for Ollama on Mac systems is
~/.ollama/models/blobs
(as shown below). As with Windows and Linux, Mac systems are also configured by setting theOLLAMA_MODELS
variable to control the model download path, we can set the download path in two ways.
I. Temporary change of download path
utilization launchctl setenv
set up OLLAMA_MODELS
The effect of this command is temporary, i.e., it is lost after the computer is rebooted or the account is logged off.
launchctl setenv OLLAMA_MODELS "/Users/lta/Desktop/models"
After setting the environment variables you can set the environment variables by using thelaunchctl getenv OLLAMA_MODELS
View the current environment variables.
Changing environment variables
Test after changing environment variables
When you want to cancel a previously set variable you can do so by using the launchctl unsetenv OLLAMA_MODELS
command to reset.
II. Change the download path permanently
- pass (a bill or inspection etc)
nano ~/.zshrc
Command Editor~/.zshrc
file - Add to the file
export OLLAMA_MODELS="/Users/lta/Desktop/models"
The - After saving and exiting the editor run
source ~/.zshrc
to make it effective is sufficient.
Remember to restart Ollama after changing the path.