Installing Gitlab on Ubuntu 18.04

August 01, 2019

As part of my path of trying to self host everything I can, I figured the first thing I should do is get a solid Gitlab server setup to hold my website source code. My website source code will remain public, so you all can continue to see the fact that I don’t track you.

For this server, I decided that I would put it up on Digital Ocean for now. This is partially because I’m lazy and wanted it to be easy to get going but also because my Hacktanix cluster that I’m building is very angry with me right now.

So, let’s get started. I grabbed a 4GB Memory Droplet on DO, running Ubuntu 18.04.

Do your generic Ubuntu setup, make sure you have a user that is not root, but has sudoer access.

sudo apt-get install -y curl ca-certificates
sudo apt-get install -y postfix
sudo systemctl start postfix
sudo systemctl enable postfix
sudo apt-get install fail2ban
sudo vim /etc/fail2ban/jail.local

At this point we want to make sure fail2ban is going to be watching SSH. Insert the following block of text into /etc/fail2ban/jail.local.

[sshd]
enabled = true
port = 22
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

Now restart fail2ban:

sudo systemctl restart fail2ban
sudo systemctl enable fail2ban

Now let’s get Gitlab’s repository setup.

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

Note: If piping directly into bash isn’t your thing, head over to their website and download the .deb file directly.

Now we’re going to install Gitlab-CE.

sudo apt-get install gitlab-ce
sudo vim /etc/gitlab/gitlab.rb

You’ll want to add your FQDN for the server in /etc/gitlab/gitlab.rb. This is also a good time to make sure that you have DNS setup for your server, otherwise the automated Letsencrypt setup will fail.

sudo gitlab-ctl reconfigure

This will run for a few minutes and then you’re ready to go! Log into https://yourserver.example.com and set the root password.

If you run into an error where it says you can’t set the password because of 7 or 8 reasons, here’s what I did to solve the issue.

gitlab-rails console production
user = User.where(id: 1).first
user.password = 'mypasswordhere'
user.password_confirmation = 'mypasswordhere'
user.save!

I hope this helps! In the future, we’ll look at how to deploy a highly available instance of Gitlab.