Git has become the default version control system for much of the open source world. While Git hosting services like Github and Bitbucket are good and work well, they leave you dependent on those services for everything, including crucial factors like uptime and security. Aside from that, neither of those services are open source. Thankfully, an alternative exists in the form of Gitlab.
Gitlab is an open source Git repository service written in Ruby on Rails that can either be self-hosted, or purchased as a service. Hosting Gitlab is fairly easy, especially since it comes in a per-configured “Omnibus” package.
In this tutorial, you will see how to install GitLab and all prerequisite packages to use the service on Ubuntu Linux. We will also take you through step by step instructions of setting up GitLab and getting started with using it as the version control system for your next project.
In this tutorial you will learn:
- How to install GitLab and prerequisite packages on Ubuntu
- How to get started with creating a new project in GitLab
- How to securely connect to your GitLab repository using SSH
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install GitLab on Ubuntu Linux step by step instructions
Git is a version control system that can be used with many different services, not just GitLab. It works similarly, regardless of which service you choose to use. To learn all about Git and the commands used to interact with Git repositories, check out our guide on Git tutorial for beginners.
- The Gitlab developers have made it relatively easy to install with a package repository and install scripts, so the first thing to do is update Ubuntu and install the required dependencies.
$ sudo apt update $ sudo apt install curl openssh-server ca-certificates postfix
- Next, get the Gitlab install script with curl and run it. The script will add the Gitlab repository to your system for easy installs and updates in the future. Once the script is finished, use Apt to install the Gitlab Community Edition package.
$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash $ sudo apt install gitlab-ce
- The install shouldn’t take that long, and when it completes, Gitlab needs to be configured. The Gitlab “Omnibus” package contains all of the software needed to get Gitlab running, including the Ruby on Rails project, a database, and a web server. The configuration utility will automatically configure all of that for your system. Don’t worry if you want something specific. That can be changed later.
$ sudo gitlab-ctl reconfigure
The configuration will take several minutes, since it needs to go through a ton of different things to get Gitlab working. The good news is, once it’s done, you really don’t have to configure anything, if you don’t want to. Also, because Ubuntu is a Debian based distribution, Gitlab will start as soon as the configuration finishes.
How to use Gitlab on Ubuntu Linux – First run
- By default, the Gitlab web interface will be accessible on
localhostthrough the browser. This can be changed with configuration later on. Once you get there, you will be prompted to create a new password and log in. The default user is
root, so the password that you would be setting is the root password for the Gitlab install. Once you do that, you can sign out and make your user account. Once you create the account, you will be signed in to your “Welcome” screen.
- From the “Welcome” screen, you can create a new project repository. When you start a project, you will be taken to a simple screen that allows you to name the project and set the level of access that others will have to it.
How to set up SSH keys for GitLab
- In order to securely connect to your Gitlab repository, you need to use SSH keys, If you already have one that you would like to use, skip down a bit. If not, you can create them easily with one command. To create an SSH key, type the following linux command in the terminal.
$ ssh-keygen -t rsa -C "email@example.com"
The “user” portion would be your user name, either on your local machine or the server, and the “domain.com” part would either be the name of your computer or the domain of the server. However you’d prefer to do it will work fine.
- Now, the next line will show the key that you just generated.
$ cat ~/.ssh/id_rsa.pub
- You should see a long string of characters. From that file, copy the line that begins with
ssh-rsa. Back in the browser, pull down the menu, and navigate to “Profile Settings”. From there, select “SSH Keys” from the menu across the top. Paste your key into the box marked, “Key” and give it a name before saving it. After that, your repository should be set up to use like any other web-based Git hosting service.
In this tutorial, we saw how to install the GitLab service on Ubuntu Linux, and use Ubuntu as the version control server for a project. This included setting up a new Git repository and configuring SSH keys in order to securely connect to it. GitLab is a great project for self hosted Git repositories. Best of all, it is secure and free to use. If you do not like hosting your own Git server, you can always pay a small fee to have it professionally hosted for you at GitLab.