8-OSS
Gitlab
Self Host

GitLab Community Edition Installation and Setup

Overview

GitLab is a web-based DevOps lifecycle tool that provides a Git repository manager with built-in CI/CD capabilities. This guide will help you install and configure GitLab Community Edition on your server.


Prerequisites

  • A Linux server (Ubuntu 20.04 or later recommended)
  • A domain name pointing to your server's IP address
  • Sufficient server resources (4GB RAM and 2 CPU cores recommended)
  • Root or sudo access to the server

Step 1: Install and Configure Dependencies

1.1 Update Package Index

Start by updating the package index:

sudo apt-get update

1.2 Install Required Packages

Install the necessary dependencies:

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

1.3 Install Postfix (Optional)

If you want to send notification emails, install Postfix. If you plan to use an external SMTP server, skip this step.

sudo apt-get install -y postfix

During the Postfix installation, a configuration screen may appear. Select Internet Site and press Enter. Use your server's external DNS for the mail name and press Enter. If additional screens appear, continue to press Enter to accept the defaults.


Step 2: Add GitLab Package Repository and Install GitLab

2.1 Add GitLab Repository

Run the following command to add the GitLab package repository:

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

2.2 Install GitLab

Next, install the GitLab package. Replace https://gitlab.example.com with the URL you want to use for your GitLab instance.

For HTTP:

sudo EXTERNAL_URL="http://gitlab.example.com" apt-get install gitlab-ee

For HTTPS:

For HTTPS URLs, GitLab will automatically request a certificate with Let's Encrypt, which requires inbound HTTP access and a valid hostname.

sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ee

Optional: Specify a Custom Password

If you want to set a custom password for the initial administrator user (root), check the GitLab documentation for details. If a password is not specified, a random password will be automatically generated.

2.3 Pinning the Version (Optional)

To limit auto-updates or to specify a version:

# List available versions:
apt-cache madison gitlab-ee
 
# Specify version:
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ee=16.2.3-ee.0
 
# Pin the version to limit auto-updates:
sudo apt-mark hold gitlab-ee
 
# Show what packages are held back:
sudo apt-mark showhold

Step 3: Access GitLab and Login

Once the installation is complete, browse to your GitLab URL:

http://gitlab.example.com

Initial Login

Unless you provided a custom password during installation, a password will be randomly generated and stored for 24 hours in:

/etc/gitlab/initial_root_password

Use this password along with the username root to log in.


Additional Configuration

1. SSL Setup

To enable SSL for your GitLab instance, you can use Let's Encrypt or upload your own certificates.

Using Let's Encrypt:

  1. Ensure that your EXTERNAL_URL uses https.

  2. In your GitLab configuration file (/etc/gitlab/gitlab.rb), set:

    letsencrypt['enable'] = true
  3. Reconfigure GitLab:

    sudo gitlab-ctl reconfigure

2. SSO Setup

To configure Single Sign-On (SSO), you need to enable the OmniAuth feature in GitLab.

  1. In the GitLab configuration file (/etc/gitlab/gitlab.rb), add your SSO provider configuration:

    omniauth['enabled'] = true
    omniauth['providers'] = [
      {
        "name": "saml",
        "args": {
          "assertion_consumer_service_url": "https://gitlab.example.com/users/auth/saml/callback",
          "idp_cert_fingerprint": "YOUR_IDP_CERT_FINGERPRINT",
          "idp_sso_target_url": "YOUR_IDP_SSO_TARGET_URL",
          "name_identifier_format": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
          "name": "SAML",
        }
      }
    ]
  2. Reconfigure GitLab:

    sudo gitlab-ctl reconfigure

3. Automatic Backups to S3

To set up automatic backups to S3, follow these steps:

  1. Install the AWS CLI on your GitLab server:

    sudo apt-get install awscli
  2. Configure your AWS credentials:

    aws configure
  3. Add backup configuration to the GitLab config file (/etc/gitlab/gitlab.rb):

    gitlab_rails['backup_upload']['connection'] = {
      "provider" => "AWS",
      "aws_access_key_id" => "YOUR_AWS_ACCESS_KEY",
      "aws_secret_access_key" => "YOUR_AWS_SECRET_KEY",
      "region" => "YOUR_AWS_REGION"
    }
    
    gitlab_rails['backup_upload']['bucket'] = "YOUR_BUCKET_NAME"
  4. Schedule regular backups by adding a cron job:

    sudo crontab -e

    Add the following line to run backups daily at 2 AM:

    0 2 * * * /opt/gitlab/bin/gitlab-backup create
  5. Reconfigure GitLab:

    sudo gitlab-ctl reconfigure

Conclusion

By following these steps, you should have a fully functional self-hosted GitLab Community Edition instance. You can further customize your GitLab setup by enabling SSL, configuring SSO, and setting up automatic backups to S3. For detailed information, refer to the official GitLab documentation (opens in a new tab).


This document provides a comprehensive guide to installing and setting up GitLab CE, along with important configurations and features. Let me know if you need any additional information!


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI