Git LFS 跨平台安装指南:Linux、macOS 与 Windows 配置详解
为什么需要 Git LFS?
在使用 Git 管理大型文件时,经常遇到仓库体积膨胀、克隆耗时过长或 CI/CD 流程失败的问题。Git LFS(Git Large File Storage)通过将设计稿、数据集、二进制资产等大文件存储在仓库之外,仅在代码库中保留轻量级指针文件,有效解决了这些痛点。以下提供主流操作系统的安装与配置方案。
Linux 系统安装
包管理器快速安装
对于 Debian/Ubuntu 系列,推荐使用官方仓库:
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install -y git-lfs
git lfs version
RHEL/CentOS 系列用户则使用 yum/rpm:
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum install -y git-lfs
git lfs version
源码编译安装
如需体验最新版本,可从源码构建。先安装依赖:
# Debian/Ubuntu
sudo apt-get install -y build-essential git golang-go asciidoctor
# CentOS/RHEL
sudo yum install -y gcc git golang asciidoctor
随后克隆并编译:
git clone https://github.com/git-lfs/git-lfs.git
cd git-lfs
make
sudo make install
git lfs version
macOS 系统安装
Homebrew 安装(推荐)
brew install git-lfs
git lfs version
手动安装
若需特定版本,可下载二进制包解压安装:
curl -OL https://github.com/git-lfs/git-lfs/releases/download/v3.5.1/git-lfs-darwin-amd64-v3.5.1.tar.gz
tar -zxvf git-lfs-darwin-amd64-v3.5.1.tar.gz
cd git-lfs-3.5.1
sudo ./install.sh
git lfs version
Windows 系统安装
包管理器安装
使用 Chocolatey(需管理员权限 PowerShell):
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install git-lfs -y

