GitLab CE is a free and open-source Git-repository manager written in Ruby. It provides a web-based interface for issue management, code review, monitoring, and continuous integration and deployment. It is very similar to GitHub and allows you to host your own internal repository store for your development team.
GitLab gives you complete control over your repositories. So If you are looking to host and manage git repositories on a centralized server then GitLab is the best choice for you.
In this tutorial, you’ll learn how to install and configure GitLab CE on Ubuntu 22.04 server.
Requirements
- A server running Ubuntu 22.04 server.
- Minimum 4 GB RAM, 1 vCore and 10 GB disk.
- A root password is configured.
Getting Started
Before starting, it is recommended to update your systems package repository to the latest version. You can update it with the following command:
# apt-get update && apt-get upgrade -y
Once your system is up-to-date, you will need to install some dependencies to your system. You can install all of them with the following command:
# apt-get install ca-certificates curl openssh-server postfix -y
During the installation, you will be asked mail server configuration type. Select ‘Internet Site’ and click “OK”:
Then, you will be asked to provide System mail name. Provide the appropriate name for your server configuration and press Ok to finish the installation:
Installing GitLab
By default, GitLab is not available in the Ubuntu 22.04 default repository. So you will need to add the GitLab repository to your system. You can add the repository with the following command:
# curl -sLO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh && bash script.deb.sh
Once the repository has been added, you should see the following output:
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.
The repository is setup! You can now install packages.
Next, install the GitLab CE by running the following command:
# apt-get install gitlab-ce -y
Once the installation has been completed successfully, you should see the following output:
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Configuring GitLab
Next, you will need to configure GitLab with your Domain name. You can edit the GitLab configuration file as shown below:
# nano /etc/gitlab/gitlab.rb
Change the following line as per your domain name.
# external_url ‘http://gitlab.example.com
Save and close the file. Then, run the following command to reconfigure GitLab:
# gitlab-ctl reconfigure
You should get the following output:
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
Accessing GitLab
GitLab is now installed and configured. It’s time to access the GitLab web-based interface. Open your web browser and type the URL http://gitlab.example.com. You will be redirected to the following page:
Execute the following command to obtain the root user's password:
# cat /etc/gitlab/initial_root_password
Next, type the password to log in with the GitLab root user, and you should see the GitLab control panel by default on the following page:
Now, click on the "Create a project" button to create your first project. You should see the following page:
Select the desired option and provide all the required information, then click the "Create project" button to finish.
Test GitLab
First, log in to another system and set the global username and email for Git with the following command:
# git config --global user.name "root"
# git config --global user.email "admin@gitlab.example.com"
Next, clone your repository with the following command:
# git clone http://gitlab.example.com/root/name_project.git
You should see the following result:
Cloning into 'name_project'...
Username for 'http://gitlab.example.com': root
Password for 'http://root@gitlab.example.com':
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
Now change the directory to project1 and create the new file example.md:
# cd project1
# touch example.md
Then, stage a new file to the project directory:
# git add example.md
# git commit -m "add example"
You should see the following result:
[master (root-commit) 7bf8685] add example
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 example.md
Finally, push the changes to your GitLab repository server:
# git push -u origin master
Provide your GitLab username, password, and click "Enter" to continue. You should see the following result:
Username for 'http://gitlab.example.com': root
Password for 'http://root@gitlab.example.com':
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://gitlab.example.com/root/project1.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Now access the web interface of your GitLab server, click on the project, and you should see the added file in the repository.
Congratulations! You have successfully installed and configured GitLab CE on your cloud server running Ubuntu 22.04. Now you can create another project and configure the appropriate level of access for your development team.
Remember, if you have any questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io. We are by your side for whatever you need, ask us!