ollama/docs/linux.md

200 lines
4.2 KiB
Markdown
Raw Normal View History

# Linux
2023-09-25 12:34:44 +08:00
2023-10-26 05:47:49 +08:00
## Install
2023-09-25 12:38:23 +08:00
To install Ollama, run the following command:
```shell
curl -fsSL https://ollama.com/install.sh | sh
2023-09-25 12:38:23 +08:00
```
## Manual install
build: Make target improvements (#7499) * llama: wire up builtin runner This adds a new entrypoint into the ollama CLI to run the cgo built runner. On Mac arm64, this will have GPU support, but on all other platforms it will be the lowest common denominator CPU build. After we fully transition to the new Go runners more tech-debt can be removed and we can stop building the "default" runner via make and rely on the builtin always. * build: Make target improvements Add a few new targets and help for building locally. This also adjusts the runner lookup to favor local builds, then runners relative to the executable, and finally payloads. * Support customized CPU flags for runners This implements a simplified custom CPU flags pattern for the runners. When built without overrides, the runner name contains the vector flag we check for (AVX) to ensure we don't try to run on unsupported systems and crash. If the user builds a customized set, we omit the naming scheme and don't check for compatibility. This avoids checking requirements at runtime, so that logic has been removed as well. This can be used to build GPU runners with no vector flags, or CPU/GPU runners with additional flags (e.g. AVX512) enabled. * Use relative paths If the user checks out the repo in a path that contains spaces, make gets really confused so use relative paths for everything in-repo to avoid breakage. * Remove payloads from main binary * install: clean up prior libraries This removes support for v0.3.6 and older versions (before the tar bundle) and ensures we clean up prior libraries before extracting the bundle(s). Without this change, runners and dependent libraries could leak when we update and lead to subtle runtime errors.
2024-12-11 01:47:19 +08:00
> [!NOTE]
> If you are upgrading from a prior version, you **MUST** remove the old libraries with `sudo rm -rf /usr/lib/ollama` first.
build: Make target improvements (#7499) * llama: wire up builtin runner This adds a new entrypoint into the ollama CLI to run the cgo built runner. On Mac arm64, this will have GPU support, but on all other platforms it will be the lowest common denominator CPU build. After we fully transition to the new Go runners more tech-debt can be removed and we can stop building the "default" runner via make and rely on the builtin always. * build: Make target improvements Add a few new targets and help for building locally. This also adjusts the runner lookup to favor local builds, then runners relative to the executable, and finally payloads. * Support customized CPU flags for runners This implements a simplified custom CPU flags pattern for the runners. When built without overrides, the runner name contains the vector flag we check for (AVX) to ensure we don't try to run on unsupported systems and crash. If the user builds a customized set, we omit the naming scheme and don't check for compatibility. This avoids checking requirements at runtime, so that logic has been removed as well. This can be used to build GPU runners with no vector flags, or CPU/GPU runners with additional flags (e.g. AVX512) enabled. * Use relative paths If the user checks out the repo in a path that contains spaces, make gets really confused so use relative paths for everything in-repo to avoid breakage. * Remove payloads from main binary * install: clean up prior libraries This removes support for v0.3.6 and older versions (before the tar bundle) and ensures we clean up prior libraries before extracting the bundle(s). Without this change, runners and dependent libraries could leak when we update and lead to subtle runtime errors.
2024-12-11 01:47:19 +08:00
Download and extract the package:
```shell
2025-07-23 02:17:31 +08:00
curl -LO https://ollama.com/download/ollama-linux-amd64.tgz
sudo rm -rf /usr/lib/ollama
sudo tar -C /usr -xzf ollama-linux-amd64.tgz
```
Start Ollama:
```shell
ollama serve
```
2023-09-25 12:34:44 +08:00
In another terminal, verify that Ollama is running:
2023-09-25 12:34:44 +08:00
```shell
ollama -v
```
### AMD GPU install
2023-09-25 12:34:44 +08:00
If you have an AMD GPU, **also** download and extract the additional ROCm package:
> [!IMPORTANT]
> The ROCm tgz contains only AMD dependent libraries. You must extract **both** `ollama-linux-amd64.tgz` and `ollama-linux-amd64-rocm.tgz` into the same location.
```shell
curl -L https://ollama.com/download/ollama-linux-amd64-rocm.tgz -o ollama-linux-amd64-rocm.tgz
sudo tar -C /usr -xzf ollama-linux-amd64-rocm.tgz
2023-09-25 12:34:44 +08:00
```
### ARM64 install
Download and extract the ARM64-specific package:
```shell
curl -L https://ollama.com/download/ollama-linux-arm64.tgz -o ollama-linux-arm64.tgz
sudo tar -C /usr -xzf ollama-linux-arm64.tgz
```
2023-10-26 05:47:49 +08:00
### Adding Ollama as a startup service (recommended)
2023-09-25 12:34:44 +08:00
Create a user and group for Ollama:
2023-09-25 12:34:44 +08:00
```shell
docs, scripts: Prevent useradd(8) from failing on Fedora Silverblue On OSTree based operating systems like Fedora Siverblue [1], the /usr/share directory is part of the read-only /usr mount point. This causes the install.sh script to fail when adding the 'ollama' user with its home directory at /usr/share/ollama, because useradd(8) is unable to create the directory: $ curl -fsSL https://ollama.com/install.sh | sh >>> Installing ollama to /usr/local >>> Downloading Linux amd64 bundle ############################################################### 100.0% >>> Creating ollama user... useradd: cannot create directory /usr/share/ollama >>> The Ollama API is now available at 127.0.0.1:11434. >>> Install complete. Run "ollama" from the command line. The /var/lib directory is an alternative for this, because /var is a read-write mount point. eg., this is used by Geoclue [2] and the GNOME Display Manager [3] for their users' home directories on Linux distributions like Arch, Fedora and Ubuntu. With this change the install.sh script is able to proceed further: $ sh scripts/install.sh >>> Installing ollama to /usr/local >>> Downloading Linux amd64 bundle ############################################################### 100.0% >>> Creating ollama user... >>> Adding ollama user to render group... >>> Adding ollama user to video group... >>> Adding current user to ollama group... >>> Creating ollama systemd service... >>> Enabling and starting ollama service... Created symlink '/etc/systemd/system/default.target.wants/ollama.service' → '/etc/systemd/system/ollama.service'. >>> The Ollama API is now available at 127.0.0.1:11434. >>> Install complete. Run "ollama" from the command line. WARNING: No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode. The install.sh script is able to use /usr/local on Fedora Silverblue, because /usr/local is not considered part of the read-only OS image, and is a symbolic link to /var/usrlocal to make it read-write. [1] https://fedoraproject.org/silverblue/ [2] https://gitlab.freedesktop.org/geoclue/geoclue/-/wikis/home [3] https://wiki.gnome.org/Projects/GDM/ https://github.com/ollama/ollama/pull/12455
2025-09-30 21:31:29 +08:00
sudo useradd -r -s /bin/false -U -m -d /var/lib/ollama ollama
sudo usermod -a -G ollama $(whoami)
2023-09-25 12:34:44 +08:00
```
Create a service file in `/etc/systemd/system/ollama.service`:
```ini
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
2023-09-25 12:34:44 +08:00
[Install]
WantedBy=multi-user.target
2023-09-25 12:34:44 +08:00
```
Then start the service:
```shell
2023-09-25 12:34:44 +08:00
sudo systemctl daemon-reload
sudo systemctl enable ollama
```
2023-09-26 07:10:32 +08:00
### Install CUDA drivers (optional)
2023-10-26 05:47:49 +08:00
[Download and install](https://developer.nvidia.com/cuda-downloads) CUDA.
Verify that the drivers are installed by running the following command, which should print details about your GPU:
```shell
2023-10-26 05:47:49 +08:00
nvidia-smi
```
### Install AMD ROCm drivers (optional)
[Download and Install](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html) ROCm v6.
2023-10-26 05:47:49 +08:00
### Start Ollama
Start Ollama and verify it is running:
2023-10-26 05:47:49 +08:00
```shell
2023-10-26 05:47:49 +08:00
sudo systemctl start ollama
sudo systemctl status ollama
2023-10-26 05:47:49 +08:00
```
> [!NOTE]
> While AMD has contributed the `amdgpu` driver upstream to the official linux
> kernel source, the version is older and may not support all ROCm features. We
> recommend you install the latest driver from
> [AMD](https://www.amd.com/en/support/download/linux-drivers.html) for best support
> of your Radeon GPU.
## Customizing
To customize the installation of Ollama, you can edit the systemd service file or the environment variables by running:
```shell
sudo systemctl edit ollama
```
Alternatively, create an override file manually in `/etc/systemd/system/ollama.service.d/override.conf`:
```ini
[Service]
Environment="OLLAMA_DEBUG=1"
```
## Updating
2023-10-26 05:47:49 +08:00
Update Ollama by running the install script again:
2023-10-26 05:47:49 +08:00
```shell
curl -fsSL https://ollama.com/install.sh | sh
2023-10-26 05:47:49 +08:00
```
Or by re-downloading Ollama:
2023-10-26 05:47:49 +08:00
```shell
curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o ollama-linux-amd64.tgz
sudo tar -C /usr -xzf ollama-linux-amd64.tgz
2023-10-26 05:47:49 +08:00
```
## Installing specific versions
Use `OLLAMA_VERSION` environment variable with the install script to install a specific version of Ollama, including pre-releases. You can find the version numbers in the [releases page](https://github.com/ollama/ollama/releases).
For example:
```shell
curl -fsSL https://ollama.com/install.sh | OLLAMA_VERSION=0.5.7 sh
```
2023-10-26 05:47:49 +08:00
## Viewing logs
2023-09-26 07:10:32 +08:00
To view logs of Ollama running as a startup service, run:
```shell
journalctl -e -u ollama
2023-09-26 07:10:32 +08:00
```
2023-10-25 02:07:05 +08:00
## Uninstall
Remove the ollama service:
2023-10-26 05:47:49 +08:00
```shell
2023-10-26 05:47:49 +08:00
sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm /etc/systemd/system/ollama.service
2023-10-25 02:07:05 +08:00
```
Remove the ollama binary from your bin directory (either `/usr/local/bin`, `/usr/bin`, or `/bin`):
2023-10-26 05:47:49 +08:00
```shell
2023-10-26 05:47:49 +08:00
sudo rm $(which ollama)
2023-10-25 02:07:05 +08:00
```
Remove the downloaded models and Ollama service user and group:
```shell
docs, scripts: Prevent useradd(8) from failing on Fedora Silverblue On OSTree based operating systems like Fedora Siverblue [1], the /usr/share directory is part of the read-only /usr mount point. This causes the install.sh script to fail when adding the 'ollama' user with its home directory at /usr/share/ollama, because useradd(8) is unable to create the directory: $ curl -fsSL https://ollama.com/install.sh | sh >>> Installing ollama to /usr/local >>> Downloading Linux amd64 bundle ############################################################### 100.0% >>> Creating ollama user... useradd: cannot create directory /usr/share/ollama >>> The Ollama API is now available at 127.0.0.1:11434. >>> Install complete. Run "ollama" from the command line. The /var/lib directory is an alternative for this, because /var is a read-write mount point. eg., this is used by Geoclue [2] and the GNOME Display Manager [3] for their users' home directories on Linux distributions like Arch, Fedora and Ubuntu. With this change the install.sh script is able to proceed further: $ sh scripts/install.sh >>> Installing ollama to /usr/local >>> Downloading Linux amd64 bundle ############################################################### 100.0% >>> Creating ollama user... >>> Adding ollama user to render group... >>> Adding ollama user to video group... >>> Adding current user to ollama group... >>> Creating ollama systemd service... >>> Enabling and starting ollama service... Created symlink '/etc/systemd/system/default.target.wants/ollama.service' → '/etc/systemd/system/ollama.service'. >>> The Ollama API is now available at 127.0.0.1:11434. >>> Install complete. Run "ollama" from the command line. WARNING: No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode. The install.sh script is able to use /usr/local on Fedora Silverblue, because /usr/local is not considered part of the read-only OS image, and is a symbolic link to /var/usrlocal to make it read-write. [1] https://fedoraproject.org/silverblue/ [2] https://gitlab.freedesktop.org/geoclue/geoclue/-/wikis/home [3] https://wiki.gnome.org/Projects/GDM/ https://github.com/ollama/ollama/pull/12455
2025-09-30 21:31:29 +08:00
sudo rm -r /var/lib/ollama
2023-10-26 05:47:49 +08:00
sudo userdel ollama
sudo groupdel ollama
2023-10-25 02:07:05 +08:00
```
Remove installed libraries:
```shell
sudo rm -rf /usr/local/lib/ollama
```