This tutorial is out of date and no longer maintained.
Warning: For the latest information, refer to the documentation for installing and configuring GitLab or the 1-Click App for GitLab Enterprise Edition.
Okay – GitLab isn’t really your own self-hosted GitHub. I don’t believe GitLab or GitHub share any relationship besides both being Git Management Software, but it’s the best way I find to describe in laymen’s terms what GitLab is. GitLab is awesome. It’s featured packed, and it does nearly everything that GitHub does. Best of all, you get unlimited private repos with it (or technically as many as your server can handle).
I have some pretty good DevOps skills, but I’m not really a server guy. Until recently, I’ve never previously wanted to deal with the hassle of setting up my own Git server, and GitHub’s managed solution is really quite appealing. With GitHub, you have a reliable and easy solution that you never really have to worry about. It’s also very nicely integrated with a huge array of social features like forking and organizations amongst other collaboration tools. The only thing is it can get expensive real fast if you need more than a handful of private repositories.
DigitalOcean has recently made it very simple and straightforward to set up GitLab with minimal effort and fully supporting one-click restorable backups. They also even provide great resources and tutorials on it:
This post will be very similar to those articles, but I’ll be going through it step-by-step in more detail as well as some improvements and notes of my own. Feel free to read below or go straight to the DigitalOcean docs themselves.
The first thing you’ll need to do is signup with DigitalOcean.
DigitalOcean automatically will provision your server with the public keys you upload to your account. This step isn’t really required, but it makes it easier and faster to access your new server environment.
If you don’t know much about servers - don’t worry. DigitalOcean will make this very easy for us, and they’ll actually “automatically” do most of the work for us.
For this, use the domain (or subdomain) that you would like to use. For example, you could do gitlab.scotch.io
.
The official recommendation for GitLab can be found here. In summary, your server should have:
However, I’ve found that GitLab still works well even if you don’t meet these requirements. If you select the smallest Droplet, GitLab will occasionally freeze or hang. This is usually fixed with a quick reboot of the server. I recommend the smallest Droplet you select is their $10/month plan. I have found no problems yet running this with a small team for both work and play.
Select the region that you would like your server to be in. You should select a region that is closest to you to reduce latency.
The next step is to select the GitLab application image provided by DigitalOcean. Selecting this basically means that GitLab will automatically be installed when the server is provisioned.
Select the Public SSH Key you added from earlier. This will allow you to SSH into the server without needing a password. Selecting this also means that DigitalOcean won’t send you a root password when the Droplet is created.
The last step is to enable backups. Even though Git is a distributed version control system, I still would enable this so that you can easily recover your Git repos if anything unexpected happens.
Now that we have created our Droplet and before we do anything, lets SSH in and make some minor setting changes. To get the IP address of your Droplet, just navigate to your Droplets in the DigitalOcean backend. After you find it, open the terminal and connect with it via SSH (no password will be required since we are using public and private keys):
- ssh root@<IP Address>
Note: You can visit the IP address in your browser now to see GitLab is working. Don’t worry about that just yet, we’ll get to that soon enough.
This helps remove warnings when rebooting GitLab. We’re going to add the hostname of your Droplet to the hosts file. To do this, open /etc/hosts
with your favorite editor:
- vim /etc/hosts
Then, add your IP address, a tab, and the hostname on line 2 of that file:
- <IP Address> gitlab.scotch.io
We’ll need to set some default settings and globals for GitLab. These are things like the base URL and default support email. Open the /home/git/gitlab-shell/config.yml
and update the variable gitlab_url
:
- vim /home/git/gitlab-shell/config.yml
After that, we’ll need to update one last file. Open up /home/git/gitlab/config/gitlab.yml
in your editor:
- vim /home/git/gitlab/config/gitlab.yml
You can go through this file and make adjustments to customize your installation. Most of these are just default settings. For the most part, you should leave it as is, but you’ll need to change host
under GitLab settings to your domain name.
host: gitlab.scotch.io
Then, you need to set the default From and Admin emails:
email_from: yo-its-me-gitlab@gitlab.scotch.io
support_email: nick@scotch.io
To finalize everything, reboot GitLab with the following command:
service gitlab restart
The final step is to now point the A record of either the domain or subdomain to your DigitalOcean IP address. I use CloudFlare to manage my domains, but your setup should look very similar to the below screenshot:
If everything worked out correctly and DNS propagated, you can now visit the URL in your browser to access your new git server!
You also can now SSH into your Droplet with the following command:
- ssh root@gitlab.scotch.io
Now that you have successfully navigated to your URL, you’ll need to log in. The default login for this image is:
Username: admin@local.host
Password: <PASSWORD>
You probably noticed this already when you were SSH-ing into the server. This appears in the welcome message.
After you log in, you’ll be prompt to change the password, then you’ll need to log in again with the same email and the new password. Once you have logged in successfully, you’ll need to change the default Admin email to your email address. To do this, navigate to the Admin Panel located here:
/admin/users/root/edit
Next, we’ll need to update the default username (which is currently root
). To do this, navigate to:
/profile/account
After you make that change, you are all set on configuring the server!
GitLab has a whole bunch of cool features. I won’t go over everything in detail because a lot of it is self-explanatory, but some of the things you should consider playing around with once logged in are:
If GitLab ever hangs or freezes on you, you can try rebooting it with:
- service gitlab restart
If that doesn’t work, you can reboot your entire Droplet through the command line with:
- shutdown -h now
or
- sudo reboot
When you do a power cycle from the command line like this, DigitalOcean will take a snapshot of your Server in case you need to safely restore. If that doesn’t work, you can just login to your DigitalOcean account and reboot the Droplet through their backend.
If you ever need to restore from a backup, all you have to do is log into the backend of DigitalOcean, select your Droplet, and click Restore from Backup.
That’s all there is to get your own little private Git server. GitLab is an amazing tool, and the awesome guys over at DigitalOcean have made it really straightforward to set one up with backups, hardened security, “unlimied” privated repos, and more.
I’m a huge fan of DigitalOcean and their services, and I highly recommend that you use them. GitHub is really worth every penny, but if you’re in need of a ton of private repos on a tight budget, GitLab might be the best solution for you.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!