温馨提示×

Debian GitLab如何换源

小樊
42
2026-08-02 10:47:11
栏目: 智能运维

Debian 上更换 GitLab 软件源(APT 源),通常是指把 GitLab 官方的软件仓库换成 国内镜像源,以加快安装和更新速度。下面按常见场景说明。


一、GitLab 官方源(默认)

GitLab 官方源地址一般是:

https://packages.gitlab.com/gitlab/

在国内访问可能较慢,因此可以换成 清华 TUNA 镜像


二、使用清华大学镜像(推荐)

1️⃣ 查看当前 GitLab 源

cat /etc/apt/sources.list.d/gitlab*.list

如果看到类似:

deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ bullseye main

说明是官方源。


2️⃣ 替换为清华源

Debian 11(bullseye) 为例(其他版本替换 bullseye 即可):

sudo sed -i \
's|https://packages.gitlab.com/gitlab/gitlab-ce|https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce|g' \
/etc/apt/sources.list.d/gitlab_gitlab-ce.list

✅ 常用 Debian 版本对应关系:

Debian 版本 代号
Debian 12 bookworm
Debian 11 bullseye
Debian 10 buster

3️⃣ 更新软件索引

sudo apt update

三、如果是全新安装 GitLab(推荐方式)

1️⃣ 安装依赖

sudo apt update
sudo apt install -y curl openssh-server ca-certificates

2️⃣ 使用清华镜像直接安装

curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/gitlab-ce.gpg

echo "deb [signed-by=/usr/share/keyrings/gitlab-ce.gpg] \
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/gitlab-ce.list

然后:

sudo apt update
sudo apt install gitlab-ce

四、GitLab EE(企业版)换源

gitlab-ce 改为 gitlab-ee 即可:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/debian

五、常见问题

❓ 换源后 apt update 报错

  • 检查 Debian 版本代号是否正确
  • 确认 GPG 密钥是否正确导入
  • 使用:
apt-cache policy gitlab-ce

❓ 只换 GitLab,不影响系统源

✅ 正确做法:
只修改 /etc/apt/sources.list.d/gitlab*.list
不要修改 /etc/apt/sources.list


六、总结

推荐方案

Debian + GitLab → 使用 清华大学 GitLab CE 镜像

如果你愿意,可以告诉我:

  • Debian 版本
  • GitLab CE 还是 EE
  • 新安装 还是 已安装后换源

我可以给你一条 完全适配你环境的命令

0