GitLab is a popular, open-source Git repository manager that provides a web interface for version control, issue tracking, CI/CD pipelines, and more. Installing GitLab on a Virtual Private Server (VPS) allows you to have a self-hosted version control system for managing your code repositories.
In this guide, we will walk you through the steps to install and configure GitLab on your VPS for managing your version control and project management needs.
Prerequisites
Before you begin the installation, ensure the following:
- A VPS running Ubuntu 20.04 or later (This guide assumes Ubuntu; you can adapt the instructions for other distributions such as CentOS or Debian).
- Root or sudo access to your VPS.
- A minimum of 4 GB of RAM and 2 CPU cores (recommended for GitLab).
- A domain name (optional, for a more professional setup) and access to your DNS provider.
Step 1: Update Your VPS
To ensure that your system packages are up-to-date, run the following commands:
Step 2: Install Required Dependencies
GitLab requires several dependencies to run properly. Install them by running the following command:
For email notifications, you will need an SMTP server. You can configure SMTP later, but for now, we will proceed without it.
Step 3: Install GitLab
GitLab provides a convenient Omnibus package that bundles all necessary dependencies, making it easy to install and configure. You can install GitLab by following these steps:
-
Download and Install the GitLab Package:
First, you need to add the GitLab package repository to your system. Run the following commands to install GitLab:
After the repository is added, you can install GitLab CE (Community Edition) by running:
-
Configure GitLab:
Once GitLab is installed, you need to configure it. You can configure it using the
gitlab-ctl
command.Run the following command to configure GitLab:
This command will configure GitLab with the default settings. It may take a few minutes to complete.
Step 4: Access GitLab Web Interface
Once the installation is complete, GitLab should be running on your VPS. You can access the GitLab web interface by navigating to the following URL in your browser:
- If you're using the server's IP:
http://your_server_ip
- If you're using a domain:
http://your_domain.com
The first time you access GitLab, you'll be prompted to set an admin password. This password will be used for the root
admin account.
- Set the Admin Password: Enter a strong password and click "Save" to continue.
- Log In: After setting the password, you can log in to GitLab using the username
root
and the password you just set.
Step 5: Configure GitLab for Production Use
Configure GitLab URL
If you're using a domain name for your GitLab instance, you should configure the external URL so that GitLab knows how to handle requests properly.
-
Open the GitLab configuration file:
-
Find the line that begins with
external_url
and change it to your domain name (or IP address if you're not using a domain): -
After saving the changes, reconfigure GitLab:
Set Up SSL (Optional but Recommended)
If you want to secure your GitLab instance with HTTPS, it is highly recommended to set up an SSL certificate. You can use a free SSL certificate from Let's Encrypt.
-
Open the GitLab configuration file again:
-
Change the
external_url
tohttps
: -
Enable Let's Encrypt:
-
Save the file and reconfigure GitLab:
GitLab will automatically generate and install the SSL certificate for you.
Step 6: Create a GitLab Project and Add Repositories
After you have successfully set up GitLab, you can start creating projects and adding repositories.
-
Create a Project:
- Log in to the GitLab web interface with your
root
account. - Click on the “New Project” button.
- Enter the project name, description, and visibility level (Private, Internal, or Public).
- Click "Create Project".
- Log in to the GitLab web interface with your
-
Create a New Repository:
You can create a new repository inside your project by following the instructions on the project page. You can either create a repository through the GitLab interface or clone it to your local machine and push your code.
Example commands to clone and push to GitLab:
-
Add Users and Permissions:
You can invite other users to collaborate on your GitLab project. To add users:
- Go to your project page.
- Click on “Settings” > “Members”.
- Enter the user's email address and select the appropriate permissions (Guest, Reporter, Developer, Maintainer, or Owner).
Step 7: Enable and Manage GitLab Services
GitLab is composed of several services (such as the web interface, database, etc.), all of which are managed using gitlab-ctl
.
-
Check GitLab Services Status:
To check the status of GitLab services, run:
-
Start, Stop, or Restart GitLab:
You can start, stop, or restart GitLab services using the following commands:
-
View Logs:
To view the logs of GitLab, use:
Step 8: Backup and Restore GitLab
It's important to regularly back up your GitLab data. GitLab provides built-in tools for creating and restoring backups.
-
Create a Backup:
To create a backup of your GitLab instance, run:
-
Restore from Backup:
To restore a backup, run:
Conclusion
You have now successfully installed and configured GitLab on your VPS for version control. With GitLab, you can manage your Git repositories, collaborate with your team, set up CI/CD pipelines, and much more. Remember to secure your GitLab installation, configure SSL, and regularly back up your data to ensure your project stays safe.