How To Install GitLab CE on Ubuntu 22.04|20.04|18.04

Posted on 158 views

Welcome to our guide on how to install GitLab CE on Ubuntu 22.04|20.04|18.04 Linux system. GitLab is a fully-featured platform for accelerated software development. It provides up to scratch features like integrated CI/CD, Kubernetes integration, Auto DevOps, GitLab Container Registry e.t.c.

In our previous guide, we covered how Install Gitlab CE on CentOS / Fedora. Follow below steps to Install Gitlab CE on Ubuntu 22.04|20.04|18.04. The server can be running in Cloud or your own premise virtualized infrastructure.

Step 1: Update system & install dependencies

Kickoff the installation by ensuring your system is updated:

sudo apt update
sudo apt upgrade -y

Install GitLab dependencies below:

sudo apt install -y ca-certificates curl openssh-server tzdata

Step 2: Configure Postfix Send-Only SMTP Server

GitLab should be able to send emails to you on Git activities. Configure Postfix SMTP Server using the guide below:

Step 3: Add the GitLab CE Repository

Once you have all pre-requisites installed, proceed to add GitLab repository to your Ubuntu 22.04|20.04|18.04 by running the command:

Ubuntu 22.04:

At the time of updating this article, the GitLab APT repository for Ubuntu 22.04 is not ready. What we’ll do is configure repository for Ubuntu 20.04 on 22.04. Once the repository for 22.04 is available this article will be updated.

Install dependency packages required:

sudo apt update
sudo apt install curl debian-archive-keyring lsb-release ca-certificates apt-transport-https software-properties-common -y

Import GitLab repo GPG key

gpg_key_url="https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey"
curl -fsSL $gpg_key_url| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/gitlab.gpg

Add repository contents to /etc/apt/sources.list.d/gitlab_gitlab-ce.list file.

sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list<

Confirm configured repository is working by updating APT package index.

$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:3 http://ke.archive.ubuntu.com/ubuntu jammy InRelease
Hit:4 http://ke.archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:2 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal InRelease [23.3 kB]
Hit:5 http://ke.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:6 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal/main amd64 Packages [27.8 kB]
Fetched 51.1 kB in 2s (32.6 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done

Ubuntu 20.04|18.04:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

Command installation output:

Detected operating system as Ubuntu/focal.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.

The repository contents are added to:

cat /etc/apt/sources.list.d/gitlab_gitlab-ce.list

Step 4: Install GitLab CE on Ubuntu 22.04|20.04|18.04

Once the repository has been added, install GitLab CE on Ubuntu 22.04|20.04|18.04 using the apt package manager command:

sudo apt update
sudo apt install gitlab-ce

Installation output:

It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!

Edit the GitLab configuration file to set hostname and other parameters:

$ sudo vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'

Replace gitlab.example.com with valid domain for GitLab server.

When done, start your GitLab instance by running the following command:

sudo gitlab-ctl reconfigure

All GitLab services should be started after configuration.

$ sudo gitlab-ctl status
run: alertmanager: (pid 92581) 18s; run: log: (pid 92343) 80s
run: gitaly: (pid 92590) 18s; run: log: (pid 91561) 189s
run: gitlab-exporter: (pid 92551) 20s; run: log: (pid 92078) 98s
run: gitlab-kas: (pid 92520) 22s; run: log: (pid 91845) 175s
run: gitlab-workhorse: (pid 92531) 21s; run: log: (pid 91985) 117s
run: grafana: (pid 92610) 17s; run: log: (pid 92471) 38s
run: logrotate: (pid 91486) 202s; run: log: (pid 91494) 201s
run: nginx: (pid 91993) 114s; run: log: (pid 92013) 110s
run: node-exporter: (pid 92540) 21s; run: log: (pid 92049) 104s
run: postgres-exporter: (pid 92601) 18s; run: log: (pid 92367) 76s
run: postgresql: (pid 91693) 184s; run: log: (pid 91704) 183s
run: prometheus: (pid 92560) 20s; run: log: (pid 92297) 88s
run: puma: (pid 91904) 132s; run: log: (pid 91917) 129s
run: redis: (pid 91521) 196s; run: log: (pid 91538) 193s
run: redis-exporter: (pid 92553) 20s; run: log: (pid 92217) 94s
run: sidekiq: (pid 91922) 126s; run: log: (pid 91934) 122s

Step 5: Access GitLab CE Web Interface

Once the installation of GitLab CE on Ubuntu 22.04|20.04|18.04 is done, open the URL http://gitlab.example.com on your browser to finish the installation of Gitlab.

A password for root user is randomly generated and stored for 24 hours in /etc/gitlab/initial_root_password. You can check the password with the commands below:

$ cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: kOtOjWp7v70OjkjtadnSJAhcDbCNo9nTNGVC5UoSCyE=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

Use this password with username root to login.

GiltLab-Login-1024x389

GitLab Dashboard should look like below.

install-gitlab-ubuntu-18.04-debian-9-interface-1024x301

Reset root user password

Go to root user profile > Preferences

gitlab-change-root-password-01

Then Password section

gitlab-change-root-password-02-1024x358

Input the current password, and set new one.

gitlab-change-root-password-03-1024x439

Step 6: Secure Gitlab CE with SSL Certificate

Read our next article below on how to configure your GitLab server to be accessible via HTTPS

GitLab Administrations cheats

Whenever you edit GitLab configuration file – /etc/gitlab/gitlab.rb,reconfigure GitLab service by running:

sudo gitlab-ctl reconfigure
sudo gitlab-rake gitlab:check

To check the status of all GitLab service, use:

sudo gitlab-ctl status

To stop all GitLab services, use:

sudo gitlab-ctl stop

To restart all GitLab services, use:

sudo gitlab-ctl restart

You can restart a specific service by proving service name at the end

$ sudo gitlab-ctl restart logrotate
 ok: run: logrotate: (pid 22824) 0s

If you need LDAP Authentication on your GitLab Server, read:

Enjoy running GitLab on Ubuntu 22.04|20.04|18.04 server and stay connected for more informative and hands-on Linux guides.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.