How to Install GitLab on Ubuntu 22.04 (Step by Step)

How to Install GitLab on Ubuntu 22.04 (Step by Step). In this post, we introduce GitLab, its features, and advantages and after explain how to install GitLab on Ubuntu 22.04.

What is GitLab?

GitLab is a web based Git repository manager, written in Ruby and Go language. Also, an open source project, originally created by Dmitriy Zaporozhets and Valery Sizov in 2011.

Moreover, GitLab is a collaborative tool that aids in managing server hosted repositories, as well as bug tracking for CI/CD pipeline functions. Not to mention, it is free tool that makes it easy to manage and sets up in minutes.

A few high profile tech companies like Cisco, Juniper, and IBM prefer Gitlab for deployment and collaborating on web based projects. It helps developers in bug tracking, analysis, and project management. DevOps even create private and public projects via Gitlab.

One can also comment on the code of other developers and pull requests in GitLab. Further, you may import repositories from Google Code, Bitbucket, and other services using GitLab as well.

Features of GitLab

Primarily, Gitlab provides all the features of the Git version control system and includes additional features such as bug and project management, CI integration, code reviews, etc. The following are some of the features of GitLab:

  • Unprompted user interface.
  • Time Tracking, Automatic code evaluation and Application Load Balancing.
  • Fix chat management problems.
  • Container registry and Docker images management via third party servers.
  • Group Milestones for the development process.
  • Unlimited private and public repos.
  • Issue tracking with comment threads and milestones.
  • Merge and Closure of Critical Issues.
  • Kubernetes integration and support clusters.

Advantages of GitLab

Particularly, with GitLab it is a web based Git repository manager that provides a single, unified platform to manage projects including code reviews, issue tracking, etc. What is more, it also offers built in CI for faster deployments and a built in container registry for easy image sharing.

With the cloud native application, many organizations may operate better and produce greater outcomes in a shorter amount of time. Here are some additional advantages of utilizing GitLab:

1. Configuration Process is simple

GitLab CI/CD tool provides a secure, password protected repository that is easy to install. Developers configure it in the cloud, on premises, or inside a container. Remember to create a virtual machine in order to configure. Additionally, a stick is needed for preset setup. Configuring GitLab projects also benefits a user’s command line experience with Git.

2. Schedule for Deployments

In order to reduce conflicts, it became necessary to check ongoing performance and schedule monitoring. But, it was a time consuming task and the staff could not pay attention to the more concerned areas. With the launch of GitLab, users could simply run CI/CD pipeline schedules. They could simply choose a time for deployment management. Additionally, this functionality notifies you right away whenever there are changes to the code.

3. Active and Large Community

Nonetheless, GitLab has an open source model with an enterprise version that is customized to suit the needs of the user. The GitLab community is large and active which means there are always people to help if you have any questions or need help with anything.

4. Maturity Feedback

Particularly, Gitlab has a score board features that show whether developers are properly utilizing GitLab capabilities. Additionally, it aids in releasing the appropriate software and addressing defects before the process begins. Also, the teams compare the activities and measure which areas need an extension.

5. Security for Source Code

In addition, GitLab also provides a variety of security protections for CI/CD pipelines, including Kerberos user permissions, granular limits, and management over live codes. Developers can even control, manage, and maintain the place where code is stored. The administration, for instance, has complete access to the server and the location of the codes. Additionally, they have the power to store outside codes.

6. Automates Building, Deployment, and Testing of Pipeline codes

The Auto DevOps feature helps automatically create, test, deploy, and track apps and their code. But remember, a Kubernetes cluster must be integrated in order to fully utilize the Auto DevOps capability. It helps enforce best practices while also saving time.

We have arrived to the main part of the article How to Install GitLab on Ubuntu 22.04 (Step by Step).

How to Install GitLab on Ubuntu 22.04 (Step by Step)

In this section, we will explain how to install GitLab on Ubuntu 22.04.

Prerequisites

  • An Ubuntu 22.04 server is installed on your server.
  • A root user or a user with sudo privileges.

Step 1 - Getting Started

Before installing GitLab, it is recommended to update and upgrade all system packages to the updated version. You update all the packages using the following command.

				
					apt update -y
apt upgrade -y
				
			

Once all the packages are updated, you proceed to add the GitLab repository.

Step 2 - Add GitLab Repository

By default, the GitLab package is not included in the Ubuntu default repository. So you need to add the GitLab official repository to APT.

First, install all the required dependencies using the following command.

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

Once all the dependencies are installed, add the GitLab GPG key with the following command.

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

Next, add the GitLab repo to APT with the following command.

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

Add the following line.

				
					deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main
				
			

Save and close the file then update the repository with the following command.

				
					apt update -y
				
			

Step 3 - Install GitLab

Now, you install GitLab by running the following command.

				
					apt install gitlab-ce -y
				
			

Once the GitLab is installed, you should see the following output.

				
					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

				
			

Step 4 - Configure GitLab

Next, you need to edit the GitLab configuration file and define your domain URL to access it over the internet.

				
					nano /etc/gitlab/gitlab.rb
				
			

