Technical Article => Software => Open Source

GitHub, GitLab and BitBucket are the three most famous code hosting platform in the world. They have different features which allow teams or individuals to share code with others remotely. In case you want to build your own code hosting server so that you can host and share the code by yourself, you can install and set up your own server. In this post, we will walk you through a guide on installing and setting up GitLab server on Linux environment.

gitlab is a web based code hosting tool which is open sourced to everyone. Below we start the installation and setup process. The Linux system we are using is Ubuntu.

1. Install gitlab

On Ubuntu, we can run below commands to first update the package dependencies.

sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates

Next download and run the installation script.

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

In case the server is not connected to internet or the UBuntu release doesn't have the official support of the GItLab package support yet(Like currently Ubuntu 20.04 LTS doesn't work with above command), can also download the package first from another server which has internet connection. The place to download package is at https://packages.gitlab.com/gitlab/gitlab-ce. After downloading the package, copy it over to the server you want to install it and run below command to install.

cd /tmp wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/bionic/gitlab-ce_12.10.1-ce.0_amd64.deb/download.deb sudo dpkg -i gitlab-ce_12.10.1-ce.0_amd64.deb

The installation output:

pike@pike-VirtualBox:/tmp$ sudo dpkg -i gitlab-ce_12.10.1-ce.0_amd64.deb Selecting previously unselected package gitlab-ce. (Reading database ... 123505 files and directories currently installed.) Preparing to unpack gitlab-ce_12.10.1-ce.0_amd64.deb ... Unpacking gitlab-ce (12.10.1-ce.0) ... Setting up gitlab-ce (12.10.1-ce.0) ... 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

2. Setup gitlab

The configuration file of gitlab is located at /etc/gitlab/gitlab.rb . Open the file and find the variable external_url and update it to a hostname which can be accessed from other machine. Save and run command.

sudo gitlab-ctl reconfigure

This will reconfigure the gitlab service and make the configuration change to take effect. It may take some time to finish this step and be patient.



Now start the service.

sudo gitlab-ctl start

THe output of the command would tell whether all services started successfully.

pike@pike-VirtualBox:/tmp$ sudo gitlab-ctl start ok: run: alertmanager: (pid 20838) 9s ok: run: gitaly: (pid 20821) 11s ok: run: gitlab-exporter: (pid 20790) 13s ok: run: gitlab-workhorse: (pid 20775) 14s ok: run: grafana: (pid 20854) 8s ok: run: logrotate: (pid 20173) 345s ok: run: nginx: (pid 20156) 356s ok: run: node-exporter: (pid 20784) 14s ok: run: postgres-exporter: (pid 20847) 8s ok: run: postgresql: (pid 19818) 452s ok: run: prometheus: (pid 20799) 12s ok: run: redis: (pid 19693) 471s ok: run: redis-exporter: (pid 20792) 13s ok: run: sidekiq: (pid 20102) 374s ok: run: unicorn: (pid 20071) 380s

And can check status with command.

sudo gitlab-ctl status

Also can open a browser and enter localhost to open the GitLab web portal. And it will ask you to set root user and password.

After this set up is done. You can access the gitlab repo from another machine with the correct hostname which is configured in external_url.