8️⃣ Setting Up a Self-Hosted GitLab Instance
GitLab self-hosting refers to running your own instance of GitLab on your own server instead of using GitLab's cloud-based services (GitLab.com). This allows organizations or individuals to have full control over their repositories, CI/CD pipelines, and development workflows while keeping their data private.
Step 1: Update System and Install Dependencies
Before installing GitLab, update and upgrade your system packages:
sudo apt update && sudo apt upgrade -y
GitLab requires some essential packages. Install them using:
sudo apt install -y curl openssh-server ca-certificates tzdata perl
If you want GitLab to send emails (e.g., password resets), install Postfix:
sudo apt install -y postfix
Step 2: Install GitLab
Download the GitLab repository script and install the package:
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
If you want the free Community Edition (CE) instead of the Enterprise Edition (EE), replace gitlab-ee
with gitlab-ce
in the script above.
Replace <YOUR_DOMAIN>
with your actual domain (or use your server’s IP address if you don’t have one).
sudo EXTERNAL_URL="http://<YOUR_DOMAIN>" apt install -y gitlab-ee
For HTTPS, use:
sudo EXTERNAL_URL="https://<YOUR_DOMAIN>" apt install -y gitlab-ee
GitLab will install and configure itself.
Step 3: Configure GitLab
The main configuration file is:
sudo nano /etc/gitlab/gitlab.rb
You can change settings like:
- External URL
- Port bindings
- Email settings
- Backup configuration
After making changes, apply them:
sudo gitlab-ctl reconfigure
Step 4: Adjust Firewall Settings
If you have UFW (Uncomplicated Firewall) enabled, allow necessary ports:
sudo ufw allow http
sudo ufw allow https
sudo ufw allow OpenSSH
sudo ufw enable
Step 5: Access GitLab Web Interface
Open your browser and go to:
http://<YOUR_DOMAIN> or http://<YOUR_SERVER_IP>
The first time, GitLab will ask for the root password. Get it using:
sudo cat /etc/gitlab/initial_root_password
Log in with the username set as root
and the password obtained from the file above.
Step 6: Optional Configurations
Enable Auto-Start on Boot
Ensure GitLab runs on every system startup:
sudo systemctl enable gitlab-runsvdir
Backup GitLab
Create a backup to prevent data loss:
sudo gitlab-backup create
Backups are stored in /var/opt/gitlab/backups/
.
Conclusion
You now have a fully functional self-hosted GitLab instance running on Ubuntu 22.04. You can start creating repositories, setting up CI/CD, and managing users.