GitLab

How To Set Up GitLab As Your Very Own Private GitHub On Ubuntu 24.04

In today’s digital landscape, version control is an essential tool for developers and teams managing code. While GitHub is a popular choice for hosting repositories, some users prefer a self-hosted solution like GitLab for added privacy and customization. In this post, we’ll guide you through the process of setting up GitLab on your Ubuntu 24.04 server, allowing you to enjoy the benefits of a private GitHub-like environment.

Why Choose GitLab?

Before we dive into the setup process, let’s briefly discuss why GitLab might be a better option for you:

  1. Data Control: With GitLab, you have full control over your repositories and data, ensuring privacy and security.
  2. Rich Features: GitLab offers a comprehensive set of features including CI/CD integration, issue tracking, and a robust wiki.
  3. Self-Hosting: You can customize your GitLab instance to suit your team’s needs without being constrained by the limitations of a public hosting service.

Prerequisites

Before you begin, make sure you have the following:

  • A server running Ubuntu 24.04 (either a virtual machine or a dedicated server).
  • Root access or a user with sudo privileges.
  • A domain name (optional, but recommended for accessing GitLab).
  • Basic knowledge of using the terminal.

Step 1: Update Your System

Start by updating your package index and upgrading your installed packages to their latest versions. Open your terminal and run:

sudo apt update && sudo apt upgrade -y

Step 2: Install Required Dependencies

GitLab requires several dependencies. Install them using the following command:

sudo apt install -y curl openssh-server ca-certificates tzdata

If you plan to use GitLab’s built-in email notification feature, you’ll also need to install Postfix:

sudo apt install -y postfix

During the installation, you may be prompted to choose a configuration type. For most users, “Internet Site” is the best choice. Enter your server’s domain name when prompted.

Step 3: Add the GitLab Repository

Next, you’ll need to add the official GitLab package repository. First, download the GitLab installation script:

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

Now, you can install GitLab. Replace your-domain.com with your actual domain name:

sudo EXTERNAL_URL="http://your-domain.com" apt install gitlab-ee

Step 4: Configure GitLab

Once the installation is complete, you need to configure GitLab. Run the following command to start the GitLab configuration process:

sudo gitlab-ctl reconfigure

This command will set up GitLab with the specified URL and initialize the necessary services.

Step 5: Access GitLab

After the configuration is complete, you can access GitLab by navigating to http://your-domain.com in your web browser. You should see the GitLab welcome page.

Initial Setup

  1. Create an Admin Account: The first time you access GitLab, you will be prompted to set up an admin account. Enter the required information to create your account.
  2. Configure Your Profile: Once logged in, take a moment to configure your profile and preferences.

Step 6: Set Up Your First Repository

With GitLab up and running, it’s time to create your first repository:

  1. Click on the “New Project” button on your GitLab dashboard.
  2. Choose a project name, description, and visibility level (public, internal, or private).
  3. Click on “Create project” to finalize the setup.

Now you can clone the repository to your local machine and start working on your code!

Step 7: Enable HTTPS (Optional, But Recommended)

For enhanced security, it’s essential to enable HTTPS for your GitLab instance. This can be done using Let’s Encrypt. First, install Certbot:

sudo apt install -y certbot

Then, run the following command to obtain a certificate:

sudo certbot certonly --standalone -d your-domain.com

After obtaining the certificate, edit the GitLab configuration file to enable HTTPS:

sudo nano /etc/gitlab/gitlab.rb

Find and uncomment the following lines, replacing them with your domain name:

external_url 'https://your-domain.com'
nginx['ssl_certificate'] = "/etc/letsencrypt/live/your-domain.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/your-domain.com/privkey.pem"

Finally, reconfigure GitLab:

sudo gitlab-ctl reconfigure

Conclusion

Congratulations! You have successfully set up your very own private GitLab instance on Ubuntu 24.04. With GitLab, you can now enjoy a range of features similar to GitHub, but with the added benefit of having complete control over your data and environment.

Feel free to explore GitLab’s extensive documentation to learn more about advanced features like CI/CD pipelines, issue tracking, and user management.

Happy coding, and welcome to the world of self-hosted version control!


If you found this guide helpful, please share it with your fellow developers. For more tips and tutorials on cloud hosting and development tools, stay tuned to the Greenhost.cloud blog!