在 Debian 上安装 GitLab 主要有两种方式:官方 Omnibus 包(推荐) 和 Docker。下面我以 Debian 11/12 为例,给你一个最常用、最稳妥的安装方案(Omnibus)。
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates tzdata
curl -fsSL https://packages.gitlab.com/setup.sh | sudo bash
该脚本会自动配置 GitLab 的 APT 源
替换 gitlab.example.com 为你自己的域名或服务器 IP:
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ce -y
✅ 示例:
sudo EXTERNAL_URL="http://192.168.1.100" apt install gitlab-ce -y
sudo gitlab-ctl reconfigure
这一步会:
浏览器访问:
http://你的IP或域名
首次登录:
rootsudo cat /etc/gitlab/initial_root_password
⚠️ 该文件 24 小时后会自动删除
sudo gitlab-ctl status # 查看状态
sudo gitlab-ctl restart # 重启
sudo gitlab-ctl stop # 停止
sudo gitlab-ctl start # 启动
sudo gitlab-ctl tail # 查看日志
sudo nano /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['your@email.com']
sudo gitlab-ctl reconfigure
如果你更熟悉 Docker:
docker run -d \
--hostname gitlab.example.com \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
/etc/gitlab/gitlab.rbapt update
apt install -y curl
curl -fsSL https://packages.gitlab.com/setup.sh | bash
EXTERNAL_URL="http://你的IP" apt install gitlab-ce -y
gitlab-ctl reconfigure
如果你愿意,我可以帮你:
只要告诉我你的 Debian 版本 + 使用场景 即可。