How to Install GitLab on CentOS 7

How to Install GitLab on CentOS 7

We’ll show you how to install GitLab on CentOS 7. GitLab is a self-hosted git repository management system. It is used by more than 100,000 organizations worldwide. Today we will show you how to install GitLab on your CentOS VPS. For instructions about how to install GitLab on an Ubuntu VPS, you can check our Install GitLab on Debian tutorial. Installing GitLab on CentOS 7 is fairly easy task and it should take 10 minutes for the installation.

To run GitLab on your server you will need to have Ruby 2.0 or 2.1 installed on your server. GitLab requires 2 CPU cores and 2GB of RAM so it can support up to 500 users. This makes our SSD 2 VPS hosting plan suitable for your needs. You will need to have MySQL or PostgreSL and Redis. Additional packages will be installed. When it comes to this tutorial, we are using our CentOS 6 64bit full template.

Step 1: Add the required repositories to your system

The first step is to add the required repositories to your system. You can do this using the following commands:

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm -Uvh
wget -O /etc/yum.repos.d/PUIAS_6_computational.repo
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

Step 2: Installing the required packages

Next thing you need to do is update all your system software, remove the unnecessary packages and install the required packages.

yum update -y
yum remove git httpd sendmail -y
yum -y install nginx zlib-devel openssl-devel git redis perl-CPAN ncurses-devel gdbm-devel glibc-devel tcl-devel curl-devel byacc db4-devel sqlite-devel libxml2 libxml2-devel libffi libffi-devel libxslt libxslt-devel libyaml libyaml-devel libicu libicu-devel system-config-firewall-tui sudo wget crontabs gettext perl-Time-HiRes cmake gettext-devel readline readline-devel libcom_err-devel.i686 libcom_err-devel.x86_64 expat-devel logwatch logrotate patch

Step 3: Create user

Create a system user for GitLab:

adduser --shell /bin/bash --home-dir /home/git/ git

Now edit the ‘/etc/sudoers’ file and add ‘/usr/local/bin’ at the end of:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

It should look like this:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Step 4: Download Git source

Download Git source and extract it in your ‘/tmp’ directory. At the moment of writing, the latest version available is 2.1.3.

mkdir /tmp/git
cd /tmp/git
tar -xzvf git-2.1.3.tar.gz
cd git-2.1.3/
make prefix=/usr/local install

install gitlab on centos 7

Step 5: Download and install Ruby

After doing this, you will need to download and install Ruby on your CentOS VPS. At the moment of writing, the latest version available is 2.1.5.

mkdir /tmp/ruby
cd /tmp/ruby
tar -xzvf ruby-2.1.5.tar.gz
cd ruby-2.1.5
./configure --disable-install-rdoc
make prefix=/usr/local install

Step 6: Create new database

Once the installation of Ruby is completed, it is time to create a database. You can do this using the following commands:

mysql -u root -p 
CREATE USER 'git'@'localhost' IDENTIFIED BY 'PaSsWoRd';
CREATE DATABASE `gitlabdb` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT ALL ON `gitlabdb`.* TO 'git'@'localhost';

Do not forget to change ‘PaSsWoRd’ with a password of your choice.

Step 7: Configure Redis

Now, let’s configure Redis. Open the ‘/etc/redis.conf’ file with an editor of your choice and set ‘port 0’.

port 0

Then, add the following lines at the end of the file:

unixsocket /var/run/redis/redis.sock
unixsocketperm 0775

Restart the service and add git to the redis group:

service redis restart
usermod -aG redis git

Step 7: Install GitLab on CentOS 7

Now, let’s install GitLab. We assume that you have a full root access to your Linux VPS so you should execute all these commands as root. Also, you can change the ‘7-4-stable’ to the latest stable version available.

cd /home/git
sudo -u git -H git clone -b 7-4-stable gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

Edit ‘config/gitlab.yml’ and follow the instructions at the top of the file.

sudo -u git -H nano config/gitlab.yml

Execute the commands:

chown -R git log/
chmod -R u+rwX log/
chown -R git tmp/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/sockets/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX  public/uploads
sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

Then, copy the ‘config/unicorn.rb.example’ file to ‘config/unicorn.rb’. Edit the ‘config/unicorn.rb’ file and set the number of workers to match the number of cores on your CentOS VPS.

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H nano config/unicorn.rb

Please note, ‘unicorn.rb’ and ‘gitlab.yml’ should contain the same information.

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H cp config/resque.yml.example config/resque.yml

Now, copy ‘config/database.yml.mysql’ to ‘config/database.yml’ and edit the file. Please note that you will need to change the secure password with your ‘PaSsWoRd’ value.

sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H nano config/database.yml
sudo -u git -H chmod o-rwx config/database.yml

Install Bundler, gems, GitLab shell and initialize the database.

gem install bundler
cd /home/git/gitlab
sudo -u git -H bundle install --deployment --without development test postgres aws
sudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
restorecon -Rv /home/git/.ssh
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=YourPassword

Please change ‘YourPassword’ with your password. Also, you can review and modify the ‘config.yml’ file.

sudo -u git -H nano /home/git/gitlab-shell/config.yml

Step 8: Install init script

We are approaching the end of this tutorial. It is now time to install the init script. You can use the following commands:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

wget -O /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab

Set the logrotate, check the status, compile the assets and then start the GitLab:

cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
service gitlab start

Step 9: Configure Nginx

OK, it is time to configure Nginx on your server and generate an SSL.

get -O /etc/nginx/conf.d/gitlab.conf
mkdir /etc/nginx/ssl
cd /etc/nginx/ssl/
openssl genrsa -des3 -out gitlab.key 1024
openssl req -new -key gitlab.key -out gitlab.csr
cp gitlab.key
openssl rsa -in -out gitlab.key
openssl x509 -req -days 365 -in gitlab.csr -signkey gitlab.key -out gitlab.crt

Edit the ‘/etc/nginx/conf.d/gitlab.conf’ file to match your FQDN and your SSL path. Also, you will need to comment the following lines:

#  listen [::]:80 default_server;
#  listen [::]:443 ssl default_server;

Finally, run the following commands:

usermod -a -G git nginx
chmod g+rx /home/git/
service nginx start
chkconfig gitlab on
chkconfig nginx on
chkconfig redis on

That’s it. If you followed closely every single step of this tutorial, you should be able to access your newly installed GitLab using your domain name or your CentOS VPS IP address. For example, if your IP address is you need to enter .

installing gitlab on centos 7Of course, you don’t have to Install GitLab on CentOS 7, if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to install GitLab for you. They are available 24×7 and will take care of your request immediately. You can also check our guide on How to Install GitLab on Ubuntu 18.04.

PS. If you liked this post, on how to install GitLab on CentOS 7, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “How to Install GitLab on CentOS 7”

Leave a Comment