15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
31.10.2024
1 +1

How to Install GitLab on Ubuntu: Complete Step-by-Step Guide

GitLab is one of the most powerful open-source DevOps platforms available today, offering a comprehensive suite of tools including Git-based version control, continuous integration/continuous delivery (CI/CD) pipelines, issue tracking, and team collaboration features — all under one roof. Whether you're managing a small development team or running enterprise-scale software projects, self-hosting GitLab on Ubuntu gives you full control over your data, workflows, and infrastructure.

This guide walks you through every step of installing and configuring GitLab Community Edition (CE) on an Ubuntu server, from initial system preparation to enabling HTTPS and managing services.

Prerequisites

Before you begin, make sure you have the following in place:

  • A server running Ubuntu 20.04 or 22.04 LTS (fresh installation recommended)
  • A minimum of 4 GB RAM and 2 CPU cores (GitLab recommends at least 4 cores for production use)
  • Root or sudo access to the server
  • A registered domain name pointing to your server's IP address (optional but strongly recommended for HTTPS)
  • Ports 80 and 443 open in your firewall

> Tip: For the best GitLab performance, consider deploying on a VPS Hosting plan with sufficient RAM and CPU resources. AlexHost VPS plans are optimized for Linux workloads and come with full root access, making them an ideal environment for self-hosted DevOps platforms like GitLab.

Step 1: Update System Packages

Before installing any software, it is critical to ensure your system's package index and installed packages are fully up to date. This prevents dependency conflicts and ensures you're working with the latest security patches.

sudo apt update && sudo apt upgrade -y

Wait for the upgrade process to complete before proceeding to the next step.

Step 2: Install Required Dependencies

GitLab requires several supporting packages to function correctly, including tools for secure communication, time zone management, and scripting. Install them with the following command:

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

Here's what each package does:

PackagePurpose
curlDownloads scripts and files from the web
openssh-serverEnables SSH access to your server
ca-certificatesValidates SSL/TLS certificates
tzdataProvides time zone data
perlRequired for GitLab's internal scripts

Step 3: Add the Official GitLab Repository

GitLab maintains an official package repository that makes installation and future upgrades straightforward. Use the following command to download and execute the repository setup script:

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

This script automatically:

  • Detects your Ubuntu version
  • Adds the GitLab package repository to your APT sources
  • Imports the repository's GPG signing key for package verification

Once the script completes, your system is ready to install GitLab directly from the official source.

Step 4: Install GitLab Community Edition

Now install GitLab CE using the apt package manager. You must set the EXTERNAL_URL environment variable to the URL or IP address through which users will access your GitLab instance.

If you have a domain name:

sudo EXTERNAL_URL="https://gitlab.yourdomain.com" apt install gitlab-ce

If you're using an IP address (e.g., for a local or private server):

sudo EXTERNAL_URL="http://YOUR_SERVER_IP" apt install gitlab-ce

Replace gitlab.yourdomain.com or YOUR_SERVER_IP with your actual domain or IP address.

> Note: The installation process may take several minutes as it downloads and configures all GitLab components, including PostgreSQL, Redis, NGINX, and Sidekiq.

During installation, GitLab will:

  • Install all bundled services (database, cache, web server, etc.)
  • Configure itself based on the EXTERNAL_URL you provided
  • Generate initial configuration files in /etc/gitlab/

Step 5: Run the GitLab Reconfiguration

After installation, run the reconfiguration command to finalize the setup, initialize the database, and start all GitLab services:

sudo gitlab-ctl reconfigure

