Home  >  Article  >  Development Tools  >  How to install and use GitLab on Ubuntu systems

How to install and use GitLab on Ubuntu systems

PHPz
PHPzOriginal
2023-03-31 11:09:20911browse

GitLab is an open source code hosting platform. In addition to being used for Git warehouse management, it also provides many other functions, such as continuous integration, build, CI/CD, etc. In this article, I will teach you how to install and use GitLab on Ubuntu system.

1. Installation

  1. Update the system and install the necessary software packages

First, we need to update the system and install some necessary software packages:

sudo apt update
sudo apt install -y curl openssh-server ca-certificates
  1. Install Git

GitLab uses Git for version control, so we need to install Git on the system:

sudo apt install -y git
  1. Installation PostgreSQL

GitLab uses PostgreSQL as the database. Install using the following command:

sudo apt install -y postgresql postgresql-client
  1. Configure PostgreSQL

Next, we need to log in to PostgreSQL and create a new database user and database:

sudo su - postgres
psql
CREATE USER git CREATEDB;
CREATE DATABASE gitlabhq_production OWNER git;
\q
exit
  1. Install Redis

GitLab uses Redis as a cache server. Install using the following command:

sudo apt install -y redis-server
  1. Install GitLab

Now, we can start installing GitLab. Use the following command to add the GitLab software repository:

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
  1. Install GitLab CE

Use the following command to install GitLab CE:

sudo apt install -y gitlab-ce

2. Configure GitLab

  1. Configure domain name and IP

Before we start using GitLab, we need to add the domain name and IP address to GitLab's configuration file. Edit the following file:

sudo nano /etc/gitlab/gitlab.rb

Find and uncomment the following line:

external_url 'http://example.com'

Replace "example.com" with your actual domain name or IP address.

  1. Configure SMTP

GitLab uses an SMTP server to send email notifications. In the GitLab configuration file, find the following line and set the correct SMTP server address, port, username and password:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "user@example.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

Replace "smtp.example.com", "user@example.com" and "password" Replace with your actual value.

  1. Save and exit

Save and exit the GitLab configuration file:

sudo gitlab-ctl reconfigure

Changes to the configuration file will take effect when GitLab is reconfigured.

3. Log in using GitLab

Enter your GitLab domain name or IP address in the browser to log in to GitLab. The default username is "root" and the default password is "5iveL!fe".

  1. Create project

Create a new project in GitLab. Enter the project name, description and other information.

  1. GitLab CI/CD

GitLab has built-in CI/CD capabilities that enable compilation, testing, and deployment as code is modified. To configure CI/CD, you need to add a .gitlab-ci.yml file to the project root directory.

This file defines what tasks GitLab should perform and how to perform these tasks. For example:

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - make

test:
  stage: test
  script:
    - make test

deploy:
  stage: deploy
  script:
    - make deploy

This file tells GitLab that the "make" command should be executed in the "build" phase, the "make test" command should be executed in the "test" phase, and the "make deploy" command should be executed in the "deploy" phase.

  1. Participate in open source projects

You can also discover some open source projects on GitLab, participate in them and contribute. Pull code, commit changes, push code, initiate merge requests, etc., these can all be done in GitLab.

Conclusion

It is not difficult to install and use GitLab, and its functions are very powerful. Through GitLab, you can manage your Git warehouse more conveniently and implement a series of functions such as CI/CD. Therefore, if you are interested in the fields of code hosting, automated builds, and continuous integration, don't hesitate to give GitLab a try!

The above is the detailed content of How to install and use GitLab on Ubuntu systems. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn