Sunday, November 22, 2026
TR
LinuxOpen Source

How to Install and Configure GitLab on Ubuntu 18.04

How to Install and Configure GitLab on Ubuntu 18.04
Contents
  1. Introduction
  2. Prerequisites
  3. Step 1 – Installing Dependencies
  4. Step 2 – Installing GitLab
  5. Step 3 – Adjusting Firewall Rules
  6. Step 4 – Editing the GitLab Configuration File
  7. Step 5 – Performing the Initial Configuration Through the Web Interface
  8. Logging In for the First Time
  9. Adjusting Your Profile Settings
  10. Changing Your Account Name
  11. Adding an SSH Key to Your Account
  12. Step 6 – Restricting or Disabling Public Sign-ups (Optional)
  13. Disabling Sign-ups
  14. Restricting Sign-ups by Domain
  15. Restricting Project Creation
  16. Renewing Let's Encrypt Certificates
  17. Conclusion

Introduction

GitLab CE , or Community Edition, is an open-source application primarily used to host Git repositories, with additional development-related features such as issue tracking. It is designed to be hosted on your own infrastructure and provides flexibility in deploying it as an internal repository store for your development team, a public way to interface with users, or a tool for contributors to host their own projects.

The GitLab project makes it relatively easy to set up a GitLab instance on your own hardware with an easy installation mechanism. In this guide, we will cover how to install and configure GitLab on an Ubuntu 18.04 server.

Prerequisites

For this tutorial you will need:

We recommend using a server with the published GitLab hardware requirements :

  • 2 cores
  • 8 GB RAM

Although you may be able to get by with swapping some space for RAM, it is not recommended. For this guide, we will assume that you have at least the above resources.

Step 1 – Installing Dependencies

Before installing GitLab, it is important to install some software that it uses during installation and on an ongoing basis. Fortunately, all the required software can be easily installed from Ubuntu's default package repositories.

Since this is the first time we are using apt in this session, we can refresh the local package index and then install the dependencies by typing:

sudo apt update
sudo apt install ca-certificates curl openssh-server postfix

You will probably already have some of this software. For the postfix installation, select Internet Site when prompted. On the next screen, enter your server's domain name to configure how the system will send mail.

Step 2 – Installing GitLab

Now that the dependencies are in place, we can install GitLab itself. This is a straightforward process that uses an installation script to configure your system with the GitLab repositories.

Move into the /tmp directory and then download the installation script:

cd /tmp
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
less /tmp/script.deb.sh

Once you are satisfied that the script is safe, run the installer:

sudo bash /tmp/script.deb.sh

The script will set up your server to use the repositories maintained by GitLab. This lets you manage GitLab with the same package management tools you use for your other system packages. Once this is complete, you can install the actual GitLab application with apt:

sudo apt install gitlab-ce

This will install the necessary components on your system.

Step 3 – Adjusting Firewall Rules

Before configuring GitLab, you need to make sure your firewall rules are permissive enough to allow web traffic. If you followed the guide linked in the prerequisites, you will have a ufw firewall enabled.

View the current status of your active firewall by typing:

sudo ufw status
OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)

As you can see, the current rules allow SSH traffic through, but access to other services is restricted. Since GitLab is a web application, we should allow HTTP access. Because we will take advantage of GitLab's ability to request and automatically provision a free TLS/SSL certificate from Let's Encrypt , we will also allow HTTPS access.

The protocol-to-port mapping for HTTP and HTTPS is available in the /etc/services file, so we can allow that traffic by name. If you do not already have OpenSSH traffic enabled, you should allow that traffic now as well:

sudo ufw allow http
sudo ufw allow https
sudo ufw allow OpenSSH

Check ufw status again; you should see access configured for at least these two services:

sudo ufw status
OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)

The output above indicates that the GitLab web interface will be accessible once we configure the application.

Step 4 – Editing the GitLab Configuration File

Before you can use the application, you need to update the configuration file and run a reconfiguration command. First, open GitLab's configuration file:

sudo nano /etc/gitlab/gitlab.rb

Near the top is the external_url configuration line. Update it to match your domain. Change http to https so that GitLab automatically redirects users to the site protected by the Let's Encrypt certificate:/etc/gitlab/gitlab.rb

##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'https://example.com'

