How to Install and Configure GitLab CE on Ubuntu 18.04 / 16.04 Sever

GitLab CE(Community Edition) is a free and opensource is git manager tool, it provides a beautiful graphical user interface and allows us to manage all our git repositories from the centralized server.

GitLab CE is generally used for Software development teams, where coders can check-in and checkout their latest code, it can also be used for version control, Code review and CI/CD(Continues Integration / Continues Development) approach.

In this article we will demonstrate how to install latest version of GitLab CE on Ubuntu 18.04 / 16.04 Server. Below are my Lab Setup details:

  • IP Address of Ubuntu Server (18.04 /16.04) : 192.168.0.104
  • Hostname of Ubuntu Server: gitlabce.example.com
  • RAM : 2GB ( Though Gitlab recommends 4 GB for Gitlab Setup)

1) Install Gitlab dependencies using apt command

Login to your Ubuntu 16.04 / 18.04 server and run the following apt commands to install gitlab dependencies,

[email protected]:~$ sudo apt update
[email protected]:~$ sudo apt install curl openssh-server ca-certificates postfix -y

Above command will prompt you how you want to configure Postfix sever, select the option which suits to your environment.

2) Setup GitLab CE package repository via script

Run the below curl command, which will download the gitlab-ce script and will configure package repository

[email protected]:~$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

Output of above curl command would be something like below:

GitLab-CE-Package-Repository

3) Install GitLab CE package using apt command

Run the beneath command to install and configure gitlab-ce  on your server automatically, replace the server’s hostname as your setup,

[email protected]:~$ sudo EXTERNAL_URL="http://gitlabce.example.com" apt-get install gitlab-ce

Once the above the command is executed successfully, we will get output something like below,

GitLab-CE-Installion-Message

Note : If OS firewall is enabled on your server, then allow 80 and 443 ports, on Ubuntu Servers ufw is default firewall,

[email protected]:~$ sudo ufw allow http
Rule added
Rule added (v6)
[email protected]:~$ sudo ufw allow https
Rule added
Rule added (v6)
[email protected]:~$

4) Access GitLab Server from Web browser

Open your favorite web browser and type the url http://gitlabce.example.com

First time , it prompt us to set the password, so specify the password and the click on “Change your password”

GitLab-CE-Password-Set-Screen

In next screen we will get the below screen, Now login with the user name with “root” and the password that we have set in above step,

Login-GitLab-CE-GUI

Click on “Sign in”

Dashboard -GitLab-Ubuntu-18-04

As of now our GitLab Server is working on http (80) protocol, if you want to enable https for your GitLab portal, then refer the below step,

5) Configure https for your GitLab Server

All the important configuration for Gitlab server is controlled by the file “/etc/gitlab/gitlab.rb” So edit this file,  search “external_url” and add the “gitlabce.example.com” in front of external_url parameter

[email protected]:~$ sudo vi /etc/gitlab/gitlab.rb
----------------------------------------------------------
external_url 'https://gitlabce.example.com'
----------------------------------------------------------

Save and exit the file,

Now let’s create following folder and generate self-sign certificates using openssl command

[email protected]:~$ sudo mkdir -p /etc/gitlab/ssl
[email protected]:~$ sudo chmod 700 /etc/gitlab/ssl

Let first generate the private key using openssl command,

[email protected]:~$ sudo openssl genrsa -des3 -out /etc/gitlab/ssl/gitlabce.example.com.key 2048

Enter the passphrase and and remember it

Create the CSR using below command,

[email protected]:~$ sudo openssl req -new -key /etc/gitlab/ssl/gitlabce.example.com.key -out /etc/gitlab/ssl/gitlabce.example.com.csr
Enter pass phrase for /etc/gitlab/ssl/gitlabce.example.com.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Delhi
Locality Name (eg, city) []:Delhi
Organization Name (eg, company) [Internet Widgits Pty Ltd]:LinuxTechi
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:gitlabce.example.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[email protected]:~$

Remove Passphrase from the key

Run the following commands one after the another