This command reads the configuration from /etc/gitlab/gitlab.rb and applies all settings. It also generates SSL certificates (if Let's Encrypt is configured), sets up the database schema, and starts all required background services.

You should see a long output ending with a message similar to:

gitlab Reconfigured!

Step 6: Access GitLab in Your Web Browser

Once reconfiguration is complete, open your web browser and navigate to the URL you specified during installation:

https://gitlab.yourdomain.com

or

http://YOUR_SERVER_IP

First-Time Login

On your first visit, GitLab will prompt you to set an administrator password. After setting it, log in using the following credentials:

  • Username: root
  • Password: The password you just created

> Security Tip: Change the default root account credentials immediately after your first login. Create a personal admin account and restrict the root account for emergency use only.

Step 7: Configure GitLab Email Notifications (Optional)

Sending email notifications is essential for a production GitLab instance — it enables features like account verification, merge request updates, CI/CD alerts, and password resets. Configure SMTP settings in the main GitLab configuration file:

sudo nano /etc/gitlab/gitlab.rb

Add or modify the following SMTP configuration block:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.yourmailprovider.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your_email@yourdomain.com"
gitlab_rails['smtp_password'] = "your_email_password"
gitlab_rails['smtp_domain'] = "yourdomain.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true

Save the file and apply the changes:

sudo gitlab-ctl reconfigure

> Looking for a reliable email infrastructure? AlexHost offers professional Email Hosting services that integrate seamlessly with self-hosted applications like GitLab, providing stable SMTP relay with high deliverability.

Running GitLab over HTTPS is strongly recommended for any production or team environment. GitLab has built-in support for Let's Encrypt, a free and automated SSL certificate authority.

> Important: Let's Encrypt requires that your domain name is publicly accessible and that port 80 is open on your server. It will not work with raw IP addresses.

Open the GitLab configuration file:

sudo nano /etc/gitlab/gitlab.rb

Add the following configuration:

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['your_admin_email@yourdomain.com']
letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = 12
letsencrypt['auto_renew_minute'] = 30
letsencrypt['auto_renew_day_of_month'] = "*/7"

Save the file and reconfigure GitLab:

sudo gitlab-ctl reconfigure

GitLab will automatically obtain and install your SSL certificate, and the auto_renew setting ensures it is renewed before expiration without any manual intervention.

> Alternative: If you prefer to manage SSL certificates independently or need wildcard/multi-domain certificates, AlexHost offers a range of SSL Certificates that can be manually configured in GitLab's NGINX settings.

Step 9: Managing GitLab Services

GitLab bundles its own service management tool called gitlab-ctl. Use the following commands to control GitLab services:

Start GitLab

sudo gitlab-ctl start

Stop GitLab

sudo gitlab-ctl stop

Restart GitLab

sudo gitlab-ctl restart

Check Service Status

sudo gitlab-ctl status

View Real-Time Logs

sudo gitlab-ctl tail

View Logs for a Specific Service (e.g., NGINX)

sudo gitlab-ctl tail nginx

These commands are invaluable for troubleshooting and routine maintenance. The status command will display the state of all GitLab sub-services, including PostgreSQL, Redis, Sidekiq, Puma (web server), and NGINX.

Step 10: Initial GitLab Configuration for Your Organization

With GitLab installed and running, it's time to configure it for your team's needs. Here are the key areas to set up through the GitLab web interface:

User Management

Navigate to Admin Area → Users to create user accounts for your team members. You can configure authentication methods, including LDAP, OAuth, and SAML for enterprise single sign-on.

Groups and Projects

  • Groups allow you to organize related projects and manage permissions at scale
  • Projects are individual repositories with their own issue trackers, wikis, and CI/CD pipelines

CI/CD Pipelines

GitLab's built-in CI/CD is one of its most powerful features. Create a .gitlab-ci.yml file in your repository root to define automated build, test, and deployment pipelines.

Repository Settings

Configure branch protection rules, merge request approvals, and code review workflows under each project's Settings → Repository section.

Backup Configuration

Set up automated backups by configuring the following in /etc/gitlab/gitlab.rb:

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_keep_time'] = 604800  # Keep backups for 7 days

Run a manual backup at any time with:

sudo gitlab-backup create

Firewall Configuration

If you have UFW (Uncomplicated Firewall) enabled on your Ubuntu server, make sure to allow HTTP and HTTPS traffic:

sudo ufw allow http
sudo ufw allow https
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Troubleshooting Common Issues

IssueSolution
GitLab not accessible after installCheck firewall rules; verify EXTERNAL_URL in /etc/gitlab/gitlab.rb
502 Bad Gateway errorRun sudo gitlab-ctl restart; check logs with sudo gitlab-ctl tail
Let's Encrypt certificate failureEnsure port 80 is open and domain DNS is correctly configured
High memory usageReduce Puma workers in gitlab.rb: puma['worker_processes'] = 2
Email notifications not sendingVerify SMTP credentials and run sudo gitlab-rails console to test

Conclusion

Installing GitLab on Ubuntu is a straightforward process that delivers an enterprise-grade DevOps platform under your complete control. By following this guide, you've set up a fully functional GitLab instance with HTTPS encryption, email notifications, and proper service management — ready for real-world development workflows.

Self-hosting GitLab gives your team the freedom to customize workflows, maintain data sovereignty, and integrate with your existing infrastructure without recurring SaaS subscription costs. The key to a smooth GitLab experience is starting with a reliable, high-performance server.

For teams that need a robust foundation for GitLab, AlexHost's Dedicated Servers offer maximum performance and isolation, while VPS Hosting plans provide a cost-effective and scalable alternative for smaller teams and growing projects. Both options come with full root access, SSD storage, and 24/7 technical support — everything you need to run GitLab with confidence.

15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started