TranslateProject/sources/tech/20230727.1 ⭐️ How to Install GitLab on Ubuntu 22.04 20.04.md
2023-08-02 08:59:57 +08:00

6.8 KiB
Raw Blame History

How to Install GitLab on Ubuntu 22.04 | 20.04

GitLab, an open-source platform, provides a robust and feature-rich solution for managing repositories, issues, CI/CD pipelines, and much more. If youre an Ubuntu 22.04 or 20.04 user and want to set up your own GitLab instance to streamline your DevOps workflow, youre in the right place.

This step-by-step guide will walk you through the installation process of GitLab on Ubuntu 22.04 or 20.04. GItlab comes with Enterprise edition (Gitlab EE) and Community edition (Gitlab CE). In this post , we will cover the community edition.

Prerequisites
  • A virtual or dedicated server running Ubuntu 22.04 or 20.04 with SSH access.
  • Static Hostname ( gitlab.linuxtechi.net)
  • Sudo User with admin rights
  • 2 GB RAM or more
  • 2 vCPUs or more
  • Internet Connectivity

1) Update System Packages

Lets begin by updating the package lists and upgrading any existing packages to their latest versions.

$ sudo apt update
$ sudo apt upgrade -y

Reboot the system after applying updates,

$ sudo reboot.

2) Install Dependencies

GitLab requires some dependencies to function correctly. Install them using the following commands:

$ sudo apt install -y curl openssh-server ca-certificates postfix

During the postfix installation, a configuration window will appear. Choose “Internet Site” and enter your servers hostname as the mail server name. This will allow GitLab to send email notifications.

,

Choose “Internet Site” and then slect OK.

Check systems hostname and choose OK.

3) Add GitLab Apt Repository

Now, well add the GitLab repository, run the following curl command. It will automatically detect your Ubuntu version and will set the repository accordingly.

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

4) Install Gitlab

Run the beneath command to install and configure gitlab-ce  on your ubuntu system automatically, replace the servers hostname as your setup,

$ sudo EXTERNAL_URL="http://gitlab.linuxtechi.net" apt install gitlab-ce

Once the above the command is executed successfully, we will get output something like below,

Output above confirms that GitLab has been installed successfully. User name for gitlab web interface is root and password is stored at “/etc/gitlab/initial_root_password”

Note :If OS firewall is enabled on your ubuntu system, then allow 80 and 443 ports.

$ sudo ufw allow http
$ sudo ufw allow https

5) Access GitLab Web Interface

With GitLab installed and configured, open your web browser and enter your servers IP address or hostname.

http://

  • User Name: root
  • Password : <<Get Password from /etc/gitlab/initial_root_password>>

click on “Sign in”

Great, above confirms that we have successfully login to Gitlab Web interface.

As of now our GitLab Server is working on http (80) protocol, if you want to enable https for your GitLab, then refer the below steps,

6) Setup HTTPS for GitLab Web Interface

For added security, you can configure HTTPS for your GitLab instance using self-signed certificate or Lets Encrypt. We can use Lets encrypt only for public domain whose A recorded available on internet. But in our case, we are using a private domain, so we will be using self-signed certificate to secure GitLab.

Now, lets create following folder and generate self-sign certificates using openssl command

$ sudo mkdir -p /etc/gitlab/ssl
$ sudo chmod 755 /etc/gitlab/ssl

Generate the private key using following openssl command,

$ sudo openssl genrsa -des3 -out /etc/gitlab/ssl/gitlab.linuxtechi.net.key 2048

Enter the passphrase and and remember it

Create the CSR using below command,

$ sudo openssl req -new -key /etc/gitlab/ssl/gitlab.linuxtechi.net.key -out /etc/gitlab/ssl/gitlab.linuxtechi.net.csr

Remove Passphrase from the key, execute the following commands one after the another

$ sudo cp -v /etc/gitlab/ssl/gitlab.linuxtechi.net.{key,original}
$ sudo openssl rsa -in /etc/gitlab/ssl/gitlab.linuxtechi.net.original -out /etc/gitlab/ssl/gitlab.linuxtechi.net.key
$ sudo rm -v /etc/gitlab/ssl/gitlab.linuxtechi.net.original

Create the Certificate file

$ sudo openssl x509 -req -days 1460 -in /etc/gitlab/ssl/gitlab.linuxtechi.net.csr -signkey /etc/gitlab/ssl/gitlab.linuxtechi.net.key -out /etc/gitlab/ssl/gitlab.linuxtechi.net.crt

Remove the CSR file using below rm command,

$ sudo rm -v /etc/gitlab/ssl/gitlab.linuxtechi.net.csr

Set the permissions on key and certificate file

$ sudo chmod 600 /etc/gitlab/ssl/gitlab.linuxtechi.net.key
$ sudo chmod 600 /etc/gitlab/ssl/gitlab.linuxtechi.net.crt

All the important configuration for Gitlab server is controlled by the file “/etc/gitlab/gitlab.rb” So edit this file,  search “external_url” and add the “https://gitlab.linuxtechi.net”

$ sudo vi /etc/gitlab/gitlab.rb
----------------------------------------------------------
external_url 'https://gitlab.linuxtechi.net'
----------------------------------------------------------

Save and exit the file, reconfigure gitlab using beneath command so that its web interface start working https.

$ sudo gitlab-ctl reconfigure

Once above command is executed successfully, then your GitLab interface should be accessible over https protocol, In my case url will be: https://gitlab.linuxtechi.net/

When you access it first time, it will say something like your connection is not secure, click on “Accept the Risk and Continue”

Conclusion

Congratulations! Youve successfully installed GitLab on your Ubuntu 22.04 or 20.04 system. With GitLab up and running, you can now create repositories, collaborate with your team, and enhance your development workflow through GitLabs impressive features. Enjoy seamless version control, continuous integration, and more, all under your control!


via: https://www.linuxtechi.com/how-to-install-gitlab-on-ubuntu/

作者:Pradeep Kumar 选题:lkxed 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出