Linux下OLLAMA安装卡住怎么办?

网络环境不理想,经常在官方的linux安装脚本执行时卡住,其实主要是下载文件卡住,于是我想到了是否可以把其中下载的过程显化、分步,这样更可控,于是修改了官方的install.sh

#!/bin/sh
# This script installs Ollama on Linux.
# It detects the current operating system architecture and installs the appropriate version of Ollama.set -eured="$( (/usr/bin/tput bold || :; /usr/bin/tput setaf 1 || :) 2>&-)"
plain="$( (/usr/bin/tput sgr0 || :) 2>&-)"status() { echo ">>> $*" >&2; }
error() { echo "${red}ERROR:${plain} $*"; exit 1; }
warning() { echo "${red}WARNING:${plain} $*"; }# 指定下载目录
DOWNLOAD_DIR="/home/xgocn/下载"
if [ ! -d "$DOWNLOAD_DIR" ]; thenerror "The specified download directory $DOWNLOAD_DIR does not exist. Please create it or specify a different directory."
ficleanup() { :; }  # 清理函数不再需要
trap cleanup EXITavailable() { command -v $1 >/dev/null; }
require() {local MISSING=''for TOOL in $*; doif ! available $TOOL; thenMISSING="$MISSING $TOOL"fidoneecho $MISSING
}[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.'ARCH=$(uname -m)
case "$ARCH" inx86_64) ARCH="amd64" ;;aarch64|arm64) ARCH="arm64" ;;*) error "Unsupported architecture: $ARCH" ;;
esacIS_WSL2=falseKERN=$(uname -r)
case "$KERN" in*icrosoft*WSL2 | *icrosoft*wsl2) IS_WSL2=true;;*icrosoft) error "Microsoft WSL1 is not currently supported. Please use WSL2 with 'wsl --set-version <distro> 2'" ;;*) ;;
esacVER_PARAM="${OLLAMA_VERSION:+?version=$OLLAMA_VERSION}"SUDO=
if [ "$(id -u)" -ne 0 ]; then# Running as root, no need for sudoif ! available sudo; thenerror "This script requires superuser permissions. Please re-run as root."fiSUDO="sudo"
fiNEEDS=$(require curl awk grep sed tee xargs)
if [ -n "$NEEDS" ]; thenstatus "ERROR: The following tools are required but missing:"for NEED in $NEEDS; doecho "  - $NEED"doneexit 1
fifor BINDIR in /usr/local/bin /usr/bin /bin; doecho $PATH | grep -q $BINDIR && break || continue
done
OLLAMA_INSTALL_DIR=$(dirname ${BINDIR})if [ -d "$OLLAMA_INSTALL_DIR/lib/ollama" ] ; thenstatus "Cleaning up old version at $OLLAMA_INSTALL_DIR/lib/ollama"$SUDO rm -rf "$OLLAMA_INSTALL_DIR/lib/ollama"
fi
status "Installing ollama to $OLLAMA_INSTALL_DIR"
$SUDO install -o0 -g0 -m755 -d $BINDIR
$SUDO install -o0 -g0 -m755 -d "$OLLAMA_INSTALL_DIR/lib/ollama"# 修改下载逻辑,提示用户手动下载
DOWNLOAD_URL="https://ollama.com/download/ollama-linux-$ARCH.tgz$VER_PARAM"
status "Please download the Ollama Linux $ARCH bundle from the following URL and place it in $DOWNLOAD_DIR:"
echo "$DOWNLOAD_URL"
read -p "Press [Enter] after placing the file in $DOWNLOAD_DIR to continue..."# 检查用户是否已将文件放置到指定位置
TGZ_FILE="$DOWNLOAD_DIR/ollama-linux-$ARCH.tgz"
if [ ! -f "$TGZ_FILE" ]; thenerror "The file was not found in $DOWNLOAD_DIR. Please download it and try again."
fistatus "Extracting Ollama..."
$SUDO tar -xzf "$TGZ_FILE" -C "$OLLAMA_INSTALL_DIR"if [ "$OLLAMA_INSTALL_DIR/bin/ollama" != "$BINDIR/ollama" ] ; thenstatus "Making ollama accessible in the PATH in $BINDIR"$SUDO ln -sf "$OLLAMA_INSTALL_DIR/ollama" "$BINDIR/ollama"
fi# 检测GPU并安装相关依赖
if [ -f /etc/nv_tegra_release ] ; thenif grep R36 /etc/nv_tegra_release > /dev/null ; thenstatus "Downloading JetPack 6 components"JETPACK_URL="https://ollama.com/download/ollama-linux-$ARCH-jetpack6.tgz$VER_PARAM"status "Please download the JetPack 6 components from the following URL and place it in $DOWNLOAD_DIR:"echo "$JETPACK_URL"read -p "Press [Enter] after placing the file in $DOWNLOAD_DIR to continue..."JETPACK_FILE="$DOWNLOAD_DIR/ollama-linux-$ARCH-jetpack6.tgz"if [ ! -f "$JETPACK_FILE" ]; thenerror "The file was not found in $DOWNLOAD_DIR. Please download it and try again."fi$SUDO tar -xzf "$JETPACK_FILE" -C "$OLLAMA_INSTALL_DIR"elif grep R35 /etc/nv_tegra_release > /dev/null ; thenstatus "Downloading JetPack 5 components"JETPACK_URL="https://ollama.com/download/ollama-linux-$ARCH-jetpack5.tgz$VER_PARAM"status "Please download the JetPack 5 components from the following URL and place it in $DOWNLOAD_DIR:"echo "$JETPACK_URL"read -p "Press [Enter] after placing the file in $DOWNLOAD_DIR to continue..."JETPACK_FILE="$DOWNLOAD_DIR/ollama-linux-$ARCH-jetpack5.tgz"if [ ! -f "$JETPACK_FILE" ]; thenerror "The file was not found in $DOWNLOAD_DIR. Please download it and try again."fi$SUDO tar -xzf "$JETPACK_FILE" -C "$OLLAMA_INSTALL_DIR"elsewarning "Unsupported JetPack version detected.  GPU may not be supported"fi
fiinstall_success() {status 'The Ollama API is now available at 127.0.0.1:11434.'status 'Install complete. Run "ollama" from the command line.'
}
trap install_success EXIT# Everything from this point onwards is optional.configure_systemd() {if ! id ollama >/dev/null 2>&1; thenstatus "Creating ollama user..."$SUDO useradd -r -s /bin/false -U -m -d /usr/share/ollama ollamafiif getent group render >/dev/null 2>&1; thenstatus "Adding ollama user to render group..."$SUDO usermod -a -G render ollamafiif getent group video >/dev/null 2>&1; thenstatus "Adding ollama user to video group..."$SUDO usermod -a -G video ollamafistatus "Adding current user to ollama group..."$SUDO usermod -a -G ollama $(whoami)status "Creating ollama systemd service..."cat <<EOF | $SUDO tee /etc/systemd/system/ollama.service >/dev/null
[Unit]
Description=Ollama Service
After=network-online.target[Service]
ExecStart=$BINDIR/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"[Install]
WantedBy=default.target
EOFSYSTEMCTL_RUNNING="$(systemctl is-system-running || true)"case $SYSTEMCTL_RUNNING inrunning|degraded)status "Enabling and starting ollama service..."$SUDO systemctl daemon-reload$SUDO systemctl enable ollamastart_service() { $SUDO systemctl restart ollama; }trap start_service EXIT;;*)warning "systemd is not running"if [ "$IS_WSL2" = true ]; thenwarning "see https://learn.microsoft.com/en-us/windows/wsl/systemd#how-to-enable-systemd to enable it"fi;;esac
}if available systemctl; thenconfigure_systemd
fi# WSL2 only supports GPUs via nvidia passthrough
# so check for nvidia-smi to determine if GPU is available
if [ "$IS_WSL2" = true ]; thenif available nvidia-smi && [ -n "$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")" ]; thenstatus "Nvidia GPU detected."fiinstall_successexit 0
fi# Don't attempt to install drivers on Jetson systems
if [ -f /etc/nv_tegra_release ] ; thenstatus "NVIDIA JetPack ready."install_successexit 0
fi# Install GPU dependencies on Linux
if ! available lspci && ! available lshw; thenwarning "Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies."exit 0
ficheck_gpu() {# Look for devices based on vendor ID for NVIDIA and AMDcase $1 inlspci)case $2 innvidia) available lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;;amdgpu) available lspci && lspci -d '1002:' | grep -q 'AMD' || return 1 ;;esac ;;lshw)case $2 innvidia) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[10DE\]' || return 1 ;;amdgpu) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[1002\]' || return 1 ;;esac ;;nvidia-smi) available nvidia-smi || return 1 ;;esac
}if check_gpu nvidia-smi; thenstatus "NVIDIA GPU installed."exit 0
fiif ! check_gpu lspci nvidia && ! check_gpu lshw nvidia && ! check_gpu lspci amdgpu && ! check_gpu lshw amdgpu; theninstall_successwarning "No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode."exit 0
fiif check_gpu lspci amdgpu || check_gpu lshw amdgpu; thenstatus "Downloading Linux ROCm $ARCH bundle"ROCM_URL="https://ollama.com/download/ollama-linux-$ARCH-rocm.tgz$VER_PARAM"status "Please download the ROCm bundle from the following URL and place it in $DOWNLOAD_DIR:"echo "$ROCM_URL"read -p "Press [Enter] after placing the file in $DOWNLOAD_DIR to continue..."ROCM_FILE="$DOWNLOAD_DIR/ollama-linux-$ARCH-rocm.tgz"if [ ! -f "$ROCM_FILE" ]; thenerror "The file was not found in $DOWNLOAD_DIR. Please download it and try again."fi$SUDO tar -xzf "$ROCM_FILE" -C "$OLLAMA_INSTALL_DIR"install_successstatus "AMD GPU ready."exit 0
fiCUDA_REPO_ERR_MSG="NVIDIA GPU detected, but your OS and Architecture are not supported by NVIDIA.  Please install the CUDA driver manually https://docs.nvidia.com/cuda/cuda-installation-guide-linux/"
# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-7-centos-7
# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-8-rocky-8
# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-9-rocky-9
# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#fedora
install_cuda_driver_yum() {status 'Installing NVIDIA repository...'case $PACKAGE_MANAGER inyum)$SUDO $PACKAGE_MANAGER -y install yum-utilsif curl -I --silent --fail --location "$CUDA_REPO_URL"

