How To Install Gitlab On Ubuntu 20.04

How To Install Gitlab On Ubuntu 20.04

Reading time1 min
#DevOps#OpenSource#Cloud#GitLab#Ubuntu#CI/CD

Step-by-Step Guide to Installing a Secure and Efficient GitLab Instance on Ubuntu 20.04

GitLab is essential for modern DevOps workflows, offering integrated CI/CD pipelines, repository management, and collaboration tools all in one platform. Installing it correctly on Ubuntu 20.04 ensures your development environment remains stable, secure, and scalable as your team grows.

Forget complex setups or cloud dependencies—this guide breaks down the exact steps to get a reliable, self-hosted GitLab running swiftly on Ubuntu 20.04, empowering you to keep full control over your infrastructure.


Why Self-Host GitLab?

Before jumping into installation, let's remind ourselves why self-hosting GitLab is valuable:

  • Full control of data and access — No third-party involvement.
  • Customizable infrastructure — Tailor performance and resources to your project needs.
  • Integrated DevOps stack — Source control, CI/CD pipelines, container registry, and monitoring.
  • Cost-effective — Avoid recurring cloud subscription fees.

With that in mind, here’s how to get your own GitLab server up and running.


Prerequisites

  • A clean Ubuntu 20.04 server (physical or VPS) with at least 2 CPU cores and 4GB RAM (8GB recommended for larger teams or CI runners).
  • A non-root user with sudo privileges.
  • Static IP assigned to the server.
  • Domain name pointed to the server’s IP (optional but highly recommended for SSL).

Step 1: Update Your System

Log in to your Ubuntu server via SSH:

ssh user@your-server-ip

Update package lists and upgrade existing packages:

sudo apt update && sudo apt upgrade -y

Reboot if necessary:

sudo reboot

Step 2: Install Required Dependencies

GitLab requires curl, openssh-server, ca-certificates, postfix (for email notifications), and more. Install them with:

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

For email notifications (adjust postfix installation according to your mail system):

sudo apt install -y postfix

During postfix configuration, select "Internet Site" and enter your domain name as system mail name.


Step 3: Add GitLab Package Repository

Download the official GitLab installation script from their repository:

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

This script adds the GitLab package repository to your system sources.


Step 4: Install GitLab Community Edition

You can install either GitLab CE (community edition) or EE (enterprise edition if you have license). For this guide, we will install CE.

Replace gitlab.example.com with your domain or server IP:

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

The installation process may take several minutes as it configures all necessary components like PostgreSQL database, Redis cache, Gitaly storage service etc.


Step 5: Configure GitLab

After installation finishes, run the following command to reconfigure GitLab with correct settings:

sudo gitlab-ctl reconfigure

This command initializes databases and sets up all required internal services.


Step 6: Access Your GitLab Web Interface

Visit http://gitlab.example.com (or use IP if no domain assigned). The first time you visit:

  • You’ll be prompted to set a password for the default root user.
  • Log in with username root and the password you just set.

Tip: Replace HTTP with HTTPS by setting up SSL for secure connections.


Step 7: Enable HTTPS with Let’s Encrypt (Optional but Recommended)

If you have a domain name pointing at your server:

  1. Update /etc/gitlab/gitlab.rb configuration file:
sudo nano /etc/gitlab/gitlab.rb

Edit or add these lines (replace gitlab.example.com):

external_url "https://gitlab.example.com"
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['your-email@example.com'] # This should be an array of emails that get notified about cert expiration.
nginx['redirect_http_to_https'] = true
  1. Reconfigure GitLab services to apply changes:
sudo gitlab-ctl reconfigure
  1. Ensure ports 80 and 443 are open on your firewall/security group settings.

Now access your instance securely via HTTPS!


Step 8: Basic Security Hardening Recommendations

To keep your instance secure:

  • Regularly update GitLab by running:

    sudo apt update && sudo apt upgrade gitlab-ce -y && sudo gitlab-ctl reconfigure
    
  • Limit SSH access by disabling password login; use SSH keys instead.

  • Use strong passwords or enable two-factor authentication in user profiles.

  • Configure backups by scheduling periodic dumps via cron using built-in rake tasks:

    To create a backup manually:

    sudo gitlab-backup create STRATEGY=copy SKIP=registry
    

    Backups are saved under /var/opt/gitlab/backups.


Optional: Configure Email Notifications Properly

Email notifications are essential for CI/CD alerts etc. If postfix isn’t suitable or you want integration with SMTP services like Gmail or SendGrid, configure it in /etc/gitlab/gitlab.rb like so:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.sendgrid.net"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "apikey"
gitlab_rails['smtp_password'] = "your_sendgrid_api_key"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true 

Then reconfigure again:

sudo gitlab-ctl reconfigure

Test emails via GitLab UI under admin settings after login.


Conclusion

You now have a fully functional, self-hosted GitLab instance running securely on Ubuntu 20.04! You can start creating projects, invite team members, configure CI/CD pipelines, manage container registries, and much more—all without dependency on external cloud providers.

Quick Recap:

  1. Update Ubuntu system packages.
  2. Install dependencies including postfix mail service.
  3. Add official GitLab repo via curl script.
  4. Install gitlab-ce.
  5. Reconfigure GitLab services.
  6. Access web interface and set root password.
  7. Enable HTTPS with Let’s Encrypt SSL certificates for security.
  8. Harden security by managing updates, SSH keys, backups & multi-factor authentication.

Feel free to bookmark this post as reference whenever setting up or scaling new DevOps environments!

If you liked this step-by-step tutorial or have any questions about customizing your setup—drop a comment below! Happy coding & deploying!


Author: Your Name
Date: [Today’s date]