GitLab Setup Guide | Install and Configure for Linux

Digital Image of engineers setting up GitLab on Linux to enhance development collaboration

When collaboratively developing scripts on Linux servers at IOFLOOD, our workflow is simplified by using GitLab. Installing and configuring GitLab enables a comprehensive set of features including CI/CD pipelines, issue tracking, and version control, for a complete DevOps platform. To assist our customers in optimizing their development and deployment processes on their bare metal cloud platforms, we have formulate today’s article.

In this guide, we will navigate you through the process of installing GitLab on Linux. We will provide you with installation instructions for APT-based distributions like Debian and Ubuntu, as well as YUM-based distributions like CentOS and AlmaLinux. We’ll delve into more advanced topics like compiling GitLab from source, installing a specific version, and finally, how to use GitLab and ensure it’s installed correctly.

So, let’s dive in and start installing GitLab on your Linux system!

TL;DR: How Do I Install GitLab on Linux?

You can install GitLab on Linux by running a series of commands. First, you need to update your system’s package list with sudo apt-get update. Then, install the necessary dependencies using sudo apt-get install -y curl openssh-server ca-certificates. After that, add the GitLab package repository to your system with curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash. Finally, install GitLab by setting your server’s fully qualified domain name (FQDN) and running sudo EXTERNAL_URL="http://your-server-FQDN" apt-get install gitlab-ee.

# Update your system's package list
sudo apt-get update

# Install the necessary dependencies
sudo apt-get install -y curl openssh-server ca-certificates

# Add the GitLab package repository to your system
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

# Install GitLab
sudo EXTERNAL_URL="http://your-server-FQDN" apt-get install gitlab-ee

# Output:
# GitLab will be installed and configured

This is a basic way to install GitLab on Linux, but there’s much more to learn about the installation process, including more advanced methods and troubleshooting common issues. Continue reading for a more detailed guide.

Getting Started with GitLab on Linux

GitLab is a web-based DevOps lifecycle tool that provides a Git-repository manager. It offers features like issue tracking, continuous integration/deployment pipelines, and a multi-cloud Kubernetes integration. GitLab is an excellent choice for teams looking for a single comprehensive application that covers the entire DevOps lifecycle.

Now, let’s get started on how to install GitLab on your Linux system. We’ll cover installation using two of the most popular package managers: APT (for Debian-based distributions) and YUM (for Red Hat-based distributions).

Installing GitLab Using APT

For Debian-based systems like Ubuntu, we use the APT package manager. Here’s how you can install GitLab:

# Update your system's package list
sudo apt-get update

# Install necessary dependencies
sudo apt-get install -y curl openssh-server ca-certificates

# Add the GitLab package repository to your system
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

# Replace 'your-server-FQDN' with your server's fully qualified domain name
# Install GitLab
sudo EXTERNAL_URL="http://your-server-FQDN" apt-get install gitlab-ee

# Output:
# GitLab will be installed and configured

In the code block above, we first update the system’s package list. Then, we install necessary dependencies such as curl, openssh-server, and ca-certificates. The next step is to add the GitLab package repository to your system. Finally, we install GitLab by setting your server’s fully qualified domain name (FQDN) and running the installation command.

Installing GitLab Using YUM

For Red Hat-based systems like CentOS, we use the YUM package manager. Here’s how you can install GitLab:

# Update your system's package list
sudo yum update

# Install necessary dependencies
sudo yum install -y curl policycoreutils openssh-server openssh-clients postfix

# Add the GitLab package repository to your system
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

# Replace 'your-server-FQDN' with your server's fully qualified domain name
# Install GitLab
sudo EXTERNAL_URL="http://your-server-FQDN" yum install gitlab-ee

# Output:
# GitLab will be installed and configured

In the code block above, we first update the system’s package list. Then, we install necessary dependencies such as curl, policycoreutils, openssh-server, openssh-clients, and postfix. The next step is to add the GitLab package repository to your system. Finally, we install GitLab by setting your server’s fully qualified domain name (FQDN) and running the installation command.

Remember, after running these commands, GitLab will start automatically. You can then navigate to the FQDN you set during installation in your web browser to access your GitLab instance.

Installing GitLab from Source

For users who want more control over the installation process, GitLab can be installed from source. This method allows you to access the latest features and bug fixes, but it requires more technical knowledge and is more time-consuming than installing from a package manager.

To install GitLab from source, you first need to clone the GitLab repository and then compile the code. Here’s how you can do it:

