How To Install GitLab As Your Private GitHub Clone.

Mohammed Naser

Mohammed Naser

Git is a distributed revision control and source code management (SCM) system with an emphasis on speed. Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server. Git is free software distributed under the terms of the GNU General Public License version 2.

GitHub is a web-based hosting service for software development projects that use the Git revision control system. GitHub offers both paid plans for private repositories and free accounts for open-source projects.

In this tutorial, we will explain how to get your own GitHub instance running on your own Ubuntu 12.04 VPS. Ubuntu 12.04 is recommended because of some incompatibilities between Python and Ruby on other Linux distributions. Also, make sure you have at least 1GB RAM memory on your VPS. Our first step is to install some required packages and dependencies.

# sudo apt-get update
# sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev

Then, we are going to install Ruby 2.0.

# mkdir /tmp/ruby && cd /tmp/ruby
# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
# cd ruby-2.0.0-p247
# ./configure
# make
# sudo make install

Once it is finished, we should make sure we are having the required version with and we should get an output with the Ruby version:

# ruby –version

Then, we need to install Bundler gem. Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. We also need to add a


user that will be used by GitLab.

# sudo gem install bundler --no-ri --no-rdoc
# sudo adduser --disabled-login --gecos 'GitLab' git

Once we are done with this, our next task is to clone the GitLab shell from its repository and set the environment.

# cd /home/git
# sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
# cd gitlab-shell
# sudo -u git -H git checkout v1.7.0
# sudo -u git -H cp config.yml.example config.yml

Now we have a local copy of the GitLab shell. There should be a sample config.yml file with it. We should open config.yml using our favourite text editor and edit as follows:

gitlab_url: "http://**yourdomain.com**/"

Once that’s done, you can move on to running the GitLab shell installer:

# sudo -u git -H ./bin/install

We will use MySQL as the database backend and connect GitLab to it. We need to install MySQL database server packages first. We will be asked to set a password during the installation. Make sure you remember or write it down because we will need it later.

# sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

Now, we should log in to MySQL, using the password that we set and create the required user and database for GitLab.

# mysql -u root –p

Once we enter the password, we are in the MySQL command prompt. We will add users, create databases and set the correct privileges to it.

CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '**enter-mysql-password**';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

To make sure your new MySQL user was created successfully let’s log in to mysql using the GitLab user. When you’ll be asked for the password, make sure to enter the one you selected above.

# mysql -u gitlab –p

If everything worked fine, we can proceed with the GitLab installation:

# cd /home/git
# sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# cd /home/git/gitlab
# sudo -u git -H git checkout 6-0-stable
# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

Similar like we did with the GitLab shell set up if we have a domain configured for our VPS we need to edit the config.yml to use that domain. We should edit the file as follows:

## Web server settings
host: **yourdomain.com**
port: 80
https: false

Now we need to execute several commands in order to set the proper privileges for everything we installed:

cd /home/git/gitlab
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX  tmp/pids/
sudo chmod -R u+rwX  tmp/sockets/
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
sudo -u git cp config/database.yml.mysql config/database.yml

Now we need to configure GitLab to be able to connect to the MySQL database using the user we set up earlier. To do this, we need to edit the config/database.yml file as follows:

  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: gitlab
  password: "**enter-mysql-password**"

Once we save the file, we should change its access level, so the other users can’t find our password:

# sudo -u git -H chmod o-rwx config/database.yml

Now we need to install a few gem and the final step (enter yes when asked):

# cd /home/git/gitlab
# sudo gem install charlock_holmes --version ''
# sudo -u git -H bundle install --deployment --without development test postgres aws
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

If everything is installed successfully, we will get output similar to:

Administrator account created:


Remember to change the password after the first login. We should set GitLab to start on server boot:

# sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
# sudo chmod +x /etc/init.d/gitlab
# sudo update-rc.d gitlab defaults 21

In order to make sure that everything is running, we execute the following command. If no error message is displayed, we are good. We can proceed and start GitLab

# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
# sudo service gitlab start

Now we need to install and make everything accessible via the web. We will use Nginx for this, once you install it, we copy the same configuration file that came with GitLab.

# cd /home/git/gitlab
# sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
# sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

We need to edit /etc/nginx/sites-available/gitlab file to use your domain name. The setting is in the beginning on the file, so it should look similar to:

server {
  listen *:80 default_server;         # e.g., listen; In most cases *:80 is a good idea
  server_name **yourdomain.com**;     #

You will have to put your fully qualified domain name instead of yourdomain.com then restart Nginx:

# sudo service nginx restart

That should be all. We have our own GitLab server fully functional. If we point our browser to the domain name we used for this installation, we will get the GitLab login prompt. We can log in with the username and provided that you used when installing, but we should change it right away. Now we can host and manage as many projects as we like.

Would you like to know about Zuul, a CI/CD project gating tool? Download our white paper and get reading!


How to up your DevOps game with Project Gating

Share on Social Media:


Cluster API driver for OpenStack Magnum

Mohammed Naser

Public Cloud

9000 MTUs (jumbo frames) in all Public Cloud Regions

Mohammed Naser


OpenInfra Summit Berlin 2022 VEXXHOST Recap

Mohammed Naser

Go to Top