Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Install GitLab on CentOS: Step-by-Step Setup

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through installing and configuring GitLab CE (Community Edition) on CentOS 7 or 8. By the end, you'll have a fully functional self-hosted Git repository manager with a web interface, issue tracking, CI/CD pipelines, and more. You'll need a CentOS server with at least 4GB of RAM (8GB recommended), root or sudo access, and a domain name or IP address pointing to the server.

What You'll Need

  • A CentOS 7 or 8 server with at least 4GB RAM (8GB recommended for larger teams)
  • Root or sudo access to the server
  • A domain name (optional but recommended) or a public IP address
  • Open ports 80 (HTTP) and 443 (HTTPS) in your firewall
  • Basic familiarity with the command line

Step-by-Step

  1. Update your system
    Log in to your server and run: sudo yum update -y
    This ensures all existing packages are up to date before installing new software.
  2. Install required dependencies
    GitLab needs a few packages to run. Install them with: sudo yum install -y curl policycoreutils openssh-server openssh-clients postfix
    Postfix is used for email notifications. If you already have a mail server, you can skip it, but the default install works well.
  3. Start and enable Postfix
    If you installed Postfix, start it and enable it to run on boot: sudo systemctl start postfix
    sudo systemctl enable postfix
    If you don't want Postfix, you can skip this step and configure GitLab to use an external SMTP server later.
  4. Add the GitLab repository
    GitLab provides a package repository. Add it with: curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
    This script sets up the repository and GPG keys for you.
  5. Install GitLab CE
    Now install the GitLab package. Replace http://your-domain.com with your actual domain or IP address: sudo EXTERNAL_URL="http://your-domain.com" yum install -y gitlab-ce
    This step downloads and installs GitLab, then configures it to use the URL you provided. The installation may take several minutes.
  6. Reconfigure GitLab (if needed)
    If you need to change the external URL after installation, edit /etc/gitlab/gitlab.rb and set external_url 'http://your-domain.com'. Then run: sudo gitlab-ctl reconfigure
    This applies any changes to the configuration.
  7. Access the GitLab web interface
    Open your browser and go to http://your-domain.com. On the first visit, you'll be prompted to set a password for the initial administrator account (root).
  8. Log in as root
    Use the username root and the password you just set. After logging in, you can create users, groups, and projects.
  9. Configure HTTPS (optional but recommended)
    To enable HTTPS, edit /etc/gitlab/gitlab.rb and set external_url 'https://your-domain.com'. Then run sudo gitlab-ctl reconfigure. If you have a domain name, you can use Let's Encrypt for a free SSL certificate by setting letsencrypt['enable'] = true in the same file before reconfiguring.
  10. Set up firewall rules
    If you have a firewall enabled, allow HTTP and HTTPS traffic: sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload

Common Mistakes

  • Not enough RAM: GitLab is resource-hungry. On 2GB RAM, it will be extremely slow or fail to start. Use at least 4GB.
  • Incorrect external URL: If you set the URL to http://localhost, you won't be able to access it from other machines. Use a domain or public IP.
  • Skipping Postfix: Without a mail server, GitLab cannot send password resets or notifications. If you skip Postfix, configure SMTP in gitlab.rb.
  • Forgetting to open firewall ports: Even if GitLab is running, you can't access it if the firewall blocks ports 80/443.
  • Using CentOS 6: GitLab no longer supports CentOS 6. Stick with CentOS 7 or 8.

Tips

  • Use a domain name instead of a raw IP to avoid issues with Git's remote URLs and SSL certificates.
  • Back up /etc/gitlab/gitlab.rb before making changes. You can restore it if something breaks.
  • Set up regular backups using gitlab-rake gitlab:backup:create. Store backups on a separate drive or remote location.
  • Monitor disk space; GitLab repositories and logs can grow quickly.
  • Consider enabling GitLab's built-in Prometheus monitoring for performance insights.

Troubleshooting

  • GitLab won't start or times out: Check memory usage with free -h. If you have less than 4GB, add swap space or increase RAM. Restart with sudo gitlab-ctl restart.
  • 502 Bad Gateway: This often means the Unicorn or Puma service isn't running. Check with sudo gitlab-ctl status and restart any failed services.
  • Port 80 already in use: If Apache or nginx is running, stop it or change GitLab's port in gitlab.rb (e.g., external_url 'http://your-domain.com:8080').
  • Can't access from outside: Verify your firewall and cloud security group allow ports 80/443. Also check that your server's public IP is correct.
  • SSL certificate errors: If using Let's Encrypt, ensure your domain resolves to the server's IP and port 80 is open for the HTTP challenge.
  • Postfix fails to start: Check sudo systemctl status postfix. If there's a conflict with an existing mail server, you may need to disable it.

Frequently Asked Questions

Can I install GitLab on CentOS 8?

Yes, GitLab CE supports CentOS 8. The steps are the same, but ensure you have the EPEL repository enabled if needed.

What is the default admin username?

The default administrator is root. You set the password during the first web visit.

How do I update GitLab?

Run sudo yum update gitlab-ce and then sudo gitlab-ctl reconfigure to apply changes.

Can I use an existing nginx server?

Yes, you can configure GitLab to use an external nginx, but it's more complex. The bundled nginx is simpler for most setups.

How do I change the port GitLab listens on?

Edit external_url in /etc/gitlab/gitlab.rb to include the port (e.g., http://example.com:8080), then reconfigure.

Does GitLab work with SELinux?

Yes, GitLab provides SELinux policies. If you run into permission issues, check sudo getenforce and consider setting it to permissive for testing.