只要在本地运行bash install.sh即可,在安装中会提示你手动下载指定的文件到指定的目录,手动下载后,回车继续执行

记住把 /home/xgocn/下载 改为你指定的下载目录

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/pingmian/84600.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++面试(5)-----删除链表中指定值的节点

操作系统&#xff1a;ubuntu22.04 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 给定一个单向链表的头节点 head 和一个特定值 val&#xff0c;要求编写一个函数来删除链表中所有值等于 val 的节点&#xff0c;并返回修改后的链表头节点。 示例&#xff1a; 输…

如何用AI赋能学习

由于博主是大学生&#xff0c;今天花费了大量的时间去进行期末的复习&#xff0c;不过从复习中得到了一些学习的灵感&#xff0c;即&#xff1a;如何用AI赋能学习 当我们需要掌握一门新的技能的时候&#xff0c;我们很容易的想到三种办法&#xff1a;买书自己学&#xff0c;报…

【threejs】每天一个小案例讲解:常见材质

代码仓 GitHub - TiffanyHoo/three_practices: Learning three.js together! 可自行clone&#xff0c;无需安装依赖&#xff0c;直接liver-server运行/直接打开chapter01中的html文件 运行效果图 知识要点 1. MeshBasicMaterial&#xff08;基础网格材质&#xff09; • 特…

