GitLab is a DevSecOps platform that provides all the tools required in a software development cycle from Git repo hosting and issue tracking to CI/CD, container repos, and more.
There are multiple GitLab versions suited for different use cases and environments. In this article, we’ll install the free community edition (GitLab CE), cover the steps to host a GitLab instance on your own hardware, and also discuss further configuration.
Install GitLab Dependencies
First, update your package index and install the latest versions of the necessary dependencies.
sudo apt update && sudo apt install -y curl openssh-server ca-certificates tzdata perl postfix
When installing the Postfix package, you’ll be prompted to select the Mail server configuration type. Select Internet Site and press Ok.
Enter your server’s domain name in the mail name section and press Enter for this and any further prompts.
Add GitLab Repo and Install GitLab
It is possible to download the GitLab package from the Ubuntu repo and install it offline if it’s ever required. But in most cases, it’s best to add the GitLab repo using the official script and install GitLab using apt.
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
sudo bash script.deb.sh
After setting up the repo, install GitLab with
sudo apt install gitlab-ce
Configure Your GitLab Instance
After installing GitLab, you’ll be prompted to set the external URL. We’ll use nano to configure this, but you can use any text editor you prefer.
sudo nano /etc/gitlab/gitlab.rb
Search for the
external_url directive here. With nano, you can use WhereIs (Ctrl + W) to find it easily.
Change it to your own domain or server address and save the changes (Ctrl + O for nano).
Finally, use the following command to initialize GitLab with the configurations defined just now.
sudo gitlab-ctl reconfigure
Log In To GitLab
By default, GitLab randomly generates a password and stores it in the
/etc/gitlab/initial_root_password file. Check the password from this file with
sudo cat /etc/gitlab/initial_root_password
Enter your domain name or server address in a web browser to get to the GitLab login page. Enter the username (root) and the password from earlier here and press Sign In.
After logging in, there are a few things to take care of first. Expand the user menu from the top-right and select Edit profile. You should change your username and email settings here as the default values are not secure.
Go to the Password tab next. Instead of using the randomly generated password, you can set your own password here. You can also set up 2FA (Two Factor Authentication) from the Account tab for further improved security.
Or even better, you can use SSH keys to authenticate to the GitLab server instead of the username-password. To do this, go to the SSH Keys tab, paste your public key into the Key field, and press Add key.
Beyond these immediate changes, there are a lot of customization options available to you. You can manage sign-up/sign-in restrictions, project visibility, size limits, etc. from the Admin section, visual configs like themes from Preferences, and so on.
If you feel lost on where to start or what to change next, I recommend checking out the official docs for reference on what to do after installing GitLab.