Installing and maintaining GitLab CE on Ubuntu Server

Aug 09, 2018 - 3 min read

Follow the simple steps below to install GitLab Community Edition on a Ubuntu Server. Instructions were tested with a fresh copy of Ubuntu Server 18.04.1 LTS running on a VirtualBox 5.2.16 VM (Bridged Adapter Network mode).

Install GitLab

  1. Install prerequisites sudo apt-get install -y curl openssh-server ca-certificates (enables ssh on your server, see [1])
  2. Update the OS (optional, see [2])
    sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
  3. Run omnibus setup curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
  4. Set external access URL and install sudo EXTERNAL_URL="http://server/" apt-get install gitlab-ce (see [3])
  5. Open the HTTP port sudo ufw allow http
  6. Open http://server/ in web browser to set a password for the root user
  7. Login as root with the new password
  • HDD: 20GB (depends on the size of your repos)
  • CPU: 2 cores
  • RAM: 8GB

More details: https://docs.gitlab.com/ce/install/requirements.html

Update GitLab

# Update to latest version
sudo apt-get update && sudo apt-get install gitlab-ce

Backup GitLab

# Saves a backup to /var/opt/gitlab/backups
sudo gitlab-rake gitlab:backup:create STRATEGY=copy

Configuring email settings

Configure GitLab to send emails by editing the /etc/gitlab/gitlab.rb and then running the reconfigure command:

sudo nano /etc/gitlab/gitlab.rb
# Edit the settings using examples below, save the file
sudo gitlab-ctl reconfigure

More details: https://docs.gitlab.com/omnibus/settings/smtp.html

To check if your settings are valid, send a test email using bundled tools:

sudo gitlab-rails console
Notify.test_email('test.address@yourcompany.com', 'Message Subject', 'Message Body').deliver_now

Gmail configuration example

For simple use cases, you will probably have to allow less secure apps to access the account.

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "gitlab@yourcompany.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_domain'] = "smtp.gmail.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'

gitlab_rails['gitlab_email_from'] = "gitlab@yourcompany.com"
gitlab_rails['gitlab_email_reply_to'] = "gitlab@yourcompany.com"

Zoho configuration example

Create a new account for GitLab, eg. gitlab@yourcompany.com and enable IMAP in the Zoho control panel.

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.zoho.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "gitlab@yourcompany.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_domain'] = "smtp.zoho.com"
gitlab_rails['smtp_authentication'] = "plain"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false

gitlab_rails['gitlab_email_from'] = "gitlab@yourcompany.com"
gitlab_rails['gitlab_email_reply_to'] = "gitlab@yourcompany.com"

[1] https://about.gitlab.com/installation/#ubuntu?version=ce
[2] https://askubuntu.com/a/846968
[3] https://docs.gitlab.com/omnibus/settings/configuration.html