Next, look for the letsencrypt['contact_emails'] setting. This setting defines a list of email addresses that the Let's Encrypt project can use to contact you if there are problems with your domain. It is a good idea to uncomment and fill it in so you know about any issues:/etc/gitlab/gitlab.rb

letsencrypt['contact_emails'] = ['sammy@example.com']

Save and close the file. Run the following command to reconfigure GitLab:

sudo gitlab-ctl reconfigure

This will initialize GitLab using the information it can find about your server. This is a completely automated process, so you will not have to answer any questions. The process will also configure a Let's Encrypt certificate for your domain.

Step 5 – Performing the Initial Configuration Through the Web Interface

With GitLab running and access permitted, we can perform some initial configuration of the application through the web interface.

Logging In for the First Time

Visit your GitLab server's domain name in your web browser:

https://example.com

On your first visit, you should see an initial prompt asking you to set a password for the administrator account:

At the initial password prompt, provide and confirm a secure password for the administrator account. Click the Change your password button when you are done.

You will be redirected to the conventional GitLab login page:

Here, you can log in with the password you just set. The credentials are:

  • Username: root
  • Password: [the password you set]

Enter these values in the fields for existing users and click the Sign in button. You will be logged in to the application and taken to a landing page that prompts you to begin adding projects:

You can now make some simple changes to set up GitLab the way you want.

Adjusting Your Profile Settings

One of the first things you should do after a fresh installation is get your profile into better shape. GitLab selects some reasonable defaults, but these are often not appropriate once you start using the software.

To make the necessary changes, click the user icon in the top-right corner of the interface. In the dropdown menu that appears, select Settings :

In your Profile settings section:

Change the Name and Email from "Administrator" and "admin@example.com " to something more accurate. The name you choose will be shown to other users, while the email is used for default avatar detection, notifications, Git actions through the interface, and so on.

When you are done, click the Update profile settings button at the bottom:

A confirmation email will be sent to the address you provided. Follow the instructions in the email to confirm your account so you can start using it with GitLab.

Changing Your Account Name

Next, click Account in the left-hand menu bar:

Here, you can find your private API token or configure two-factor authentication. However, the functionality we are interested in right now is the Change username section.

By default, the first administrator account is named root . Since this is a known account name, it is more secure to change it to a different name. You will still have administrative privileges; the only thing that will change is the name. Replace root with your preferred username:

 Click the Update username button to make the change:

The next time you log in to GitLab, remember to use your new username.

Adding an SSH Key to Your Account

In most cases, you will want to use SSH keys with Git to interact with your GitLab projects. To do this, you need to add your SSH public key to your GitLab account.

If you already have an SSH key pair generated on your local computer , you can usually view the public key by typing:

cat ~/.ssh/id_rsa.pub

You should see a large chunk of text like this:

Outputssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMuyMtMl6aWwqBCvQx7YXvZd7bCFVDsyln3yh5/8Pu23LW88VXfJgsBvhZZ9W0rPBGYyzE/TDzwwITvVQcKrwQrvQlYxTVbqZQDlmsC41HnwDfGFXg+QouZemQ2YgMeHfBzy+w26/gg480nC2PPNd0OG79+e7gFVrTL79JA/MyePBugvYqOAbl30h7M1a7EHP3IV5DQUQg4YUq49v4d3AvM0aia4EUowJs0P/j83nsZt8yiE2JEYR03kDgT/qziPK7LnVFqpFDSPC3MR3b8B354E9Af4C/JHgvglv2tsxOyvKupyZonbyr68CqSorO2rAwY/jWFEiArIaVuDiR9YM5 sammy@mydesktop

Copy this text and go back to the Profile Settings page in GitLab's web interface.

If you instead get a message like this, you do not yet have an SSH key pair configured on your machine:

Outputcat: /home/sammy/.ssh/id_rsa.pub: No such file or directory

In this case, you can generate an SSH key pair by typing:

ssh-keygen

Accept the defaults and optionally provide a passphrase to protect the key locally:

