How to Install and Set Up GitLab on Ubuntu 18.04

GitLab CE is a free and open-source Git-repository manager written in Ruby. It provides a web-based interface for issue management, code review, monitoring, and continuous integration and deployment. It is very similar to GitHub and allows you to host your own internal repository store for your development team.

GitLab gives you complete control over your repositories. So If you are looking to host and manage git repositories on a centralized server then GitLab is the best choice for you.

In this tutorial, you’ll learn how to install and configure GitLab CE on Ubuntu 18.04 server.

Requirements

  • A server running Ubuntu 18.04 server.
  • Minimum 4 GB RAM and 2 Core CPU.
  • A root password is configured.

Getting Started

Before starting, it is recommended to update your systems package repository to the latest version. You can update it with the following command:

# apt-get update -y
# apt-get upgrade -y

Once your system is up-to-date, you will need to install some dependencies to your system. You can install all of them with the following command:

apt-get install ca-certificates curl openssh-server postfix -y

During the installation, you will be asked mail server configuration type. Select ‘Internet Site’ and click “OK”.

Then, you will be asked to provide System mail name. Provide the appropriate name for your server configuration and press Ok to finish the installation.

 

Installing GitLab

By default, GitLab is not available in the Ubuntu 18.04 default repository. So you will need to add the GitLab repository to your system.

You can add the repository with the following command:

# curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
# bash script.deb.sh

Once the repository has been added, you should see the following output:

Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.

Next, install the GitLab CE by running the following command:
# apt-get install gitlab-ce -y

Once the installation has been completed successfully, 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


For a comprehensive list of configuration options please see the Omnibus GitLab readme

https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Configuring GitLab

Next, you will need to configure GitLab with your Domain name. You can edit the GitLab configuration file as shown below:

 nano /etc/gitlab/gitlab.rb 

Change the following line as per your domain name.

external_url ‘http://gitlab.example.com’

Save and close the file. Then, run the following command to reconfigure GitLab:

# gitlab-ctl reconfigure

You should get the following output:

Recipe: 
  * service[unicorn] action restart
    - restart service service[unicorn]
  * service[sidekiq] action restart
    - restart service service[sidekiq]
Recipe: gitlab::gitlab-rails
  * execute[clear the gitlab-rails cache] action run
    - execute /opt/gitlab/bin/gitlab-rake cache:clear
Recipe: 
  * service[nginx] action restart
    - restart service service[nginx]
  * service[grafana] action restart
    - restart service service[grafana]

Running handlers:
Running handlers complete
Chef Client finished, 12/699 resources updated in 31 seconds
gitlab Reconfigured!

Accessing GitLab

GitLab is now installed and configured. It’s time to access the GitLab web-based interface.

Open your web browser and type the URL http://gitlab.example.com. You will be redirected to the following page:

Now, type your desired password for GitLab root user and click on the Change your password button. You should see the following page:

Now, provide your username, password and click on the Sign in button. You should see the GitLab default dashboard in the following page:


Now, click on the Create a project button to create your first project. You should see the following page:

Provide all the required information and click on the Create project button. You should see the following page:

Testing GitLab

First, login to other system and set up the global username and email for git with the following command:

# git config --global user.name "root"
# git config --global user.email "[email protected]"

Next, clone your repository with the following command:

# git clone http://gitlab.example.com/root/project1.git

You should get the following output:

Cloning into 'project1'...
Username for 'http://gitlab.example.com': root
Password for 'http://[email protected]': 
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

Now, change the directory to the project1 and create a new README.md file:

cd project1
touch README.md

Next, commit a new file to the project1 directory:

 git add README.md
git commit -m "add README"

You should see the following output:

[master (root-commit) 7bf8685] add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

Finally, push the changes to your GitLab repository server:

git push -u origin master

Provide your GitLab username, password and hit Enter to continue. You should see the following output:

Username for 'http://gitlab.example.com': root
Password for 'http://[email protected]': 
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://gitlab.example.com/root/project1.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

Now, access your GitLab server web interface and click on the project. You should see that README.md file has been added to the repository.

Congratulations! you have successfully installed and configured GitLab CE on Ubuntu 18.04 server. You can now import or create other project and configure the appropriate level of access for your development team.

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.