springboot后端与鸿蒙的结合

软件&#xff1a;鸿蒙devceo3.1&#xff0c;springboot项目采用IDEA 目的&#xff1a; 1、结合springboot后端与鸿蒙的结合运用。 2、Log日志查看console语句的信息。 3、引入 import http from ohos.net.http。 4、调用springboot后端提供的链接发送post 5、TextInput的…

minio集群通过mc mirror命令进行定时备份,支持X86和arm两种架构

文章目录 前言一、思路二、使用步骤1.下载mc二进制文件2.手动测试备份命令3.配置定时任务4.成功截图 总结 前言 通过mc mirror命令对minio集群进行定时备份。 一、思路 通过mc mirror命令配合crond定时任务进行周期性的备份 二、使用步骤 1.下载mc二进制文件 wget https:…

三大能力升级,为老项目重构开辟新路径

在软件技术飞速迭代的今天&#xff0c;老项目重构是开发者们绕不开的难题。接口实现缺失、业务逻辑矛盾、架构规划偏离等问题如同拦路虎&#xff0c;让重构工作举步维艰。而传统的 AI 辅助方式&#xff0c;因未充分关联项目实际情况&#xff0c;犹如 “空中造楼”&#xff0c;难…

AES加密

AES加密算法详解 AES&#xff08;Advanced Encryption Standard&#xff09;是一种对称密钥分组加密算法&#xff0c;用于保护电子数据的安全性。其核心特点是通过相同的密钥进行加密和解密&#xff0c;属于对称加密体系。。以下从核心特性、加密流程及安全性三方面展开说明&a…

关于联咏(Novatek )自动曝光中Lv值的计算方式实现猜想

目录 一、常见Lv对应的实际场景 二、常见光圈值 三、最小二乘法计算SV中的系数K

[docker]镜像操作:关于docker pull、save、load一些疑惑解答

