In this short tutorial, we will learn how to install GitLab on Ubuntu 22.04 operating system.
Introduction
When we work in a team on a project, we will be helped by tools that allow us to share information with other team members. From developers to sysadmins, they will collaborate at every stage of the project. GitLab is one of the tools that can be used for this need.
GitLab is a DevOps software package that combines the ability to develop, secure, and operate software in a single application. GitLab also permits usto perform source code management, monitoring, security, and project planning tasks. On this short tutorial, we will learn how to install GitLab on Ubuntu 22.04 LTS operating system.
GitLab Installation on Ubuntu 22.04
The GitLab installation will be consist of several steps as described below :
- Update system packages
- Install necessary dependencies
- Import GPG key
- Add GitLab repository
- Update system packages
- Install GitLab on Ubuntu 22.04
- Configuring GitLab
- Verify GitLab installation
- Enable required ports
- Start GitLab service
- Check services status
1. Update System Package
The first step is to update our system package, for this purpose we will submit the command line :
$ sudo apt update
Output :
ramans@bckinfo:~$ sudo apt update [sudo] password for ramans: Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48,9 kB] Hit:2 http://id.archive.ubuntu.com/ubuntu jammy InRelease Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB] Get:4 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB] . . . Get:22 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [82,3 kB] Get:23 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [13,0 kB] Get:24 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [288 kB] Get:25 http://security.ubuntu.com/ubuntu jammy-security/universe i386 Packages [211 kB] Get:26 http://security.ubuntu.com/ubuntu jammy-security/universe Translation-en [63,8 kB] Get:27 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [12,4 kB] Get:28 http://security.ubuntu.com/ubuntu jammy-security/universe DEP-11 64x64 Icons [9.532 B] Fetched 4.194 kB in 14s (309 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 265 packages can be upgraded. Run 'apt list --upgradable' to see them.
2. Install Dependencies Packages
To install necessary dependencies with Gitlag, we will do following command line :
$ sudo apt install tzdata curl ca-certificates openssh-server
.Output :
ramans@bckinfo:~$ sudo apt install tzdata curl ca-certificates openssh-server Reading package lists... Done Building dependency tree... Done Reading state information... Done ca-certificates is already the newest version (20211016). curl is already the newest version (7.81.0-1ubuntu1.4). The following additional packages will be installed: ncurses-term openssh-sftp-server ssh-import-id Suggested packages: molly-guard monkeysphere ssh-askpass The following NEW packages will be installed: ncurses-term openssh-server openssh-sftp-server ssh-import-id The following packages will be upgraded: tzdata 1 upgraded, 4 newly installed, 0 to remove and 264 not upgraded. Need to get 751 kB/1.086 kB of archives. After this operation, 5.998 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 openssh-sftp-server amd64 1:8.9p1-3 [38,8 kB] Get:2 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 openssh-server amd64 1:8.9p1-3 [434 kB] Get:3 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 ncurses-term all 6.3-2 [267 kB] Get:4 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 ssh-import-id all 5.11-0ubuntu1 [10,1 kB] Fetched 751 kB in 3s (221 kB/s) Preconfiguring packages ... Selecting previously unselected package openssh-sftp-server. (Reading database ... 199230 files and directories currently installed.) Preparing to unpack .../openssh-sftp-server_1%3a8.9p1-3_amd64.deb ... Unpacking openssh-sftp-server (1:8.9p1-3) ... Selecting previously unselected package openssh-server. Preparing to unpack .../openssh-server_1%3a8.9p1-3_amd64.deb ... Unpacking openssh-server (1:8.9p1-3) ... Preparing to unpack .../tzdata_2022c-0ubuntu0.22.04.0_all.deb ... Unpacking tzdata (2022c-0ubuntu0.22.04.0) over (2022a-0ubuntu1) ... Selecting previously unselected package ncurses-term. Preparing to unpack .../ncurses-term_6.3-2_all.deb ... Unpacking ncurses-term (6.3-2) ... Selecting previously unselected package ssh-import-id. Preparing to unpack .../ssh-import-id_5.11-0ubuntu1_all.deb ... Unpacking ssh-import-id (5.11-0ubuntu1) ... Setting up openssh-sftp-server (1:8.9p1-3) ... Setting up openssh-server (1:8.9p1-3) ... Creating config file /etc/ssh/sshd_config with new version Creating SSH2 RSA key; this may take some time ... 3072 SHA256:AqjbZ0q0Lt9DkO8nweghznQTizxtJiTEUmI/C5OLkME root@bckinfo (RSA) Creating SSH2 ECDSA key; this may take some time ... 256 SHA256:2ZwZ/YPwJ7yyX6Zzm1mZbRazwiyfN8Xr3I+di59L1qo root@bckinfo (ECDSA) Creating SSH2 ED25519 key; this may take some time ... 256 SHA256:w4Y8A1Mi1YEGClr1Zb46byF9KlWhJb4DWmlB69Z5U/4 root@bckinfo (ED25519) Created symlink /etc/systemd/system/sshd.service โ /lib/systemd/system/ssh.service. Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service โ /lib/systemd/system/ssh.servic e. rescue-ssh.target is a disabled or a static unit, not starting it. ssh.socket is a disabled or a static unit, not starting it. Setting up ssh-import-id (5.11-0ubuntu1) ... Setting up tzdata (2022c-0ubuntu0.22.04.0) ... Current default time zone: 'Asia/Jakarta' Local time is now: Kam 06 Okt 2022 11:29:41 WIB. Universal Time is now: Thu Oct 6 16:29:41 UTC 2022. Run 'dpkg-reconfigure tzdata' if you wish to change it. Setting up ncurses-term (6.3-2) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for ufw (0.36.1-4build1) ...
3. Import GPG key
In this step we will import GitLab GPG key to be available on the system. To perform this task, we will submit the following command line :
$ gpg_key_url="https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey"
Output :
ramans@bckinfo:~$ 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.gpgFile '/etc/apt/trusted.gpg.d/gitlab.gpg' exists. Overwrite? (y/N) y
4. Add GitLab Repository
On this stage, we will import and add the repository of GitLab into the system, to perform this task we will submit command line below :
$ sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list<<EOF deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main EOF
Output :
ramans@bckinfo:~$ sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list<<EOF deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main EOF deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main
5. Update System
After GitLab repository has been imported, then we will update the system, by submitting following command line :
$ sudo apt update
Output :
ramans@bckinfo:~$ sudo apt update Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease Hit:4 http://id.archive.ubuntu.com/ubuntu jammy InRelease Get:5 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB] Get:2 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal InRelease [23,3 kB] Hit:6 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy InRelease . . . Get:15 http://id.archive.ubuntu.com/ubuntu jammy-backports/universe amd64 DEP-11 Metadata [12,6 kB] Fetched 1.943 kB in 4s (457 kB/s) Reading package lists... Done Building dependency tree... Done. Reading state information... Done 264 packages can be upgraded. Run 'apt list --upgradable' to see them.\
6. Install GitLab On Ubuntu 22.04
In this section, we will install GitLab on Ubuntu 22.04 by submitting the following command line :
$ sudo apt install gitlab-ce
Output :
ramans@bckinfo:~$ sudo apt install gitlab-ce Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: gitlab-ce 0 upgraded, 1 newly installed, 0 to remove and 264 not upgraded. Need to get 1.143 MB of archives. After this operation, 3.222 MB of additional disk space will be used. Get:1 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal/main amd64 gitlab-ce amd64 15.4.2-ce.0 [1.143 MB] Fetched 1.143 MB in 12min 51s (1.483 kB/s) Selecting previously unselected package gitlab-ce. (Reading database ... 202109 files and directories currently installed.) Preparing to unpack .../gitlab-ce_15.4.2-ce.0_amd64.deb ... Unpacking gitlab-ce (15.4.2-ce.0) ... Setting up gitlab-ce (15.4.2-ce.0) ... It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** *******#####.........................................................................] ******** ********####.........................................................................] ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,,###.........................................................................] ,,,,,,,,,*****,,,,,,,,,.######.........................................................................] ,,,,,,,****,,,,,,##########.........................................................................] .,,,***,,,,#############.........................................................................] ,*,.################.........................................................................] _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md Help us improve the installation experience, let us know how we did with a 1 minute survey: https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=15-4
We have installed GitLab on Ubuntu 22.04 successfully, then we will configure it to run properly on our environment.
7. Configuring GitLab
The next step is to configure GitLab to work properly. To configure the GitLab installation, we will be using command line :
$ sudo gitlab-ctl reconfigure
Output :
ramans@bckinfo:~$ sudo gitlab-ctl reconfigure [sudo] password for ramans: [2022-10-06T23:57:57+07:00] INFO: Started Chef Infra Zero at chefzero://localhost:1 with repository at /opt/gitlab/embedded (One version per cookbook) Chef Infra Client, version 17.10.0 Patents: https://www.chef.io/patents Infra Phase starting [2022-10-06T23:57:57+07:00] INFO: *** Chef Infra Client 17.10.0 *** [2022-10-06T23:57:57+07:00] INFO: Platform: x86_64-linux [2022-10-06T23:57:57+07:00] INFO: Chef-client pid: 21542 [2022-10-06T23:58:00+07:00] INFO: Setting the run_list to ["recipe[gitlab]"] from CLI options [2022-10-06T23:58:00+07:00] INFO: Run List is [recipe[gitlab]] [2022-10-06T23:58:00+07:00] INFO: Run List expands to [gitlab] [2022-10-06T23:58:00+07:00] INFO: Starting Chef Infra Client Run for bckinfo [2022-10-06T23:58:00+07:00] INFO: Running start handlers [2022-10-06T23:58:00+07:00] INFO: Start handlers complete. Resolving cookbooks for run list: ["gitlab"] [2022-10-06T23:58:00+07:00] INFO: Loading cookbooks [gitlab@0.0.1, package@0.1.0, logrotate@0.1.0, postgresql@0.1.0, redis@0.1.0, monitoring@0.1.0, registry@0.1.0, mattermost@0.1.0, consul@0.1.0, gitaly@0.1.0, praefect@0.1.0, gitlab-kas@0.1.0, gitlab-pages@0.1.0, letsencrypt@0.1.0, nginx@0.1.0, runit@5.1.3, acme@4.1.5, crond@0.1.0] Synchronizing cookbooks: [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/resources/sidekiq_service.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/bootstrap.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/resources/database_objects.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/resources/rails_migration.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/resources/puma_config.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/add_trusted_certs.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/bootstrap_disable.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/config.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/database_migrations.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/gitlab-rails.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/gitlab-healthcheck.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/attributes/default.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/default.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/gitlab-workhorse.rb in the cache. [2022-10-06T23:58:01+07:00] INFO: Storing updated cookbooks/gitlab/recipes/database_reindexing_enable.rb in the cache. . . . running handlers: [2022-10-07T00:01:51+07:00] INFO: Running report handlers Running handlers complete [2022-10-07T00:01:52+07:00] INFO: Report handlers complete Infra Phase complete, 571/1529 resources updated in 03 minutes 54 seconds Notes: Default admin account has been configured with following details: Username: root Password: You didn't opt-in to print initial root password to STDOUT. Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours. NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password. gitlab Reconfigured!
8. Verifying GitLab installation
To make sure if our GitLab installation was successfully done, we will verify it by viewing the related information. On this stage, we will retrieve GitLab environment info, by submitting command line :
$ sudo gitlab-rake gitlab:env:info
Output :
ramans@bckinfo:~$ sudo gitlab-rake gitlab:env:info System information System: Ubuntu 22.04 Current User: git Using RVM: no Ruby Version: 2.7.5p203 Gem Version: 3.1.6 Bundler Version:2.3.15 Rake Version: 13.0.6 Redis Version: 6.2.7 Sidekiq Version:6.4.2 Go Version: unknown GitLab information Version: 15.4.2 Revision: ef309cf1466 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 13.6 URL: http://gitlab.example.com HTTP Clone URL: http://gitlab.example.com/some-group/some-project.git SSH Clone URL: git@gitlab.example.com:some-group/some-project.git Using LDAP: no Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 14.10.0 Repository storage paths: - default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
It shown above, if our GitLab installation showing the right information.
9. Enable required Ports
The GitLab service that was provided on our server must be accessible from any other party via http or https. To ensure these services run normally by using the following command line.
$ sudo ufw allow https $ sudo ufw allow http $ sudo ufw enable
Output :
ramans@bckinfo:~$ sudo ufw allow https Rules updated Rules updated (v6) ramans@bckinfo:~$ sudo ufw allow http Rules updated Rules updated (v6) ramans@bckinfo:~$ sudo ufw enable Firewall is active and enabled on system startup ramans@bckinfo:~$ sudo ufw reload Firewall reloaded
10. Start GitLab Service
On this start, we will start GitLab service by submitting command line :
$ sudo gitlab-ctl start
Output :
ramans@bckinfo:~$ sudo gitlab-ctl start ok: run: alertmanager: (pid 24699) 303s ok: run: gitaly: (pid 24695) 303s ok: run: gitlab-exporter: (pid 24700) 303s ok: run: gitlab-kas: (pid 24687) 303s ok: run: gitlab-workhorse: (pid 24673) 303s ok: run: logrotate: (pid 24682) 303s ok: run: nginx: (pid 24696) 303s ok: run: node-exporter: (pid 24692) 303s ok: run: postgres-exporter: (pid 24701) 303s ok: run: postgresql: (pid 24703) 303s ok: run: prometheus: (pid 24681) 303s ok: run: puma: (pid 24689) 303s ok: run: redis: (pid 24671) 303s ok: run: redis-exporter: (pid 24694) 303s ok: run: sidekiq: (pid 24669) 303s
11. Check Services Status
When we have started GitLab service, then we will check its service by submitting command line :
$ sudo gitlab-ctl status
Output :
ramans@bckinfo:~$ sudo gitlab-ctl status [sudo] password for ramans: run: alertmanager: (pid 1893) 13503s; run: log: (pid 1885) 13503s run: gitaly: (pid 1895) 13503s; run: log: (pid 1887) 13503s run: gitlab-exporter: (pid 1872) 13503s; run: log: (pid 1870) 13503s run: gitlab-kas: (pid 1896) 13503s; run: log: (pid 1883) 13503s run: gitlab-workhorse: (pid 1864) 13503s; run: log: (pid 1862) 13503s run: logrotate: (pid 1875) 13503s; run: log: (pid 1868) 13503s run: nginx: (pid 1876) 13503s; run: log: (pid 1873) 13503s run: node-exporter: (pid 1865) 13503s; run: log: (pid 1863) 13503s run: postgres-exporter: (pid 1881) 13503s; run: log: (pid 1877) 13503s run: postgresql: (pid 1906) 13503s; run: log: (pid 1890) 13503s run: prometheus: (pid 1892) 13503s; run: log: (pid 1884) 13503s run: puma: (pid 1894) 13503s; run: log: (pid 1889) 13503s run: redis: (pid 1871) 13503s; run: log: (pid 1869) 13503s run: redis-exporter: (pid 1879) 13503s; run: log: (pid 1878) 13503s run: sidekiq: (pid 1867) 13503s; run: log: (pid 1866) 13503s
Until this stage, we have installed GitLab on Ubuntu 22.04 LTS successfully. The next step is we will use GitLab for our purpose.
Using GitLab
On this stage, we will try to use and explore GitLab. We will use web browser to access GitLab. On this tutorial we are using localhost or hostname (bckinfo), so we will hit the http://localhost or http//:bckinfo, as shwon below =.
We will use root user to login to GitLab where the password is located at /etc/gitlab/initial_root_password file, as shown below.
ramans@bckinfo:~$ sudo more /etc/gitlab/initial_root_password [sudo] password for ramans: # WARNING: This value is valid only in the following conditions # 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `git lab_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: LeRxtHqSqnAu97XcNiU1ikW+KCCRuEbLzo4nkG21Vw0= # NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
We are recommended to chage the given password.
After successfully logging in, we will find the GitLab main page as below
Conclusion
In this tutorial, we have learnt how to install GitLab on Ubuntu 22.04 LTS operating system successfully. I hope this tutorial will be helpful.