腾讯云 Ubuntu 22.04 安装 GitLab CE 踩坑记录:apt 源 404、找不到 gitlab-ce、官网下载过慢问题解决

发布时间:2026/7/9 1:30:57

腾讯云 Ubuntu 22.04 安装 GitLab CE 踩坑记录:apt 源 404、找不到 gitlab-ce、官网下载过慢问题解决 一、环境说明本次安装环境如下系统Ubuntu22.04系统代号jammy 服务器腾讯云 CVM 目标服务GitLab CE 访问地址http://150.158.123.242安装方式采用 GitLab CE 的 Omnibus 包安装方式也就是通过apt安装gitlab-ce。二、最初的安装思路一开始的安装流程大致如下sudoapt-getupdatesudoapt-getinstall-ycurlopenssh-server ca-certificates postfixcurlhttps://packages.gitlab.com/gpg.key|sudoapt-keyadd-sudovim/etc/apt/sources.list.d/gitlab-ce.listsudoapt-getupdatesudoEXTERNAL_URLIP地址apt-getinstall-ygitlab-ce理论上流程是对的但实际执行时遇到了多个问题主要集中在GitLab apt 源配置错误和下载速度过慢上。三、问题一清华 GitLab CE 源 404一开始配置的 GitLab CE 源为deb[signed-by/usr/share/keyrings/gitlab_gitlab-ce-archive-keyring.gpg]https://mirrors.tuna.tsinghua.edu.cn/gitlab/gitlab-ce/ubuntu/ jammy main执行sudoapt-getupdate报错Err:6 https://mirrors.tuna.tsinghua.edu.cn/gitlab/gitlab-ce/ubuntu jammy Release404Not Found E: The repositoryhttps://mirrors.tuna.tsinghua.edu.cn/gitlab/gitlab-ce/ubuntu jammy Releasedoes not have a Release file.这个错误的核心原因是GitLab CE 的 apt 源地址写错了。我当时写的是https://mirrors.tuna.tsinghua.edu.cn/gitlab/gitlab-ce/ubuntu/中间多了一层/gitlab/导致 apt 找不到对应的Release文件。四、问题二修改为清华源后仍然找不到 Release 文件后来我把源改成了类似https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu但是执行sudoapt-getupdate仍然报E: The repositoryhttps://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu jammy Releasedoes not have a Release file.这说明当前源路径和 apt 期望的目录结构仍然不匹配。随后执行apt-cachepolicy gitlab-ce结果是N: Unable tolocatepackage gitlab-ce这说明系统并没有成功加载 GitLab CE 的软件包索引。也就是说此时并不是 GitLab 安装失败而是apt 根本不知道 gitlab-ce 这个包在哪里。五、问题三执行 sed 替换腾讯源时报文件不存在后来我准备把官方源替换成腾讯镜像源执行了类似命令sudosed-is#https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/#https://mirrors.tencent.com/gitlab-ce/ubuntu/#g/etc/apt/sources.list.d/gitlab_gitlab-ce.list结果报错sed: cantread/etc/apt/sources.list.d/gitlab_gitlab-ce.list: No suchfileor directory这个问题的原因也很明确/etc/apt/sources.list.d/gitlab_gitlab-ce.list这个文件当时并不存在。可能原因有几个GitLab 官方源脚本还没有成功执行之前手动删除过这个文件GitLab 源文件名字不是gitlab_gitlab-ce.list而是其他名字比如gitlab-ce.list源文件根本没有创建成功。排查命令ls-l/etc/apt/sources.list.d/以及grep-Rgitlab/etc/apt/sources.list.d/这两个命令很重要后面排查 apt 源问题时经常用到。六、问题四官方源可以安装但下载速度太慢后来通过 GitLab 官方脚本成功添加了官方源curl-fsSLhttps://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh|sudobash再执行sudoapt-getupdateapt-cachepolicy gitlab-ce这时已经能找到gitlab-ce包了。然后执行安装sudoEXTERNAL_URLhttp://150.158.123.242apt-getinstall-ygitlab-ce安装开始后可以看到包确实找到了The following NEW packages will be installed: gitlab-ce Need to get976MB of archives. After this operation,3,612MB of additional disk space will be used.但是下载地址是https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/jammy下载速度非常慢31.4kB/s 8h 38min这说明官方源虽然可用但是在国内服务器上下载 GitLab CE 包速度很慢。七、最终解决方案切换到腾讯云 GitLab CE 镜像源因为服务器本身就是腾讯云所以最终选择使用腾讯云镜像源。最终确认 GitLab CE 源为https://mirrors.tencent.com/gitlab-ce/ubuntu/jammy在确认源已经切换为腾讯源后需要清理旧缓存sudoapt-getcleansudorm-f/var/cache/apt/archives/partial/gitlab-ce*.debsudorm-f/var/cache/apt/archives/gitlab-ce*.deb然后重新更新 apt 索引sudoapt-getupdate再确认 GitLab CE 包来源apt-cachepolicy gitlab-ce重点看输出里的源地址应该是https://mirrors.tencent.com/gitlab-ce/ubuntu/jammy而不是https://packages.gitlab.com确认无误后再安装sudoEXTERNAL_URLIP地址apt-getinstall-ygitlab-ce八、完整安装命令整理下面是本次最终比较推荐的一套流程。1. 清理旧 GitLab 源sudorm-f/etc/apt/sources.list.d/gitlab-ce.listsudorm-f/etc/apt/sources.list.d/gitlab_gitlab-ce.list2. 安装基础依赖sudoapt-getupdatesudoapt-getinstall-ycurlopenssh-server ca-certificates gnupg postfix3. 添加 GitLab 官方源curl-fsSLhttps://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh|sudobash这一步的作用是生成 GitLab CE 的 apt 源文件和相关 GPG 配置。4. 查看 GitLab 源文件grep-Rgitlab/etc/apt/sources.list.d/如果能看到类似packages.gitlab.com/gitlab/gitlab-ce/ubuntu说明官方源已经生成成功。5. 替换为腾讯云镜像源根据实际源文件路径执行替换。通常源文件是/etc/apt/sources.list.d/gitlab_gitlab-ce.list可以执行sudosed-is#https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu#https://mirrors.tencent.com/gitlab-ce/ubuntu#g/etc/apt/sources.list.d/gitlab_gitlab-ce.list如果这个文件不存在需要先执行ls-l/etc/apt/sources.list.d/grep-Rgitlab/etc/apt/sources.list.d/找到实际的 GitLab 源文件名再修改对应文件。6. 清理 apt 缓存sudoapt-getcleansudorm-f/var/cache/apt/archives/partial/gitlab-ce*.debsudorm-f/var/cache/apt/archives/gitlab-ce*.deb7. 更新 apt 索引sudoapt-getupdate8. 检查 GitLab CE 是否可用apt-cachepolicy gitlab-ce如果能看到Candidate说明 apt 已经能找到 GitLab CE 包。例如Candidate:19.1.2-ce.0同时需要确认来源是腾讯源而不是官方源。9. 安装 GitLab CEsudoEXTERNAL_URLIP地址apt-getinstall-ygitlab-ce其中EXTERNAL_URLIP地址表示 GitLab 安装完成后对外访问的地址。九、安装完成后的检查安装完成后查看 GitLab 服务状态sudogitlab-ctl status如果服务没有完全起来可以执行sudogitlab-ctl reconfigure然后再次查看sudogitlab-ctl status查看初始 root 密码sudocat/etc/gitlab/initial_root_password默认账号是root访问地址IP地址

相关新闻