[email protected]:~$ sudo cp -v /etc/gitlab/ssl/gitlabce.example.com.{key,original}
'/etc/gitlab/ssl/gitlabce.example.com.key' -> '/etc/gitlab/ssl/gitlabce.example.com.original'
[email protected]:~$
[email protected]:~$ sudo openssl rsa -in /etc/gitlab/ssl/gitlabce.example.com.original -out /etc/gitlab/ssl/gitlabce.example.com.key
Enter pass phrase for /etc/gitlab/ssl/gitlabce.example.com.original:
writing RSA key
[email protected]:~$
[email protected]:~$ sudo rm -v /etc/gitlab/ssl/gitlabce.example.com.original
removed '/etc/gitlab/ssl/gitlabce.example.com.original'
[email protected]:~$

Create the Certificate using below openssl command,

[email protected]:~$ sudo openssl x509 -req -days 1460 -in /etc/gitlab/ssl/gitlabce.example.com.csr -signkey /etc/gitlab/ssl/gitlabce.example.com.key -out /etc/gitlab/ssl/gitlabce.example.com.crt

Remove the CSR file using below rm command,

[email protected]:~$ sudo rm -v /etc/gitlab/ssl/gitlabce.example.com.csr
removed '/etc/gitlab/ssl/gitlabce.example.com.csr'
[email protected]:~$

Set the below permissions on Key and Certificate

[email protected]:~$ sudo chmod 600 /etc/gitlab/ssl/gitlabce.example.com.key
[email protected]:~$ sudo chmod 600 /etc/gitlab/ssl/gitlabce.example.com.crt

Reconfigure the gitlab using below command

[email protected]:~$ sudo gitlab-ctl reconfigure

Once above command is executed successfully, then your GitLab portal should be accessible over https protocol, In my case url will be: https://gitlabce.example.com/

When you access it first time, it will say something like your connection is not secure, click on “Add-Exception..”

Https-GitLab-Dashboard

6) Create a test Project and perform basic git operations

Let’s create a test project with name “linuxrocks“, click on “Create a project” option from GitLab dashboard,

New-Project-GitLab-Ubuntu-18-04

Specify the Project and its description and then click on “Create project”

GitLab-Dashboard-Linuxrocks-Project-Ubuntu18-04

Now Let’s clone the repository of “linuxrocks” project using the following commands,

[email protected]:~# git config --global user.name "Administrator"
[email protected]:~# git config --global user.email [email protected]
[email protected]:~# export GIT_SSL_NO_VERIFY=1
[email protected]:~# git clone https://gitlabce.example.com/root/linuxrocks.git
Cloning into 'linuxrocks'...
Username for 'https://gitlabce.example.com': root
Password for 'https://[email protected]':
warning: You appear to have cloned an empty repository.
[email protected]:~# ls
linuxrocks
[email protected]:~# cd linuxrocks
[email protected]:~/linuxrocks# touch linux-distributions.txt
[email protected]:~/linuxrocks# git add linux-distributions.txt
[email protected]:~/linuxrocks# git commit -m "add linux-distributions"
[master (root-commit) 3a72b57] add linux-distributions
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 linux-distributions.txt
[email protected]:~/linuxrocks# git push -u origin master
Username for 'https://gitlabce.example.com': root
Password for 'https://[email protected]':
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 238 bytes | 238.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlabce.example.com/root/linuxrocks.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
[email protected]:~/linuxrocks#

Now go to the GitLab dashboard and see whether new file has been pushed under “linuxrocks” project

Files-Projects-Gitlab-Dashboard-Ubuntu18-04

That’s conclude our article, there are plenty of things that can be configured, but that is not feasible to discuss in this tutorial. I hope this article helps you to install latest version of GitLab on your Ubuntu Servers, please do share your feedback and comments.

2 Responses

  1. Gerald Brown says:

    After running steps 1 & 2 above then running step 3 I get the following error
    sudo apt install gitlab-ce returns Unable to locate package gitlab-ce

    • Pradeep Kumar says:

      Hi Gerald,

      It seems like gitlab ce repository is not configured properly on your system that’s why you are getting the error.

      To Fix this issue, please try to enable the repo using the step2 and then run “apt-get update” and after that try to install gitlab-ce packages.

Leave a Reply

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

Pin It on Pinterest