Change the following line:

				
					external_url 'http://gitlab.yourdomain.com'
				
			

Save and close the file then reconfigure the GitLab with the following command.

				
					gitlab-ctl reconfigure
				
			

You should see the following output.

				
					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!
				
			

Now, you also verify the GitLab configuration using the following command.

				
					gitlab-rake gitlab:check
				
			

You will get the following output.

				
					Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Cable config exists? ... yes
Resque config exists? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet)
Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units)
Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units)
Projects have namespace: ...
GitLab Instance / Monitoring ... yes
Redis version >= 6.0.0? ... yes
Ruby version >= 2.7.2 ? ... yes (2.7.7)
Git user has default SSH configuration? ... yes
Active users: ... 1
Is authorized keys file accessible? ... yes
GitLab configured to store new projects in hashed storage? ... yes
All projects are in hashed storage? ... yes

Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished

				
			

Step 5 - Access GitLab

At this point, GitLab is installed and configured. To access the GitLab web interface, you will need to retrieve the GitLab root password to log in to GitLab.

				
					cat /etc/gitlab/initial_root_password
				
			

You should see the GitLab root password in the following output.

				
					# 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: FRYbS6wrP+YqRSrRXx9pdskGsGfzZDVMFE8auADjSd8=

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

Now, open your web browser and access the GitLab web UI using the URL http://gitlab.yourdomain.com. You should see the GitLab login page.

Provide your GitLab username, password and click on the Sign in button. You should see the GitLab dashboard on the following page.

Click on the Monitoring. You should see the following screen.

Step 6 - Install Let's Encrypt SSL on GitLab

It is also recommended to secure your GitLab installation with Let’s Encrypt SSL. First, edit the GitLab configuration file using the following command.

				
					nano /etc/gitlab/gitlab.rb
				
			

Change the following lines:

				
					external_url 'https://gitlab.yourdomain.com'

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['user@yourdomain.com']
letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = 3
letsencrypt['auto_renew_day_of_month'] = "*/7"

				
			

Save and close the file then reconfigure the GitLab to apply the configuration.

				
					gitlab-ctl reconfigure
				
			

You can now access the GitLab dashboard securely using the URL https://gitlab.yourdomain.com.

Step 7 - Manage GitLab Instance

If you want to reset your GitLab root password, run the following command.

				
					gitlab-rake 'gitlab:password:reset[root]'
				
			

Set your GitLab new password as shown below.

				
					Enter password:
Confirm password:
Password successfully updated for user with username root.
				
			

To verify the status of GitLab, run the following command.

				
					gitlab-ctl status
				
			

You will get the following output.

				
					run: alertmanager: (pid 80145) 311s; run: log: (pid 79865) 357s
run: gitaly: (pid 80010) 319s; run: log: (pid 79317) 485s
run: gitlab-exporter: (pid 80120) 313s; run: log: (pid 79808) 375s
run: gitlab-kas: (pid 80098) 314s; run: log: (pid 79591) 472s
run: gitlab-workhorse: (pid 80106) 314s; run: log: (pid 79725) 392s
run: logrotate: (pid 79245) 498s; run: log: (pid 79253) 497s
run: nginx: (pid 79737) 388s; run: log: (pid 79746) 387s
run: node-exporter: (pid 80114) 314s; run: log: (pid 79786) 381s
run: postgres-exporter: (pid 80154) 310s; run: log: (pid 79958) 351s
run: postgresql: (pid 79449) 479s; run: log: (pid 79500) 476s
run: prometheus: (pid 80130) 312s; run: log: (pid 79845) 363s
run: puma: (pid 79657) 407s; run: log: (pid 79665) 404s
run: redis: (pid 79280) 492s; run: log: (pid 79297) 489s
run: redis-exporter: (pid 80122) 312s; run: log: (pid 79826) 369s
run: sidekiq: (pid 79675) 401s; run: log: (pid 79696) 398s

				
			

If you want to stop the GitLab, run the following command.

				
					gitlab-ctl stop
				
			

This will stop your GitLab instance as shown below.

				
					ok: down: alertmanager: 0s, normally up
ok: down: gitaly: 0s, normally up
ok: down: gitlab-exporter: 0s, normally up
ok: down: gitlab-kas: 0s, normally up
ok: down: gitlab-workhorse: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 1s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: puma: 0s, normally up
ok: down: redis: 1s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up

				
			

To restart the GitLab, run the following command.

				
					gitlab-ctl restart

				
			

Thank you for reading How to Install GitLab on Ubuntu 22.04 (Step by Step). We shall conclude. 

How to Install GitLab on Ubuntu 22.04 (Step by Step) Conclusion

In this post, you have learned how to install GitLab on Ubuntu 22.04 server. You also learned to manage GitLab and secure it with Let’s Encrypt SSL. You can now use GitLab in your development environment to manage all codes from the central location.

Lastly, GitLab is open source software that provides a free alternative to proprietary products such as GitHub and BitBucket. It offers an online code repository, issue tracking, project management, and more.

Read more about GitLab by exploring our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x