ObjectiveInstall a Gitlab server on Ubuntu 18.04
DistributionsUbuntu 18.04 Bionic Beaver
RequirementsA running install of Ubuntu 18.04 with root privileges
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
IntroductionGitlab is the solution for hosting your own Git repositories. Not only are the server systems on par with commercial options like Bitbucket and Github, it's got an amazing web interface that's intuitive and simple for just about any user.
InstallationThere are two main options for installing a Gitlab server. Both are fairly convenient, and which you choose is largely dependent on how you want to run your server. You can either spin up a Docker container, which is better for servers running other services. Alternatively, you can run Gitlab directly on Ubuntu. It sort of takes over a lot of ports, so this method is best for dedicated servers.
DockerIf you don't already have Docker installed on your system, check out our guide to get up to speed. Once you do have Docker ready, you can install the official Docker image for Gitlab CE. Below is the startup command suggested by the Gitlab developers.
You should, however, tweak that command to suit your needs. Change the storage locations to fit your needs. Don't forget to change the hostname and ports to match your server configuration too. Gitlab requires HTTP, HTTPS, and SSH ports. The good news is, that's actually all you need to do to get Gitlab running on Docker. It will automatically restart itself when your restart your server too.
$ sudo docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest
TraditionalIf you'd rather run Gitlab directly on your server, Gitlab has you covered there too. Start off by installing the required dependencies.
$ sudo apt install curl openssh-server ca-certificates postfixGitlab comes from its own repository. The Gitlab developers wrote a convenient install script for Ubuntu and Debian systems to make the setup simple. Grab the script and run it.
$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bashAfter the script is done, you can install the Gitlab CE package.
$ sudo apt install gitlab-ceOnce you have the package installed, you can run the provided configuration utility. It provides an automatic configuration. You can modify things later, if you need to.
$ sudo gitlab-ctl reconfigureWhen the configuration is done, your server will be ready to use.
Using GitlabYou can access your Gitlab server either via
localhostor the hostname that you specified in your Docker setup.
You'll immediately be prompted to provide a password for the administrative account. The username of that account is
rootby default, but you can change it. Still, it's better to create a regular use account for regular use.
After you create your account, you'll be greeted with Gitlab's "Welcome" screen. From there, you'll be able to access the entire Gitlab dashboard. It's through that dashboard that you can create both new users and projects.
SSH KeysLike with other web-based Git repositories, using SSH keys to connect securely to your repository is usually the best idea. If you already have an SSH key, you can absolutely use that. If not, you can make one easily enough.
$ ssh-keygen -r rsa -C "user@domain"The
user@domainsection could either be your email address or your username and the hostname of your computer. Either is fine. After you have your key,
catit out into your terminal.
$ cat ~/.ssh/id_rsa.pub
Back in the Gitlab interface, pull down the user menu by clocking on the icon in the top right corner. Click on "Settings." On the resulting window, click on "SSH Keys" in the left side menu. Copy the key from the terminal. Get the line that begins with
ssh-rsa. Paste it in the box marked "Key" in Gitlab. Give it a name, and save it.