OutputGenerating public/private rsa key pair.
Enter file in which to save the key (/home/sammy/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sammy/.ssh/id_rsa.
Your public key has been saved in /home/sammy/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:I8v5/M5xOicZRZq/XRcSBNxTQV2BZszjlWaIHi5chc0 sammy@gitlab.docsthat.work
The key's randomart image is:
+---[RSA 2048]----+
|          ..%o==B|
|           *.E =.|
|        . ++= B  |
|         ooo.o . |
|      . S .o  . .|
|     . + .. .   o|
|      +   .o.o ..|
|       o .++o .  |
|        oo=+     |
+----[SHA256]-----+

Once you have this, you can display your public key as above by typing:

cat ~/.ssh/id_rsa.pub
Outputssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMuyMtMl6aWwqBCvQx7YXvZd7bCFVDsyln3yh5/8Pu23LW88VXfJgsBvhZZ9W0rPBGYyzE/TDzwwITvVQcKrwQrvQlYxTVbqZQDlmsC41HnwDfGFXg+QouZemQ2YgMeHfBzy+w26/gg480nC2PPNd0OG79+e7gFVrTL79JA/MyePBugvYqOAbl30h7M1a7EHP3IV5DQUQg4YUq49v4d3AvM0aia4EUowJs0P/j83nsZt8yiE2JEYR03kDgT/qziPK7LnVFqpFDSPC3MR3b8B354E9Af4C/JHgvglv2tsxOyvKupyZonbyr68CqSorO2rAwY/jWFEiArIaVuDiR9YM5 sammy@mydesktop

Copy the block of text that is displayed and go back to your profile settings in GitLab's web interface .

Click SSH Keys in the left-hand menu:

Paste the public key you copied from your local machine into the space provided. Give it a descriptive title and click the Add key button:

You should now be able to manage your GitLab projects and repositories from your local machine without having to provide your GitLab account credentials.

Step 6 – Restricting or Disabling Public Sign-ups (Optional)

When you visit your GitLab instance's landing page, you may have noticed that it is possible for anyone to sign up for an account. If you want to host a public project, this may be what you want. However, more restrictive settings are often preferable.

To begin, navigate to the administration area by clicking the wrench icon in the main menu bar at the top of the page:

On the page that follows, you can see an overview of your GitLab instance as a whole. To adjust the settings, click the Settings item at the bottom of the left-hand menu:

You will be taken to the global settings for your GitLab instance. Here, you can edit a number of settings that affect whether new users can sign up and their access levels.

Disabling Sign-ups

If you want to disable sign-ups completely (you can still create accounts for new users manually), go to the Sign-up Restrictions section.

Uncheck the Sign-up enabled checkbox:

Scroll down and click the Save changes button:

The sign-up section should now be removed from the GitLab landing page.

Restricting Sign-ups by Domain

If you are using GitLab as part of an organization that provides email addresses associated with a domain, you can restrict sign-ups by domain instead of disabling them completely.

In the Sign-up Restrictions section, select the Send confirmation email on sign-up checkbox, which will only allow users to log in after they have confirmed their email.

Next, add your domain or domains to the Whitelisted domains for sign-ups box, one domain per line. You can use the asterisk "*" to specify wildcard domains:

Scroll down and click the Save changes button:

The sign-up section should now be removed from the GitLab landing page.

Restricting Project Creation

By default, new users can create up to 10 projects. If you want to allow new users from outside for visibility and participation, but restrict their access to creating new projects, you can do so in the Account and Limit Settings section.

Inside, you can change the Default projects limit to 0 to completely disable new users from creating projects:

New users can still be added to projects manually and can access internal or public projects created by other users.

Scroll down and click the Save changes button:

New users will now be able to create accounts, but not create projects.

Renewing Let's Encrypt Certificates

By default, GitLab has a scheduled task set up to renew Let's Encrypt certificates every fourth day after midnight, based on your external_url. You can change these settings in the /etc/gitlab/gitlab.rb file. For example, if you want to renew every 7 days at 12:30, you can configure it as follows:/etc/gitlab/gitlab.rb

letsencrypt['auto_renew_hour'] = "12"
letsencrypt['auto_renew_minute'] = "30"
letsencrypt['auto_renew_day_of_month'] = "*/7"

You can also disable automatic renewal by adding an additional setting to /etc/gitlab/gitlab.rb:/etc/gitlab/gitlab.rb

letsencrypt['auto_renew'] = false

With automatic renewals in place, you will not need to worry about service interruptions.

Conclusion

You should now have a working GitLab instance hosted on your own server. You can begin importing or creating new projects and configuring the appropriate level of access for your team. GitLab regularly adds features and makes updates to their platform, so be sure to check the project's home page to stay informed of any improvements or important announcements.

Kerim Koç

Systems and infrastructure engineer. I write about Linux, open source, high availability and security.