Ollama 安装 作者:马育民 • 2025-11-06 10:37 • 阅读:10000 # 下载 到官网下载安装包: https://github.com/ollama/ollama/releases [](https://www.malaoshi.top/upload/0/0/1GW2B01ZRND1.png) [](https://www.malaoshi.top/upload/0/0/1GW2B0291fpP.png) # 安装 ### 创建目录 选择一个安装存放位置,以下按 `/root/temp` 为例,创建 `temp` 目录: ``` mkdir /root/temp ``` ### 解压安装包 ``` tar -xzf ollama-linux-amd64.tgz ``` ### 设置环境变量 在系统环境变量中加入ollama路径,解压后ollama路径为 `/root/temp/bin` 修改 `~/.bashrc` 文件,执行下面命令: ``` vim ~/.bashrc ``` 在最下面加上如下指令 ``` export PATH="/root/temp/bin:$PATH" ``` 输入 `:wq` 保存退出 [](https://www.malaoshi.top/upload/0/0/1GW2B0IcRvoC.png) ### 使环境变量生效 执行如下指令使其生效 ``` source ~/.bashrc ``` ### 创建服务文件 ``` vim /etc/systemd/system/ollama.service ``` 在文件中输入如下内容 ``` Description=Ollama Service After=network-online.target [Service] Environment="OLLAMA_HOST=0.0.0.0:11434" ExecStart="ollama执行文件路径" serve User=root Group=root Restart=always RestartSec=3 [Install] WantedBy=default.target ``` # 启动ollama服务命令 ``` # 重启 systemctl daemon-reload # 开机运行 systemctl enable ollama # 启动服务 systemctl start ollama ``` ### 验证ollama服务启动 获取版本号 ``` ollama -v ``` 执行结果如下,说明成功: [](https://www.malaoshi.top/upload/0/0/1GW2B0BM1NRr.png) # 下载模型 ### git-lfs安装 执行如下指令 ```bash #下载lfs安装包 curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash # git-lfs 安装 apt-get install git-lfs git lfs install ``` ### 下载大模型 下载Qwen3-0.6B-GGUF大模型 复制git指令,在任意路径下执行如下指令(本例中路径为 `/root/temp/models`)。 ```bash git clone 大模型的git地址 ``` # 模型部署 ### 创建配置文件 在下载模型的根目录下,创建 `ModelFile`,名称类似 `Qwen3_0_6B-Q8_0.txt`,执行下面命令: ``` vim Qwen3_0_6B-Q8_0.txt ``` 在 `Qwen3_0_6B-Q8_0.txt` 文件中输入模型启动信息 ``` # FROM PATH/TO/MODEL FROM ./Qwen3_0_6B-Q8_0.gguf # set the temperature to 1 [higher is more creative, lower is more coherent] PARAMETER temperature 0.7 PARAMETER top_p 0.8 PARAMETER repeat_penalty 1.05 PARAMETER top_k 20 TEMPLATE """{{ if .Messages }} {{- if or .System .Tools }}<|im_start|>system {{ .System }} {{- if .Tools }} # Tools You are provided with function signatures within XML tags: {{- range .Tools }} {"type": "function", "function": {{ .Function }}}{{- end }} For each function call, return a json object with function name and arguments within XML tags: {"name": , "arguments": } {{- end }}<|im_end|> {{ end }} {{- range $i, $_ := .Messages }} {{- $last := eq (len (slice $.Messages $i)) 1 -}} {{- if eq .Role "user" }}<|im_start|>user {{ .Content }}<|im_end|> {{ else if eq .Role "assistant" }}<|im_start|>assistant {{ if .Content }}{{ .Content }} {{- else if .ToolCalls }} {{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}} {{ end }} {{- end }}{{ if not $last }}<|im_end|> {{ end }} {{- else if eq .Role "tool" }}<|im_start|>user {{ .Content }} <|im_end|> {{ end }} {{- if and (ne .Role "assistant") $last }}<|im_start|>assistant {{ end }} {{- end }} {{- else }} {{- if .System }}<|im_start|>system {{ .System }}<|im_end|> {{ end }}{{ if .Prompt }}<|im_start|>user {{ .Prompt }}<|im_end|> {{ end }}<|im_start|>assistant {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}""" # set the system message SYSTEM """You are Qwen, created by Alibaba Cloud. You are a helpful assistant.""" ``` ### 加载与运行模型后可以完成本地推理 ``` #加载模型 ollama create Qwen3-0.6B-Q8_0 -f Qwen3_0_6B-Q8_0.txt #运行模型 ollama run Qwen3-0.6B-Q8_0 ``` 在控制台中问问题,如: ``` 你可以干什么? ``` 原文出处:http://malaoshi.top/show_1GW2B0KXRCsH.html