# Clone the GitLab repository
git clone https://gitlab.com/gitlab-org/gitlab-foss.git

# Navigate to the cloned directory
cd gitlab-foss

# Compile the code
make

# Output:
# GitLab will be compiled and ready to be installed

Installing Specific Versions of GitLab

There may be times when you need to install a specific version of GitLab, either for compatibility reasons or to use a feature that was removed or changed in a later version.

Installing Specific Versions from Source

To install a specific version of GitLab from source, you need to check out the appropriate tag before compiling the code. Here’s an example of how to install GitLab version 13.12.4:

# Clone the GitLab repository
git clone https://gitlab.com/gitlab-org/gitlab-foss.git

# Navigate to the cloned directory
cd gitlab-foss

# Check out the appropriate tag
git checkout v13.12.4

# Compile the code
make

# Output:
# GitLab version 13.12.4 will be compiled and ready to be installed

Installing Specific Versions with APT

To install a specific version of GitLab with APT, you can specify the version number in the installation command. Here’s an example of how to install GitLab version 13.12.4:

# Update your system's package list
sudo apt-get update

# Install GitLab version 13.12.4
sudo apt-get install gitlab-ee=13.12.4-ee.0

# Output:
# GitLab version 13.12.4 will be installed

Installing Specific Versions with YUM

To install a specific version of GitLab with YUM, you can also specify the version number in the installation command. Here’s an example of how to install GitLab version 13.12.4:

# Update your system's package list
sudo yum update

# Install GitLab version 13.12.4
sudo yum install gitlab-ee-13.12.4-ee.0.el7

# Output:
# GitLab version 13.12.4 will be installed

Version Comparison

Different versions of GitLab come with different features, improvements, and bug fixes. Here’s a brief comparison of some recent versions:

VersionKey Changes
13.12.4Introduced security dashboard, improved merge request performance
13.11.3Added support for group wikis, enhanced Kubernetes integration
13.10.2Introduced pipeline editor, improved issue tracking

Verifying Your GitLab Installation

After installing GitLab, it’s important to verify that the installation was successful. This can be done by navigating to your server’s FQDN in your web browser and checking that the GitLab interface loads correctly. You can also run the following command to check the status of the GitLab service:

# Check the status of the GitLab service
sudo gitlab-ctl status

# Output:
# The status of the GitLab service will be displayed

If GitLab is running correctly, you should see an output indicating that the GitLab service is active.

Alternative Methods to Install GitLab

While using a package manager or installing from source are typical methods to install GitLab, there are alternative approaches that can be more suitable depending on your specific needs. Two such methods involve using a different package manager or leveraging Docker.

Installing GitLab with DNF

DNF is the next-generation version of the YUM package manager. It’s the default package manager for Fedora and is also available on RHEL-based systems. Here’s how to install GitLab with DNF:

# Update your system's package list
sudo dnf update

# Install necessary dependencies
sudo dnf install -y curl policycoreutils openssh-server openssh-clients postfix

# Add the GitLab package repository to your system
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

# Replace 'your-server-FQDN' with your server's fully qualified domain name
# Install GitLab
sudo EXTERNAL_URL="http://your-server-FQDN" dnf install gitlab-ee

# Output:
# GitLab will be installed and configured

In the code block above, we first update the system’s package list. Then, we install necessary dependencies such as curl, policycoreutils, openssh-server, openssh-clients, and postfix. The next step is to add the GitLab package repository to your system. Finally, we install GitLab by setting your server’s fully qualified domain name (FQDN) and running the installation command.

Installing GitLab with Docker

Docker offers a way to run applications securely isolated in a container, packaged with all its dependencies and libraries. Here’s how to install GitLab with Docker:

# Pull the GitLab Docker image
docker pull gitlab/gitlab-ee:latest

# Run the GitLab container
# Replace 'your-server-FQDN' with your server's fully qualified domain name
docker run --detach --hostname your-server-FQDN --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ee:latest

# Output:
# GitLab will be installed and running in a Docker container

In the code block above, we first pull the GitLab Docker image. Then we run the GitLab container with specific settings, including detached mode, hostname, port mapping, container name, restart policy, and volume mapping.

Advantages and Disadvantages of Each Method

MethodAdvantagesDisadvantages
APT/YUMEasy to use, widely supportedLimited control over installation process
SourceFull control over installation process, access to latest featuresMore complex, time-consuming
DNFImproved dependency resolution, better performance than YUMNot available on all distributions
DockerEasy to update and rollback, isolated environmentRequires understanding of Docker, extra overhead

Recommendations

The best method to install GitLab depends on your specific needs. If you’re looking for a straightforward installation process and don’t need the latest features, using APT or YUM is a good choice. If you need more control over the installation process or want to access the latest features, installing from source could be the best option. If you’re using Fedora or a RHEL-based distribution and want better performance and improved dependency resolution, consider using DNF. And if you want an easy way to update and rollback GitLab or want to run it in an isolated environment, Docker could be the best choice.

GitLab Installation Troubleshooting

The installation process can sometimes be interrupted due to various issues. Here are some common problems you might encounter and their solutions.

Permission Denied Error

You might encounter a ‘Permission denied’ error when running the installation commands. This is usually due to insufficient user permissions.

To solve this, you can use the sudo command to run the commands with root privileges:

# An example command that might cause a 'Permission denied' error
apt-get update

# Output:
# E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
# E: Unable to lock directory /var/lib/apt/lists/

# The correct command with 'sudo'
sudo apt-get update

# Output:
# Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
# Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease
# Hit:3 http://dl.google.com/linux/chrome/deb stable Release
# Hit:4 http://us.archive.ubuntu.com/ubuntu bionic InRelease
# Reading package lists... Done

In the code block above, the first command fails due to a ‘Permission denied’ error. The correct command uses sudo to run the command with root privileges.

Incorrect Server FQDN

Setting the wrong server fully qualified domain name (FQDN) during the installation can lead to problems accessing GitLab. To fix this, you need to reconfigure GitLab with the correct FQDN:

# Reconfigure GitLab with the correct FQDN
sudo gitlab-ctl reconfigure

# Output:
# Starting Chef Infra Client, version 16.6.14
# resolving cookbooks for run list: ["gitlab"]
# ... truncated for brevity ...
# Chef Infra Client finished, 398/1411 resources updated in 02 minutes 28 seconds

In the code block above, the gitlab-ctl reconfigure command reconfigures GitLab with the correct FQDN.

GitLab Service Not Starting

Sometimes, the GitLab service might not start after installation. This can be due to various reasons, such as insufficient memory or disk space. You can check the status of the GitLab service with the following command:

# Check the status of the GitLab service
sudo gitlab-ctl status

# Output:
# run: alertmanager: (pid 1171) 1667s; run: log: (pid 1160) 1667s
# run: gitaly: (pid 1186) 1667s; run: log: (pid 1175) 1667s
# ... truncated for brevity ...

In the code block above, the gitlab-ctl status command checks the status of the GitLab service. If the service is not running, you might need to check the system logs for more information.

Remember, troubleshooting is a systematic approach to solving a problem. The key is to understand the problem, plan a solution, implement the solution, and then test to see if the problem has been resolved.

Exploring Version Control Systems

Before we dive deeper into GitLab, it’s crucial to understand the concepts underlying it, mainly version control systems (VCS). VCS are a type of software tools that help software teams manage changes to source code over time. They keep track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

The Importance of Version Control in Software Development

Version control systems are a cornerstone of modern software development practices. They offer numerous benefits:

  • Collaboration: VCS allow multiple developers to work on the same project without stepping on each other’s toes. They can work in parallel, making changes to the codebase that can then be merged together.

  • Versioning: VCS keep track of every change made to the codebase, along with who made the change, why they made it, and references to any problems fixed, or enhancements introduced by the change. This provides a detailed version history and a complete audit trail for your project.

  • Backup and Restore: VCS can act as a backup of your code. If you lose your local copy of the codebase, you can always retrieve it from the VCS. If you make a mistake, you can also use the VCS to revert your codebase back to a previous state.

Git: A Distributed Version Control System

Git is a specific type of version control system known as a distributed version control system. Unlike centralized version control systems, which store the version history on a central server, every copy of a Git repository contains the entire history of the project. This means that even if you lose your connection to the central server, you can continue to work and commit changes locally.

Here’s an example of how you might use Git to manage your code:

# Clone a repository
git clone https://github.com/username/repository.git

# Make changes to the code
nano myfile.txt

# Stage the changes
git add myfile.txt

# Commit the changes
git commit -m "Made some changes"

# Push the changes to the remote repository
git push origin master

# Output:
# Counting objects: 3, done.
# Delta compression using up to 8 threads.
# Compressing objects: 100% (2/2), done.
# Writing objects: 100% (3/3), 290 bytes | 290.00 KiB/s, done.
# Total 3 (delta 1), reused 0 (delta 0)
# remote: Resolving deltas: 100% (1/1), completed with 1 local object.
# To https://github.com/username/repository.git
#    4b0e18a..a8d315b  master -> master

In the code block above, we first clone a Git repository. Then, we make some changes to the code and stage these changes. After that, we commit the changes with a descriptive message. Finally, we push the changes to the remote repository.

GitLab: A Web-based Git Repository Manager

GitLab is a web-based Git repository manager that provides a centralized place to store Git repositories, a user-friendly interface for managing and reviewing code, and tools for continuous integration and deployment. It’s like a more feature-rich version of GitHub, and it can be hosted on your own servers.

GitLab is built on top of Git, so understanding Git and version control systems is crucial for understanding GitLab.

GitLab’s Role in CI/CD and DevOps

GitLab plays a central role in continuous integration/continuous deployment (CI/CD) and DevOps. CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery, and continuous deployment. CI/CD introduces ongoing automation and continuous monitoring throughout the lifecycle of apps, from integration and testing phases to delivery and deployment.

GitLab provides built-in CI/CD to test, build and deploy your code. You can easily monitor the progress of your tests and build pipelines, and you can even deploy your applications directly from GitLab.

Here’s an example of a .gitlab-ci.yml file, which is used to configure GitLab’s CI/CD pipelines:

# This file is a template, and might need editing before it works on your project.
image: ruby:2.1

before_script:
  - ruby -v
  - which ruby
  - gem install bundler --no-document
  - bundle install --jobs $(nproc)  "${FLAGS[@]}"

test:
  script:
    - bundle exec rubocop

# Output:
# The output will depend on the result of the 'rubocop' command

In the code block above, we first specify the Docker image we want to use for our CI/CD pipeline. Then, we define a before_script that will be run before all jobs. After that, we define a test job with a script that will be run during the job.

Exploring Related Concepts

While GitLab is a powerful tool on its own, it’s even more powerful when used in conjunction with other DevOps tools. Here are a few you might want to explore:

  • Git: As mentioned earlier, Git is a distributed version control system that forms the foundation for GitLab. If you’re not already familiar with Git, it’s definitely worth learning more about it.

  • Jenkins: Jenkins is an open-source automation server that can be used to automate parts of software development related to building, testing, and deploying. It can be integrated with GitLab to create a powerful CI/CD pipeline.

  • Docker: Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. Containers are isolated from each other and bundle their own software, libraries and configuration files. Docker can be used in conjunction with GitLab’s CI/CD tools to automate the deployment of your applications.

Further Resources for Mastering GitLab

If you’re interested in learning more about GitLab, CI/CD, and DevOps, here are a few resources that might be helpful:

  • GitLab’s official documentation: A comprehensive resource for all things GitLab, from basic usage to advanced features.

  • The DevOps Handbook: A book by Gene Kim, Jez Humble, Patrick Debois, and John Willis that provides a comprehensive overview of DevOps principles.

  • Docker’s Get Started Guide: A step-by-step guide to getting started with Docker, including how to build and deploy your first containerized application.

Wrap Up: Mastering GitLab Installation

In this comprehensive guide, we’ve delved into the process of installing GitLab on Linux, a crucial step for setting up your own personal code management system. GitLab, a robust platform for software management, offers a wide range of features that can significantly streamline your coding projects.

We began with the basics, walking through the process of installing GitLab on Linux using popular package managers like APT and YUM. We then ventured into more advanced territory, exploring methods such as installing GitLab from source and installing specific versions of GitLab. We also discussed alternative methods, including using different package managers like DNF and leveraging Docker for installation.

Along the way, we tackled common issues you might face during the installation process, such as ‘Permission denied’ errors, incorrect server FQDN, and the GitLab service not starting, providing you with solutions and workarounds for each issue.

Here’s a quick comparison of the methods we’ve discussed:

MethodProsCons
APT/YUMEasy to use, widely supportedLimited control over installation process
SourceFull control over installation process, access to latest featuresMore complex, time-consuming
DNFImproved dependency resolution, better performance than YUMNot available on all distributions
DockerEasy to update and rollback, isolated environmentRequires understanding of Docker, extra overhead

Whether you’re just starting out with GitLab or looking to level up your installation skills, we hope this guide has given you a deeper understanding of the different methods to install GitLab on Linux and how to troubleshoot common issues.

With the ability to install GitLab on your own server, you’re now well equipped to manage your coding projects more effectively. Happy coding!