温馨提示×

gitlab debian如何换源

小樊
35
2026-10-02 13:01:54
栏目: 智能运维

在 Debian 上使用 GitLab(通常指 GitLab CE 官方 apt 仓库)时,如果需要“换源”,一般有两种常见场景:


一、更换 GitLab 官方 apt 源(推荐)

GitLab 官方源在国内访问可能较慢,可改为清华 / 中科大镜像源。

1. 查看当前 GitLab 源

cat /etc/apt/sources.list.d/gitlab_gitlab-ce.list

通常内容类似:

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

2. 替换为清华源(示例)

Debian 11(bullseye)

sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian/ bullseye main
EOF

Debian 12(bookworm)

sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian/ bookworm main
EOF

3. 更新 apt

sudo apt update

二、使用 GitLab 中国镜像(官方 China Mirror)

GitLab 官方也提供中国源:

sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list <<EOF
deb https://packages.gitlab.cn/gitlab-ce/debian/ bullseye main
EOF

然后:

curl -fsSL https://packages.gitlab.cn/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/gitlab-ce.gpg
sudo apt update

三、更换系统 Debian 源(如果是这个意思)

如果你指的是 Debian 系统本身换源(不是 GitLab):

sudo sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
sudo apt update

四、常见问题

1. GPG 签名错误

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY_ID>

2. 安装指定版本

sudo apt install gitlab-ce=16.11.3-ce.0

如果你能说明:

  • 是 GitLab apt 源 还是 Debian 系统源
  • Debian 版本(11 / 12)
  • 是否是 GitLab 企业版(EE)

我可以给你更精确的命令。

0 踩