Header

How to Deploy GitLab on a VPS: A Step-by-Step Guide

Git, Open Source, Tips & Tricks, and Tutorials

Post Image

GitLab is a powerful, open-source DevOps platform that provides a complete solution for managing your source code, continuous integration, and deployment. In this guide, we'll walk you through the process of deploying GitLab on a Virtual Private Server (VPS) using the official installation method.

Prerequisites

Before you begin, ensure you have:

  • A VPS running Ubuntu 20.04 LTS
  • Root access to the server
  • At least 2GB of RAM (4GB recommended)
  • A domain name pointed to your server's IP address
  • Minimum Hard Drive Space:
    • 50GB for basic installation
    • 100GB recommended for repositories and backups
    • Storage breakdown:
    • GitLab installation: 5-10GB
    • Operating system: 10GB
    • Repository storage: 20-50GB
    • Backup space: 10-20GB

For teams with larger repositories or more projects, consider:

  • 250GB for medium-sized teams
  • 500GB+ for large organizations

Step 1: Prepare the Server

First, update your system packages:

sudo apt-get update
sudo apt-get upgrade -y

Install necessary dependencies:

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

Step 2: Install GitLab Repository

Add the official GitLab repository:

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

Note: This example uses GitLab Enterprise Edition (EE). For the community edition, use gitlab-ce instead.

Step 3: Install GitLab

Install GitLab using the following command:

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

Replace gitlab.yourdomain.com with your actual domain name.

Step 4: Configure GitLab

After installation, configure GitLab using the built-in configuration tool:

sudo gitlab-ctl reconfigure

We recommend using Let's Encrypt for free SSL certificates:

sudo gitlab-ctl stop
sudo certbot certonly --standalone -d gitlab.yourdomain.com
sudo gitlab-ctl reconfigure

Step 6: Initial Setup

Open your browser and navigate to the domain you configured. You'll be prompted to set an initial password for the root user.

Step 7: Additional Security Configurations

  • Enable two-factor authentication
  • Configure firewall rules
  • Set up regular backups
sudo gitlab-backup create

Storage Management Tips

To manage your GitLab storage effectively:

  • Regularly clean up old repositories
  • Use Git LFS for large files
  • Configure repository size limits
  • Implement backup rotation strategies

You can check current storage usage with:

sudo gitlab-rake gitlab:env:info

Common Troubleshooting Tips

  • Check GitLab status: sudo gitlab-ctl status
  • Restart GitLab: sudo gitlab-ctl restart
  • View logs: sudo gitlab-ctl tail

Performance Optimization

For better performance on a VPS:

  • Allocate more RAM
  • Use SSD storage
  • Configure Redis and PostgreSQL caching
  • Monitor storage and upgrade as needed

Deployment with DeployHQ

While GitLab has built-in CI/CD capabilities, DeployHQ can complement your workflow by providing:

  • Simple deployment workflows
  • Multi-server support
  • Detailed deployment logs
  • Easy integration with various repository types

Conclusion

Deploying GitLab on a VPS provides a robust, self-hosted solution for your development workflow. With careful configuration, regular maintenance, and proper storage management, you can create a powerful DevOps platform tailored to your needs.

Pro Tip: Always keep your GitLab installation updated to ensure you have the latest features and security patches. Regularly monitor your storage usage and plan for scalability.


Have questions about GitLab deployment or want to streamline your deployment process? Contact DeployHQ today!

A little bit about the author

Facundo | CTO | DeployHQ | Continuous Delivery & Software Engineering Leadership - As CTO at DeployHQ, Facundo leads the software engineering team, driving innovation in continuous delivery. Outside of work, he enjoys cycling and nature, accompanied by Bono 🐶.

Tree

Proudly powered by Katapult. Running on 100% renewable energy.