linux.md 3.82 KB
Newer Older
xuxzh1's avatar
update  
xuxzh1 committed
1
# Linux
mashun1's avatar
v1  
mashun1 committed
2
3
4

## Install

xuxzh1's avatar
update  
xuxzh1 committed
5
To install Ollama, run the following command:
mashun1's avatar
v1  
mashun1 committed
6

xuxzh1's avatar
update  
xuxzh1 committed
7
```shell
mashun1's avatar
v1  
mashun1 committed
8
9
10
curl -fsSL https://ollama.com/install.sh | sh
```

xuxzh1's avatar
update  
xuxzh1 committed
11
## Manual install
mashun1's avatar
v1  
mashun1 committed
12

xuxzh1's avatar
update  
xuxzh1 committed
13
Download and extract the package:
mashun1's avatar
v1  
mashun1 committed
14

xuxzh1's avatar
update  
xuxzh1 committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
```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
```

Start Ollama:

```shell
ollama serve
```

In another terminal, verify that Ollama is running:

```shell
ollama -v
```

### AMD GPU install

If you have an AMD GPU, also download and extract the additional ROCm package:

```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
```
mashun1's avatar
v1  
mashun1 committed
40

xuxzh1's avatar
update  
xuxzh1 committed
41
### ARM64 install
mashun1's avatar
v1  
mashun1 committed
42

xuxzh1's avatar
update  
xuxzh1 committed
43
Download and extract the ARM64-specific package:
mashun1's avatar
v1  
mashun1 committed
44

xuxzh1's avatar
update  
xuxzh1 committed
45
46
47
```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
mashun1's avatar
v1  
mashun1 committed
48
49
50
51
```

### Adding Ollama as a startup service (recommended)

xuxzh1's avatar
update  
xuxzh1 committed
52
Create a user and group for Ollama:
mashun1's avatar
v1  
mashun1 committed
53

xuxzh1's avatar
update  
xuxzh1 committed
54
55
56
```shell
sudo useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama
sudo usermod -a -G ollama $(whoami)
mashun1's avatar
v1  
mashun1 committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
```

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
xuxzh1's avatar
update  
xuxzh1 committed
72
Environment="PATH=$PATH"
mashun1's avatar
v1  
mashun1 committed
73
74
75
76
77
78
79

[Install]
WantedBy=default.target
```

Then start the service:

xuxzh1's avatar
update  
xuxzh1 committed
80
```shell
mashun1's avatar
v1  
mashun1 committed
81
82
83
84
sudo systemctl daemon-reload
sudo systemctl enable ollama
```

xuxzh1's avatar
update  
xuxzh1 committed
85
### Install CUDA drivers (optional)
mashun1's avatar
v1  
mashun1 committed
86
87
88
89
90

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

xuxzh1's avatar
update  
xuxzh1 committed
91
```shell
mashun1's avatar
v1  
mashun1 committed
92
93
94
nvidia-smi
```

xuxzh1's avatar
update  
xuxzh1 committed
95
### Install AMD ROCm drivers (optional)
mashun1's avatar
v1  
mashun1 committed
96

xuxzh1's avatar
update  
xuxzh1 committed
97
[Download and Install](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html) ROCm v6.
mashun1's avatar
v1  
mashun1 committed
98
99
100

### Start Ollama

xuxzh1's avatar
update  
xuxzh1 committed
101
Start Ollama and verify it is running:
mashun1's avatar
v1  
mashun1 committed
102

xuxzh1's avatar
update  
xuxzh1 committed
103
```shell
mashun1's avatar
v1  
mashun1 committed
104
sudo systemctl start ollama
xuxzh1's avatar
update  
xuxzh1 committed
105
sudo systemctl status ollama
mashun1's avatar
v1  
mashun1 committed
106
107
```

xuxzh1's avatar
update  
xuxzh1 committed
108
109
110
111
112
113
114
115
> [!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
> https://www.amd.com/en/support/linux-drivers for best support of your Radeon
> GPU.

## Customizing
mashun1's avatar
v1  
mashun1 committed
116

xuxzh1's avatar
update  
xuxzh1 committed
117
To customize the installation of Ollama, you can edit the systemd service file or the environment variables by running:
mashun1's avatar
v1  
mashun1 committed
118

xuxzh1's avatar
update  
xuxzh1 committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
```
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

Update Ollama by running the install script again:

```shell
mashun1's avatar
v1  
mashun1 committed
135
136
137
curl -fsSL https://ollama.com/install.sh | sh
```

xuxzh1's avatar
update  
xuxzh1 committed
138
Or by re-downloading Ollama:
mashun1's avatar
v1  
mashun1 committed
139

xuxzh1's avatar
update  
xuxzh1 committed
140
141
142
```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
mashun1's avatar
v1  
mashun1 committed
143
144
```

xuxzh1's avatar
init  
xuxzh1 committed
145
146
## Installing specific versions

xuxzh1's avatar
update  
xuxzh1 committed
147
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).
xuxzh1's avatar
init  
xuxzh1 committed
148
149
150

For example:

xuxzh1's avatar
update  
xuxzh1 committed
151
152
```shell
curl -fsSL https://ollama.com/install.sh | OLLAMA_VERSION=0.3.9 sh
xuxzh1's avatar
init  
xuxzh1 committed
153
154
```

mashun1's avatar
v1  
mashun1 committed
155
156
157
158
## Viewing logs

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

xuxzh1's avatar
update  
xuxzh1 committed
159
```shell
mashun1's avatar
v1  
mashun1 committed
160
161
162
163
164
165
166
journalctl -e -u ollama
```

## Uninstall

Remove the ollama service:

xuxzh1's avatar
update  
xuxzh1 committed
167
```shell
mashun1's avatar
v1  
mashun1 committed
168
169
170
171
172
173
174
sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm /etc/systemd/system/ollama.service
```

Remove the ollama binary from your bin directory (either `/usr/local/bin`, `/usr/bin`, or `/bin`):

xuxzh1's avatar
update  
xuxzh1 committed
175
```shell
mashun1's avatar
v1  
mashun1 committed
176
177
178
179
180
sudo rm $(which ollama)
```

Remove the downloaded models and Ollama service user and group:

xuxzh1's avatar
update  
xuxzh1 committed
181
```shell
mashun1's avatar
v1  
mashun1 committed
182
183
184
185
sudo rm -r /usr/share/ollama
sudo userdel ollama
sudo groupdel ollama
```