GitLab Installation Guide

Requirements

Before installing GitLab, ensure your server meets the following hardware and software requirements. For small to medium teams, a minimum of 4 CPU cores and 8GB RAM is recommended, which can support hundreds of repositories and dozens of concurrent users. Larger teams or high-load scenarios require more resources, preferably 8+ CPU cores and 16GB+ RAM.

Regarding operating systems, GitLab supports various Linux distributions including Ubuntu, Debian, CentOS, Red Hat Enterprise Linux, and Fedora. Ubuntu or Debian are officially recommended because their package management is the most convenient. GitLab requires at least 20GB of disk space for installation, with 50GB+ recommended for basic configurations, and often hundreds of GB for production environments.

Software dependencies include OpenSSH Server for SSH protocol support, PostgreSQL database (GitLab includes a built-in version), and SMTP server for email notifications. You also need to configure the correct timezone and hostname, and ensure the server has normal network access to download dependency packages from the internet.

Installation Steps

Ubuntu/Debian Installation

On Ubuntu or Debian systems, installing GitLab via the official apt repository is recommended, as this ensures you get the latest stable versions and automatic security updates. First, install the necessary dependency packages:

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl

Add the GitLab APT repository and install GitLab CE (Community Edition):

curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ce

Replace EXTERNAL_URL with the actual domain or IP address for accessing GitLab. The installation process will automatically configure PostgreSQL, Redis, and GitLab itself.

CentOS/RHEL Installation

On CentOS or Red Hat Enterprise Linux, you can install GitLab using the yum or dnf package manager. First, install the necessary dependencies:

sudo yum install -y curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd

Add the GitLab YUM repository and install:

curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ce

Initial Configuration

After installation, you need to configure GitLab's basic parameters. Edit the /etc/gitlab/gitlab.rb file, which is GitLab's main configuration file. The most important configuration item is external_url, which is the external access address for the GitLab service:

external_url 'https://gitlab.example.com'

If you need to use a custom SSH port, configure the gitlab_rails['gitlab_shell_ssh_port'] parameter. Email server configuration is also important, used for sending notifications and password reset emails:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "yourpassword"
gitlab_rails['smtp_domain'] = "example.com"

After saving the configuration, run the following command to apply the changes:

sudo gitlab-ctl reconfigure

This command will reconfigure all GitLab components, including database migrations and initial user creation. The entire process may take several minutes.

Verifying Installation

After configuration is complete, you can access the address specified by external_url through your browser. If everything is correct, you should see the GitLab login page. On first access, you'll see the administrator account login page. The default administrator username is root, and you'll need to set a password on first login.

GitLab provides the gitlab-ctl command-line tool for managing service status:

# Check service status
sudo gitlab-ctl status

# View logs
sudo gitlab-ctl tail

# Restart service
sudo gitlab-ctl restart

You can also use the gitlab-rake command for health checks:

sudo gitlab-rake gitlab:env:info
sudo gitlab-rake gitlab:check

Docker Installation

For quick testing or small deployments, you can run GitLab using Docker. First, install Docker Engine, then run the following command on the host:

docker run --detach \
  --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

The Docker installation mounts three volumes for persisting configuration, logs, and data. The first startup of the Docker container takes time to initialize. After waiting patiently, you can access it through your browser.

Upgrading and Maintenance

Regularly upgrading GitLab to the latest version provides new features and security fixes. Upgrading on Ubuntu/Debian:

sudo apt-get update
sudo apt-get install gitlab-ce

It is recommended to back up data before upgrading. GitLab provides a built-in backup tool:

sudo gitlab-backup create

Backup files are stored in /var/opt/gitlab/backups by default. You can configure backup retention policies and remote storage locations.