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
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
GitLab uses Git for version control, so we need to install Git on the system:
sudo apt install -y git
GitLab uses PostgreSQL as the database. Install using the following command:
sudo apt install -y postgresql postgresql-client
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
GitLab uses Redis as a cache server. Install using the following command:
sudo apt install -y redis-server
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
Use the following command to install GitLab CE:
sudo apt install -y gitlab-ce
2. Configure GitLab
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.
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.
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".
Create a new project in GitLab. Enter the project name, description and other information.
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.
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!