BLOG POSTS
How to Install and Configure GitLab on Ubuntu

How to Install and Configure GitLab on Ubuntu

GitLab is a powerful DevOps platform that combines Git repository management, CI/CD pipelines, issue tracking, and deployment tools into a single application. Setting up your own GitLab instance on Ubuntu gives you complete control over your development workflow, enhanced security for private projects, and the ability to customize features according to your team’s specific needs. This guide will walk you through the complete installation and configuration process, covering everything from initial system preparation to advanced settings, common troubleshooting scenarios, and optimization techniques that’ll get your GitLab instance running smoothly.

How GitLab Works: Architecture Overview

GitLab operates as a multi-component system built around several core services. The main GitLab Rails application handles the web interface and API requests, while GitLab Shell manages Git operations over SSH. PostgreSQL serves as the primary database, Redis handles caching and background job queuing, and Sidekiq processes background tasks. Understanding this architecture helps when troubleshooting performance issues or configuring advanced features.

The GitLab Omnibus package simplifies deployment by bundling all these components with automated configuration management. This approach reduces complexity compared to manual installations but requires sufficient system resources to run effectively.

System Requirements and Preparation

Before diving into installation, your Ubuntu server needs adequate resources. GitLab’s minimum requirements start at 4GB RAM for up to 500 users, but 8GB+ is recommended for production environments. CPU requirements scale with user activity, with 4+ cores being optimal for teams larger than 100 users.

User Count RAM CPU Cores Storage
Up to 500 4GB 2 cores 50GB
Up to 1,000 8GB 4 cores 100GB
Up to 2,000 16GB 8 cores 200GB
Up to 5,000 32GB 16 cores 500GB

Start by updating your Ubuntu system and installing essential dependencies:

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates tzdata perl postfix

During postfix installation, select “Internet Site” and enter your server’s domain name. This configures email notifications, though you can modify these settings later.

Step-by-Step GitLab Installation

GitLab provides an official APT repository that simplifies installation and updates. Add the repository and install GitLab Community Edition:

# Add GitLab package repository
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

# Install GitLab Community Edition
sudo apt install gitlab-ce

For GitLab Enterprise Edition users, replace gitlab-ce with gitlab-ee in both commands.

The installation process downloads approximately 1GB of packages and takes 5-10 minutes depending on your server’s specifications. Once completed, configure your GitLab instance:

sudo vim /etc/gitlab/gitlab.rb

Modify the external URL to match your domain or IP address:

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

If you’re using HTTP instead of HTTPS initially, use http:// in the URL. After saving changes, reconfigure GitLab:

sudo gitlab-ctl reconfigure

This process takes several minutes as GitLab configures all services, creates databases, and generates SSL certificates if using HTTPS.

Initial Configuration and Security Setup

After installation completes, retrieve the initial root password:

sudo cat /etc/gitlab/initial_root_password

Access your GitLab instance through a web browser using the configured external URL. Log in with username root and the password from the previous command. This initial password expires after 24 hours, so change it immediately through the web interface.

Essential security configurations include:

  • Enable two-factor authentication for the root account
  • Configure SMTP settings for email notifications
  • Set up backup procedures
  • Configure firewall rules to restrict access

Configure SMTP settings in /etc/gitlab/gitlab.rb:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your-email@gmail.com"
gitlab_rails['smtp_password'] = "your-app-password"
gitlab_rails['smtp_domain'] = "smtp.gmail.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'your-email@gmail.com'

SSL Certificate Configuration

Production GitLab instances require SSL certificates for security. Let’s Encrypt provides free certificates that integrate well with GitLab:

# Install Certbot
sudo apt install certbot

# Stop GitLab temporarily 
sudo gitlab-ctl stop

# Generate certificate
sudo certbot certonly --standalone -d gitlab.yourdomain.com

# Start GitLab
sudo gitlab-ctl start

Configure GitLab to use the generated certificates by adding these lines to /etc/gitlab/gitlab.rb:

nginx['ssl_certificate'] = "/etc/letsencrypt/live/gitlab.yourdomain.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/gitlab.yourdomain.com/privkey.pem"

Reconfigure GitLab to apply SSL settings:

sudo gitlab-ctl reconfigure

Performance Optimization and Tuning

GitLab performance depends heavily on proper resource allocation. Monitor system resources and adjust GitLab’s configuration accordingly:

# Check GitLab service status
sudo gitlab-ctl status

# Monitor resource usage
sudo gitlab-ctl top

Key performance settings in /etc/gitlab/gitlab.rb:

# PostgreSQL connections
postgresql['max_connections'] = 200
postgresql['shared_buffers'] = "256MB"

# Sidekiq worker processes
sidekiq['max_concurrency'] = 25

# Unicorn worker processes
unicorn['worker_processes'] = 4
unicorn['worker_memory_limit_min'] = "1024 * 1 << 20"
unicorn['worker_memory_limit_max'] = "1280 * 1 << 20"

