In this tutorial, we'll learn to set up GitLab on Ubuntu 24.04 server for for Version Control and CI/CD.
In today's fast-paced IT environment, a robust version control system paired with continuous integration and deployment capabilities is essential for efficient development workflows. GitLab offers a powerful, self-hosted solution that combines Git repository management with built-in CI/CD pipelines. In this guide, we'll walk you through setting up GitLab on an Ubuntu 24.04 server—from installing the software and configuring secure SSH access to enabling HTTPS with SSL certificates.
Whether you're a developer or a system administrator, this step-by-step tutorial is designed to provide you with a deep understanding of each component, ensuring a smooth setup process and a solid foundation for your DevOps practices.
Prerequisites:
- A Ubuntu 24.04 installed dedicated server or KVM VPS.
- A root user or normal user with administrative privileges.
- A domain name point A record to server's IP
Set Up GitLab on Ubuntu 24.04
1. Prepare Your Server
Before installing GitLab, it’s essential to update your system and install some prerequisites. Open a terminal on your Ubuntu 24.04 server and run:
sudo apt update && sudo apt upgrade -y
Then install necessary packages such as curl, OpenSSH (to allow Git operations over SSH), and other utilities:
sudo apt install -y curl openssh-server ca-certificates tzdata perl
These tools help with downloading files, handling secure connections, and managing time zones—ensuring your server runs smoothly.
2. Set the Hostname and Domain
GitLab needs a proper hostname (ideally a Fully Qualified Domain Name, FQDN) so that it can generate correct links and certificates. If you haven’t set one yet, you can do so by editing your hostname:
sudo hostnamectl set-hostname gitlab.example.com
Make sure your domain (e.g., gitlab.example.com
) points to your server’s IP address via DNS. This step is crucial when later configuring HTTPS and SSL certificates.
3. Add the GitLab Repository
GitLab provides an “Omnibus” package that bundles all its components. To install it, add GitLab’s official repository. Run:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
This script sets up your system so that you can install GitLab Community Edition (CE) directly via APT. (If you prefer the Enterprise Edition, the process is similar, but you’ll need a license.)
4. Install GitLab
With the repository configured, install GitLab CE by setting the external URL. Even if you plan to secure the connection later with HTTPS, you can initially set the URL with HTTP or HTTPS as needed. For example, if you plan to use HTTPS:
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ce
During installation, the package places its configuration file at /etc/gitlab/gitlab.rb
and sets up its internal services. This process may take a few minutes.
5. Configure Firewall
Before proceeding further, we need to configure firewall.
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
6. Configure HTTPS for Secure Connections
Securing your GitLab instance is critical—especially when handling source code and CI/CD pipelines. GitLab can automatically configure HTTPS with Let's Encrypt, or you can use custom SSL certificates.
Using Let's Encrypt:
Open /etc/gitlab/gitlab.rb
in your favorite text editor:
sudo nano /etc/gitlab/gitlab.rb
Find or add these lines, modifying them with your domain and contact email:
external_url "https://gitlab.example.com"
# Enable Let's Encrypt integration for automatic SSL certificate management
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['your_email@example.com'] # Replace with your email
Save the file and exit the editor. Then apply the changes:
sudo gitlab-ctl reconfigure
GitLab will now automatically request and install a certificate from Let’s Encrypt. Note that DNS must correctly point to your server for this to succeed.
Using Custom Certificates:
If you have your own SSL certificate and key, place them in a secure directory (e.g., /etc/gitlab/ssl/
) and update /etc/gitlab/gitlab.rb
:
external_url "https://gitlab.example.com"
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
After saving, run:
sudo gitlab-ctl reconfigure
This configuration tells GitLab’s integrated NGINX server to serve your site over HTTPS using your provided certificates.
7. Configure SSH Keys for Secure Git Operations
SSH keys allow you to securely push and pull code without entering passwords every time. You’ll generate a key pair on your local machine and add the public key to your GitLab account.
Generate an SSH Key Pair:
On your local computer (Linux, macOS, or using Git Bash on Windows), run:
ssh-keygen -t ed25519 -C "your_email@example.com"
- -t ed25519: Specifies the algorithm (modern and secure).
- -C "your_email@example.com": Adds a label for identification.
You’ll be prompted for a file path (press Enter to accept the default) and a passphrase (optional but recommended for extra security).
Add the SSH Key to GitLab:
Display your public key content:
cat ~/.ssh/id_ed25519.pub
Copy the output.
- Log in to your GitLab web interface at https://gitlab.example.com.
- Click your user avatar (top right) → Preferences → SSH Keys.
- Paste your public key into the Key field, add a descriptive Title, and click Add key.
Now, when you clone repositories or push code, Git will use this SSH key for authentication.
8. Verify Your Installation
Open your web browser and navigate to:
https://gitlab.example.com
You should see GitLab’s login page. The first time you access it, you might be prompted to set the root user password. Once logged in, explore the interface to familiarize yourself with project creation, repository management, and CI/CD pipelines. Default root password is in following file:
cat /etc/gitlab/initial_root_password
9. Set Up a Basic CI/CD Pipeline
GitLab CI/CD is defined by a .gitlab-ci.yml file placed at the root of your project repository. Here’s a simple example that defines two stages—build and test:
stages:
- build
- test
build_job:
stage: build
script:
- echo "Building the project..."
test_job:
stage: test
script:
- echo "Running tests..."
To Implement This:
Create a new project on your GitLab instance.
Clone the project locally:
git clone git@gitlab.example.com:your_username/your_project.git
In the project directory, create a file named .gitlab-ci.yml and paste the above YAML configuration.
Commit and push the file:
git add .gitlab-ci.yml
git commit -m "Add basic CI/CD pipeline configuration"
git push origin main
GitLab will automatically detect the pipeline configuration and trigger the defined jobs.
Note: For the pipeline to run, you need at least one GitLab Runner registered. You can install a runner on a separate machine or even on the same server, following GitLab’s official documentation.
10. (Optional) Install and Register a GitLab Runner
GitLab Runner executes the CI/CD jobs defined in your .gitlab-ci.yml
file. To install it on Ubuntu:
Add the Runner repository:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
Install GitLab Runner:
sudo apt-get install gitlab-runner
Register the runner with your GitLab instance by running:
sudo gitlab-runner register
- URL: Use your GitLab instance URL (e.g., https://gitlab.example.com).
- Registration Token: Find this token in your GitLab project’s Settings → CI/CD under the Runners section.
- Follow the prompts to set the runner’s description, tags, and executor (commonly, shell or docker).
Final Thoughts
In this tutorial, we've learnt to set up GitLab on Ubuntu 24.04 server. At this point, your GitLab server on Ubuntu 24.04 should be fully operational with version control, secure HTTPS access, and a basic CI/CD pipeline ready to run. You’ve also learned how to set up SSH keys to streamline secure Git operations.
Be sure to explore GitLab’s extensive documentation to tailor the configuration to your organization’s needs, expand your CI/CD pipelines, and take full advantage of GitLab’s powerful features. Happy coding and automating!