在使用 Docker 的过程中&#xff0c;镜像管理是极其重要的一环。无论是拉取、保存还是加载镜像&#xff0c;每一个步骤都可能遇到一些疑问或者误区。 本文将结合实际案例&#xff0c;对常见的 Docker 镜像操作问题进行系统性总结&#xff0c;帮你更好地理解 Docker 镜像的工作机…

SFTrack:面向警务无人机的自适应多目标跟踪算法——突破小尺度高速运动目标的追踪瓶颈

【导读】 本文针对无人机&#xff08;UAV&#xff09;视频中目标尺寸小、运动快导致的多目标跟踪难题&#xff0c;提出一种更简单高效的方法。核心创新在于从低置信度检测启动跟踪&#xff08;贴合无人机场景特性&#xff09;&#xff0c;并改进传统外观匹配算法以关联此类检测…

什么是渗透测试,对网站安全有哪些帮助?

在网络安全的战场中&#xff0c;网站如同暴露在数字世界的堡垒&#xff0c;时刻面临着黑客攻击的威胁。而渗透测试&#xff0c;就像是为网站进行一场 “模拟攻防演练”&#xff0c;它以黑客的思维和手段&#xff0c;主动出击&#xff0c;探寻网站潜在的安全漏洞。究竟什么是渗透…

KU115LPE-V10型FPGA加速卡

KU115LPE-V10是一款基于PCI Express总线通信的FPGA加速类产品。 该产品基于Xilinx公司的的高性能Kintex Ultra-Scale FPGA设计&#xff0c;配置最大两组DDR4缓存单元&#xff0c;每组最大支持4GB容量&#xff0c;72bit&#xff08;包含ECC&#xff0c;8bit&#xff09;&#x…

【笔记】Blockchain

区块链Blockchain是一种分布式数据库技术&#xff0c;其核心特点在于去中心化、不可篡改和透明性。它通过一系列按照时间顺序排列的数据块&#xff08;即“区块”&#xff09;组成&#xff0c;每个数据块都包含了一定时间内的一系列信息交易&#xff0c;并通过密码学方法确保这…

GitHub Desktop Failure when receiving data from the peer

目录 安装Github Desktop简易省流助手 解决 Git 克隆时出现的 "Failure when receiving data from the peer" 错误1. 网络连接问题原因&#xff1a;解决办法&#xff1a; 2. Git 配置问题原因&#xff1a;解决办法&#xff1a; 3. GitHub 服务故障原因&#xff1a;解…

疏锦行Python打卡 DAY 27 函数专题2:装饰器

def logger(func):def wrapper(*args, **kwargs):print(f"开始执行函数 {func.__name__}&#xff0c;参数: {args}, {kwargs}")result func(*args, **kwargs)print(f"函数 {func.__name__} 执行完毕&#xff0c;返回值: {result}")return resultreturn wr…

大模型布署如何选择GPU资源?

当前主流GPU型号及其显存大小&#xff08;显存“大小”&#xff09;的详细分类汇总&#xff0c;结合消费级、专业工作站级及数据中心级三大应用场景&#xff0c;数据综合自行业常用型号及最新产品信息&#xff08;截至2025年6月&#xff09;&#xff1a; &#x1f3ae; 一、消费…

目标检测——YOLOv12算法解读

论文&#xff1a;YOLOv12: Attention-Centric Real-Time Object Detectors (2025.2.18) 作者&#xff1a;Yunjie Tian, Qixiang Ye, David Doermann 链接&#xff1a;https://arxiv.org/abs/2502.12524 代码&#xff1a;https://github.com/sunsmarterjie/yolov12 YOLO系列算法…

JavaEE-Maven

maven Maven是⼀个项⽬管理⼯具, 通过pom.xml⽂件的配置获取jar包&#xff0c;⽽不⽤⼿动去添加jar包。 maven简单, ⽅便, 提⾼我们的开发效率, 减少我们的开发Bug。 IDEA本⾝已经集成了Maven, 我们可以直接使⽤, ⽆需安装。 创建maven项目 name是项目名 location是项目路径 …

使用 C/C++的OpenCV 实时播放火柴人爱心舞蹈动画

使用 C/OpenCV 实时播放火柴人爱心舞蹈动画 本文将介绍如何使用 C/OpenCV 库实时创建一个动画窗口&#xff1a;一个火柴人捧着爱心跳舞&#xff0c;同时另一个爱心从远处飞来并逐渐变大。动画会实时在 OpenCV 窗口中播放&#xff0c;直到用户按下按键退出。 准备工作 确保你…

复现论文报错解决

文章目录 一、 The detected CUDA version (12.9) mismatches the version that was used to compile PyTorch (11.8)二、error -- unsupported GNU version! gcc versions later than 11 are not supported!三、Unknown encoder libx264四、下载速度太慢、无法递归下载项目 一…