Installing and using Gitlab CE on Ubuntu 20.04

Installing and using Gitlab CE on Ubuntu

In this article, we will examine installing and using Gitlab on Ubuntu server version 20.04. Gitlab community edition or Gitlab CE can be installed by simply using apt install.

Table of Contents

Introduction

GitLab is a web-based Git repository manager that provides features such as issue tracking, continuous integration, and continuous deployment. It is available in two editions, GitLab Community Edition (CE) and GitLab Enterprise Edition (EE). In this guide, we will discuss how to install and use GitLab CE on Ubuntu 20.04.

Installing and using Gitlab CE on Ubuntu

Image by Pixabay from Pexels

Installing and using Gitlab CE on Ubuntu: Pros and Cons

GitLab CE provides several benefits over traditional Git hosting solutions, such as GitHub and Bitbucket. Some of the benefits are:

Pros

  • Self-hosted: GitLab CE can be self-hosted on your own server, which provides more control and customization options.
  • Open source: GitLab CE is open source, which means it is free to use and can be customized to meet your specific needs.
  • Integration: GitLab CE provides built-in integration with various tools, including Jenkins, Docker, and Kubernetes.
  • Scalability: GitLab CE is highly scalable, which means it can handle large codebases and teams with ease.

Cons

  • Complexity: GitLab CE can be complex to set up and configure, especially for users who are new to Git hosting solutions.
  • Resource-intensive: GitLab CE requires a considerable amount of system resources, such as RAM, CPU, and storage space.
  • Maintenance: GitLab CE requires regular maintenance, including security updates and backups.

The Process: Step-By-Step

Now, let’s dive into the installation process of GitLab CE on Ubuntu 20.04.

Step 1: Update Ubuntu

The first step is to update Ubuntu to the latest version. You can do this by running the following commands in the terminal:

				
					$ sudo apt update -y; sudo apt upgrade -y
				
			

Step 2: Install Dependencies

Before installing GitLab CE, you need to install the required dependencies. Run the following command to install the dependencies:

				
					$ sudo apt install curl openssh-server ca-certificates tzdata perl
				
			

Step 3: Install GitLab CE

You can install GitLab CE using the official GitLab repository. To do this, follow these steps:

Add the GitLab Repository

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

Install GitLab CE

This command (below) will install GitLab CE and all its dependencies:

				
					$ sudo apt install gitlab-ce
				
			

Step 4: Configure GitLab CE

Once GitLab CE is installed, you need to configure it as follows. Using your preferred text editor, open the GitLab configuration file:

				
					$ sudo vim /etc/gitlab/gitlab.rb
				
			

In the configuration file, change the external URL to the domain name or IP address of your server (example below). Then, write and quit the file.

				
					external_url 'http://example.com'
				
			

Step 5: Reconfigure GitLab

Run the following command (below) to reconfigure GitLab. It will apply the changes you made in the configuration file.

				
					$ sudo gitlab-ctl reconfigure
				
			

Installing and Using GitLab CE on Ubuntu: Accessing the Web Interface

Once GitLab CE is installed and configured, you can access the web interface by opening a web browser and navigating to the external URL that you set in the configuration file. You will be prompted to set the password for the root user.

Creating a New Project

To create a new project, follow these steps:

  1. Log in to GitLab CE using the root username and password.

  2. Click on the “New Project” button.

  3. Enter the project name, description, and visibility level.

  4. Click on the “Create Project” button.

  5. You can now add files to the project and commit them to the Git repository.

Using GitLab CI/CD

GitLab CE provides built-in continuous integration and continuous deployment (CI and CD) capabilities. To use GitLab CI/CD, follow these steps:

  1. Create a .gitlab-ci.yml file in the root directory of your Git repository.

  2. Define the stages and jobs for your CI/CD pipeline.

  3. Commit the .gitlab-ci.yml file to the Git repository.

  4. GitLab will automatically detect the file and start the CI/CD pipeline.

GITLAB CI/CD in Action

Let’s say you want to build a Docker image and deploy it to a Kubernetes cluster using GitLab CI/CD. You can define the following stages and jobs in the .gitlab-ci.yml file. The example below shows a pipeline that will build a Docker image, tag it, and push it to a Docker registry. Then, it will deploy the image to a Kubernetes cluster using Helm.

				
					stages:
  - build
  - deploy

build:
  stage: build
  image: docker:latest
  script:
    - docker build -t example-image .
    - docker tag example-image registry.example.com/example-image:latest
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.example.com
    - docker push registry.example.com/example-image:latest

deploy:
  stage: deploy
  image: alpine/helm:latest
  script:
    - helm upgrade --install example-chart example-chart --namespace example --set image.repository=registry.example.com/example-image,image.tag=latest
				
			

Conclusion

In this article, we discussed how to install and use GitLab CE on Ubuntu 20.04. GitLab CE provides several benefits over traditional Git hosting solutions, such as self-hosting, open-source, and integration. However, it can be complex to set up and configure, requires a considerable amount of system resources, and requires regular maintenance.

We covered the installation process of GitLab CE, configuring GitLab CE, accessing the GitLab CE web interface, creating a new project, and using GitLab CI/CD. By following these steps, you can get started with GitLab CE and take advantage of its powerful features for your Git hosting needs. Was this article helpful to you? If so, leave us some feedback in the comments section. We’d love to hear from you.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *