linux.md 2.04 KB
Newer Older
Michael Yang's avatar
Michael Yang committed
1
# Ollama on Linux
Jeffrey Morgan's avatar
Jeffrey Morgan committed
2

Michael Yang's avatar
Michael Yang committed
3
## Install
4

Michael Yang's avatar
Michael Yang committed
5
6
Install Ollama running this one-liner:
>
7
```bash
Michael Yang's avatar
Michael Yang committed
8
curl https://ollama.ai/install.sh | sh
9
10
```

Michael Yang's avatar
Michael Yang committed
11
## Manual install
Jeffrey Morgan's avatar
Jeffrey Morgan committed
12

Michael Yang's avatar
Michael Yang committed
13
### Download the `ollama` binary
Jeffrey Morgan's avatar
Jeffrey Morgan committed
14

Michael Yang's avatar
Michael Yang committed
15
Ollama is distributed as a self-contained binary. Download it to a directory in your PATH:
Jeffrey Morgan's avatar
Jeffrey Morgan committed
16

17
```bash
Michael Yang's avatar
Michael Yang committed
18
19
sudo curl -L https://ollama.ai/download/ollama-linux-amd64 -o /usr/bin/ollama
sudo chmod +x /usr/bin/ollama
Jeffrey Morgan's avatar
Jeffrey Morgan committed
20
21
```

Michael Yang's avatar
Michael Yang committed
22
### Adding Ollama as a startup service (recommended)
Jeffrey Morgan's avatar
Jeffrey Morgan committed
23
24
25

Create a user for Ollama:

26
```bash
Jeffrey Morgan's avatar
Jeffrey Morgan committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
sudo useradd -r -s /bin/false -m -d /usr/share/ollama ollama
```

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

[Install]
WantedBy=default.target
```

Then start the service:

50
```bash
Jeffrey Morgan's avatar
Jeffrey Morgan committed
51
52
53
sudo systemctl daemon-reload
sudo systemctl enable ollama
```
Jeffrey Morgan's avatar
Jeffrey Morgan committed
54

Michael Yang's avatar
Michael Yang committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
### Install CUDA drivers (optional – for Nvidia GPUs)

[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:

```bash
nvidia-smi
```

### Start Ollama

Start Ollama using `systemd`:

```bash
sudo systemctl start ollama
```

## Update

Update ollama by running the install script again:

```bash
curl https://ollama.ai/install.sh | sh
```

Or by downloading the ollama binary:

```bash
sudo curl -L https://ollama.ai/download/ollama-linux-amd64 -o /usr/bin/ollama
sudo chmod +x /usr/bin/ollama
```

## Viewing logs
Jeffrey Morgan's avatar
Jeffrey Morgan committed
89
90
91

To view logs of Ollama running as a startup service, run:

92
```bash
Jeffrey Morgan's avatar
Jeffrey Morgan committed
93
94
journalctl -u ollama
```
95
96
97
98

## Uninstall

Remove the ollama service:
Michael Yang's avatar
Michael Yang committed
99

100
```bash
Michael Yang's avatar
Michael Yang committed
101
102
103
sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm /etc/systemd/system/ollama.service
104
105
106
```

Remove the ollama binary from your bin directory (either `/usr/local/bin`, `/usr/bin`, or `/bin`):
Michael Yang's avatar
Michael Yang committed
107

108
```bash
Michael Yang's avatar
Michael Yang committed
109
sudo rm $(which ollama)
110
111
```

112
Remove the downloaded models and Ollama service user and group:
113
```bash
Michael Yang's avatar
Michael Yang committed
114
115
sudo rm -r /usr/share/ollama
sudo userdel ollama
116
sudo groupdel ollama
117
```