For servers with limited RAM, reduce worker processes and connections. Conversely, high-traffic instances benefit from increased values.

Common Issues and Troubleshooting

Several issues commonly occur during GitLab installation and operation:

502 Gateway Error: This typically indicates services haven't fully started. Wait 2-3 minutes after reconfiguration, then check service status:

sudo gitlab-ctl status
sudo gitlab-ctl tail

Out of Memory Errors: GitLab requires substantial RAM. If your server has limited memory, reduce worker processes:

unicorn['worker_processes'] = 2
sidekiq['max_concurrency'] = 10

SSL Certificate Issues: Verify certificate paths and permissions:

sudo ls -la /etc/letsencrypt/live/gitlab.yourdomain.com/
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart nginx

Database Connection Errors: PostgreSQL might need additional time to initialize. Check logs:

sudo gitlab-ctl tail postgresql

Git Push/Pull Failures: SSH key configuration or GitLab Shell issues often cause these problems:

sudo gitlab-rake gitlab:check
sudo gitlab-rake gitlab:shell:check

Backup and Maintenance Procedures

Regular backups protect against data loss and system failures. GitLab includes built-in backup functionality:

# Create manual backup
sudo gitlab-backup create

# Configure automatic daily backups
echo "0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1" | sudo crontab -u root -

Backup files are stored in /var/opt/gitlab/backups/ by default. Configure retention policies to manage disk usage:

gitlab_rails['backup_keep_time'] = 604800  # Keep backups for 7 days

Regular maintenance tasks include:

  • Update GitLab monthly following official upgrade paths
  • Monitor disk usage, especially for Git repositories and CI artifacts
  • Review security logs for suspicious activity
  • Test backup restoration procedures quarterly

GitLab vs Alternative Solutions

Comparing GitLab with other Git hosting solutions helps understand its positioning:

Feature GitLab CE GitHub Enterprise Bitbucket Server Gitea
Built-in CI/CD Yes Yes (Actions) Limited Yes (basic)
Issue Tracking Advanced Advanced Jira Integration Basic
Resource Usage High High Medium Low
Self-hosted Cost Free $21/user/month $3/user/month Free
Enterprise Features Limited Extensive Extensive Limited

GitLab's strength lies in its comprehensive DevOps platform approach, offering everything from planning to monitoring in a single application. However, this comes with higher resource requirements compared to lightweight alternatives like Gitea.

Real-World Use Cases and Applications

GitLab excels in several deployment scenarios:

Startup Development Teams: Small teams benefit from GitLab's integrated approach, eliminating the need for separate tools for project management, CI/CD, and code review. A typical setup on a VPS with 8GB RAM easily supports 10-20 active developers.

Enterprise Development: Large organizations often deploy GitLab on dedicated servers with high availability configurations. Multi-node setups distribute load across application, database, and storage servers.

Educational Institutions: Universities use GitLab for computer science courses, providing students with industry-standard development workflows. The built-in container registry supports Docker-based assignments and deployments.

Open Source Projects: GitLab's community features support collaborative development with merge request workflows, automated testing, and documentation hosting through GitLab Pages.

Advanced Configuration and Integration

Production GitLab deployments often require additional integrations:

LDAP Authentication: Connect GitLab to existing directory services:

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main:
  label: 'LDAP'
  host: 'ldap.company.com'
  port: 389
  uid: 'sAMAccountName'
  bind_dn: 'CN=ldapuser,OU=Users,DC=company,DC=com'
  password: 'ldappassword'
  encryption: 'plain'
  base: 'OU=Users,DC=company,DC=com'
EOS

Container Registry: Enable Docker image storage:

registry_external_url 'https://registry.gitlab.yourdomain.com'
gitlab_rails['registry_enabled'] = true

GitLab Pages: Host static websites from repositories:

pages_external_url 'https://pages.gitlab.yourdomain.com'
gitlab_pages['enable'] = true

These features require additional DNS configuration and SSL certificates but significantly expand GitLab's capabilities.

Monitoring and Health Checks

Maintaining GitLab health requires ongoing monitoring. Built-in health checks provide system status:

# Check GitLab health
sudo gitlab-rake gitlab:check

# Monitor service logs
sudo gitlab-ctl tail gitlab-rails
sudo gitlab-ctl tail sidekiq

External monitoring tools like Prometheus integrate well with GitLab's metrics endpoints. Enable monitoring by adding:

prometheus_monitoring['enable'] = true
grafana['enable'] = true

This provides detailed performance metrics accessible through GitLab's admin interface.

Setting up GitLab on Ubuntu creates a powerful foundation for modern software development workflows. While the initial resource requirements might seem substantial, the integrated DevOps capabilities often justify the investment for teams serious about streamlining their development processes. Regular maintenance, proper backup procedures, and performance monitoring ensure your GitLab instance remains reliable and responsive as your team grows.

For additional technical documentation and advanced configuration options, refer to the official GitLab installation documentation and Omnibus configuration guide.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked