
GitlabPart 1: Installing GitLab on Ubuntu 22.04
A step-by-step guide to installing GitLab CE on Ubuntu 22.04 using the Linux Package (Omnibus), from preparing the domain, SSL and SMTP to logging in as root and post-installation configuration.
Prerequisites
Before starting the installation, have the following ready so that installing and later running GitLab goes smoothly:
- A domain pointing to the gitlab-server's public IP: for example
gitlab.example.com, with an A record pointing to the server's public IP. This domain is used as theexternal_urlduring installation. - An external SMTP/API service for sending mail: GitLab needs to send email for tasks such as account confirmation, password resets, pipeline notifications, merge requests... You can use SMTP from Gmail, Amazon SES, SendGrid, Mailgun...
- A domain for the registry: if you use the GitLab Container Registry, it's best to have a dedicated domain, for example
registry.example.com, also pointing to the gitlab-server's IP. - SSL (if available): you can use your company's existing SSL certificate, or let GitLab obtain a free certificate from Let's Encrypt automatically (this requires the domain to be pointed correctly and ports 80 and 443 to be open to the Internet).
As for hardware, GitLab recommends that the server have at least 4 CPU cores and 4 GB RAM (enough for about 20 users). In practice, 8 GB RAM or more is more comfortable, especially if you also enable the Registry and CI/CD.
Installation methods
GitLab supports quite a few installation methods, depending on your infrastructure and use case:
- Docker/Docker Compose: runs GitLab as a container, convenient for labs, testing, or when your infrastructure is already standardized on containers.
- Linux Package (Omnibus): the method GitLab recommends for most cases. A single package bundles all the components (Nginx, PostgreSQL, Redis, Puma, Sidekiq, Gitaly...), making it easy to install and upgrade.
- Helm chart (k8s): deploys GitLab on Kubernetes, suited to large systems that need to scale individual components.
- GitLab Operator (k8s): manages the GitLab lifecycle on Kubernetes/OpenShift through an Operator.
- Build from source code: building from source yourself is the most flexible option, but also the most complex and maintenance-heavy. Only use it if you genuinely have special requirements.
In this post I'll use the Linux Package (Omnibus) method because it's simple, stable, and fits most self-hosting needs.
Installing GitLab CE Server via Package (Omnibus Method)
- Docs ref: https://about.gitlab.com/install/#ubuntu
- Deployment OS: Ubuntu 22.04 LTS
- Edition: GitLab Community Edition (CE)
Step 1: Update the system
First, refresh the package list and upgrade the system:
Step 2: Install dependencies
Install the required packages:
If the server has a firewall (UFW) enabled, open the ports needed for SSH, HTTP and HTTPS:
Step 3: Install Postfix (optional)
If you want to send mail directly from the server, you can install Postfix:
During installation, choose Internet Site and enter the server's domain. However, as mentioned in the Prerequisites section, I recommend using External SMTP for reliability and to avoid being flagged as spam. If you use External SMTP, you can skip this step and configure SMTP after installation.
Step 4: Add the GitLab package repository
Run GitLab's script to add the official repository to the system:
Step 5: Install GitLab CE
When installing, set the EXTERNAL_URL variable to the domain you prepared. If you use https://, GitLab will automatically request an SSL certificate from Let's Encrypt:
You can specify a particular version if needed. List the versions available in the repository with apt-cache madison gitlab-ce, then install it like this:
Installation takes a few minutes depending on the server's specs. When it finishes, GitLab automatically runs gitlab-ctl reconfigure to initialize the services.
Step 6: Get the root password and log in
After installation, GitLab generates a random password for the root account and stores it in the file:
Go to https://gitlab.example.com, log in as root with the password you just retrieved, then go to Edit profile → Password to change it.
Step 7: Check the status of the services
Check that all GitLab components are up and running:
Some commonly used commands for day-to-day operations:
sudo gitlab-ctl reconfigure: reapplies the configuration after editing/etc/gitlab/gitlab.rb.sudo gitlab-ctl restart: restarts all services.sudo gitlab-ctl tail: view real-time logs of the services.sudo gitlab-rake gitlab:check SANITIZE=true: run an overall check of the GitLab configuration.
Step 8: Post-installation configuration
All GitLab Omnibus configuration lives in the /etc/gitlab/gitlab.rb file. After every edit, remember to run sudo gitlab-ctl reconfigure.
Configuring External SMTP, for example with Gmail:
Apply the configuration:
Then send a test email from the Rails console to verify: