GitLab Tutorial – installation and first steps in GitLab

GitLab is a popular version control system (VCS) that is mainly used in software development. This web-based software was written and published in the ‘Ruby on Rails’ programming language in 2011 by Dmitri Saparoschez and is now considered an indispensable tool among the developer community.

The main advantage of GitLab is that it makes cross-team, agile software development much easier. Several developers can work on a project at the same time and edit different features in parallel, for example. Continuous logging of processes ensures that changes to the code are not lost or accidentally overwritten. In addition, changes that have already been made can be easily undone.

GitLab is based on the widely used Git version control software. As open source software, Git is freely accessible and is one of the most popular version control systems. GitLab is one of the leading alternatives to GitHub (many users switched to GitLab when GitHub was acquired by Microsoft in 2018).

How does GitLab work?

GitLab is a web-based application with a graphical user interface, but it can also be installed on a private server. Projects are the centrepiece of GitLab. In these projects, the code to be edited is stored in digital archives, which are called repositories. All project content and files can be found in these project directories, such as JavaScript, HTML, CSS or PHP files.

GitLab works like this: First, all team members download their own copy of the central repository to their computer. Changes to the code are initially made using commits. After editing, the changes are then fed into the main repository.

Another important feature is branching – branches that diverge from the main code for independent editing. This lets you add and test new functions without affecting the main line. Built-in continuous delivery and continuous integration mean GitLab is ideal for testing. Useful features like merge requests and forks make it one of the most popular continuous integration tools.

GitLab features at a glance

The main features of GitLab include:

  • User-friendly interface
  • Branches can remain private or can be shared publicly
  • Ability to manage multiple repositories
  • Code review
  • Built-in bug and issue tracking
  • Built-in, free continuous integration/delivery (CI/CD)
  • Project wikis
  • Easy creation of code snippets for sharing parts of the code

GitLab licensing and delivery models

GitLab is based on open, freely accessible source code. In 2013, a separate enterprise edition was introduced for businesses, which is why two delivery models are now available:

  • GitLab CE: Community Edition (free)
  • GitLab EE: Enterprise Edition (paid)

Both versions are based on the MIT open-source license. The Enterprise Edition has several additional features compared to the free Community Edition. GitLab offers three different subscription models depending on the scope of additional features required.

In addition, the Enterprise Edition can be used free of charge, but it only includes the basic functions of the Community Edition. This model is appropriate if you think you might want to install the Enterprise version at some point as you can upgrade later on. In contrast, it’s much more time-consuming to switch from the Community Edition to the Enterprise Edition.

GitLab Basics: Hosting and installing

We generally recommend using GitLab in a Linux environment. Like Git, GitLab software is custom-made for Linux. You can install and use GitLab on Windows, albeit with restrictions. If you want to do this, you can use a virtual machine that simulates a Linux environment on the Windows computer. A simpler option is to install the GitLab Runner, which is required if you want to use continuous integration functionalities in GitLab.

Hosting GitLab yourself or using a cloud solution

Installing GitLab on your own server doesn’t pose any major challenges if you have previous Linux experience, but it’s relatively time-consuming. In addition to the installation itself, you have to factor in the time required for configuration and regular maintenance.

If you want to save yourself this effort, you can also install and use GitLab as Software-as-a-Service (SaaS) on a cloud server (many providers offer this service). This way you can deploy the software quickly without the need for complex installation and configuration. The GitLab Runner is usually already installed so that you can get started right away.

The advantage of manually installing GitLab in your own server environment is greater flexibility. You have complete freedom when it comes to installation: You can make your own decisions about backups, updates or additional resources, and install what you need for a specific application. Nevertheless, the cloud solution is appealing, especially if your system administrator tends to deal with heavy workloads.

Tip

IONOS offers powerful, affordable cloud servers and virtual servers so you can set up your own virtual infrastructure to match your needs ASAP. These servers work with standard Linux distributions (Ubuntu, Debian) and Windows.

Installing GitLab on Linux servers

To install GitLab on a Linux server, you first need Git software. We explain how to install Git on a server in our Git tutorial. Next, you should download the GitLab omnibus package from the official GitLab website. This package contains all the necessary files and is recommended for installing GitLab on Linux.

Updating the repository

Next, log in to the server as the root user and update the repository (Ubuntu in this case) to receive all the necessary packages for GitLab. To do this, use the following commands:

sudo ssh root@GitLabServer
sudo apt-get update

Then install the packages as follows:

sudo apt install curl openssh-server ca-certificates postfix

A configuration screen appears during Postfix installation. Select Internet site and enter the server domain name that you use to send and receive emails.

Installing GitLab

The next step is to install the GitLab Omnibus package. First, add the GitLab package repository using the following command:

curl https://packages.GitLab.com/install/repositories/GitLab/GitLab-ee/script.deb.sh | sudo bash

Then install GitLab using the apt command. In this example code, GitLab is installed in the Community Edition (CE):

sudo apt install GitLab-ce

Once the data has been entered, the server automatically downloads and installs the GitLab package. After the installation has been confirmed, you should configure the main URL that you use to access the GitLab server.

Change the URL "https://GitLab.example.com" to the URL you actually use. To do this, go to the /etc/GitLab directory where the configuration is located and edit the configuration file GitLab.rb using the default vim text editor.

The commands look like this:

cd /etc/GitLab
vim GitLab.rb

In the GitLab.rb file, look for line 9 (‘external_url) and enter the desired URL. GitLab will start and configure the installation at this URL.

When you open GitLab for the first time, you’ll be directed to a password reset screen. Set the password for the administrator; you’ll then be redirected to the login screen. You can initially use the default user ‘root’ to log in. You can change the settings later in the profile settings.

Installing GitLab on Windows

GitLab itself cannot be installed on a Windows server, but you can use a GitLab Runner to access an existing GitLab installation on a Linux server from Windows. This software is installed in Windows and is compatible with the continuous integration functionality of GitLab (GitLab CI/CD). In this way, the runner can send requests and work orders to GitLab.

Downloading Git for Windows and GitLab Runner binary data

You need Git for Windows before you can install GitLab on a Windows server. You can download the software from the official website. You should also assign a unique password for the user account unless you are going to use the default system account.

You will need a token that grants the runner access to the GitLab instance. This access key can be found in the GitLab settings under Settings -> CI / CD.

Next, download the binary file (x86 or amd64) for the GitLab Runner for Windows and create a folder anywhere in your system, for example C:\GitLab-runner.

Paste the file into this folder and rename it to GitLab-runner.exe. Then open Windows PowerShell (or Command Prompt) with advanced administrator access rights.

Registering the GitLab runner in Windows

To register the GitLab runner, enter the following command in the command line:

./GitLab-runner.exe register

Then enter the URL of the GitLab installation (the following is just an example):

https://GitLab.com

In the next window, enter the token in order to link the runner to the GitLab installation. You can then define your own description for the runner. This option can also be changed later in the GitLab interface. In the next window, you can define tags. These tags are useful if you want a runner to process several projects at the same time. You can use the tags to specify exactly which projects are assigned.

In the last step, you define the ‘executor’, meaning the environment in which the runner runs, for example a VirtualBox instance or a shell environment. Shell is the easiest executor to configure and the default option when you register a GitLab Runner on Windows for the first time.

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell

Installing and starting the GitLab Runner on Windows

To install the GitLab Runner, you can either use the default system account or your own user account. In the PowerShell or Command Prompt, navigate to the directory you created above and type the following commands one at a time:

cd C:\GitLab-Runner
.\GitLab-runner.exe install
.\GitLab-runner.exe start

Gitlab tutorial – first steps in GitLab

After installing GitLab, you can access the graphical user interface at the previously defined URL. To do this, you can use the browser of your choice and then log in as an administrator. The user name and the associated password can be changed later in the Admin Area.

Creating users in GitLab

In the Admin Area, you can select the New User button to create the users who collaborate on GitLab projects. To do this, you define a unique email address and log-in credentials for the user, and then assign the user to the desired project.

In the same area, you can also change user permissions by selecting ‘Edit’ and block or remove users. Note that blocking a user prevents them from logging in while keeping all data (such as commits) intact. Completely removing a user also deletes the information linked to the user. Therefore, always exercise caution when selecting this option.

Creating a new project

The most important step is to create a new project. To do this, select the New project button. This will take to you the page for creating a new project. Enter the name of the project in the ‘Project name’ field. This field may not contain any special characters or spaces. Under Visibility level, you define which users have access to the project. GitLab distinguishes between the following levels:

  • Private: Only you have access.
  • Internal: Each logged-in user has access.
  • Public: Any user can access the project without prior authentication.

After selecting the settings, create the project by selecting Create project. You can then link the project directly to a local Git repository. To do this, select the ‘HTTPS’ option under the project name in the project view and copy the displayed commands to the command line.

In case you don’t have a local copy of the repository on the server, you can add it now by entering the following command:

$ git clone https://server/namespace/project.git

Once you’ve initialised the repository, you can view all information about it on the project page. You can also view recent activities and look at the commit history to see who made which changes to the code and when.

Team collaboration with GitLab

The easiest way to work together with other users on a GitLab project is to grant users direct push access to the repository. To do this, add the users to a project as explained above and provide them with the appropriate access rights.

Users with ‘developer’ authorisation or higher can move their commits and branches to the repository without restrictions. Alternatively, you can also use merge requests, which allow you to control access more closely since the master branch is not edited directly. Instead, users can create branches, enter their commits and then make a merge request to connect the branch to the master (or another branch).

Users without access rights can also create forks, meaning they can edit their own copy of the project with pushed commits. They can then submit a merge request to reintegrate the fork into the main project. With this feature, the project owner has full control over what goes into the repository, but he or she can also allow unknown users to make contributions.

Note

As a sophisticated collaboration tool, GitLab has numerous functions that make teamwork easier, such as project wikis or system maintenance tools.

Was this article helpful?
Page top