RVM + GitLab on Debian

I needed to install my own GitLab on my server for my personal projects, so I don’t have to use GitHub and pay for it. This will require some work, but in the end you will save some money.

Before proceeding lets install some prerequisites.

apt-get install nginx pwgen openssh-server openssh-client sudo git-core build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev

Lets install RVM first before proceeding with installation of GitLab. I always install RVM as a global installation as I can use it with other users in the systems if necessary.

curl -sSL https://get.rvm.io | sudo bash -s stable

At the time of writing this article the latest version of GitLab is version 7. And the required version of ruby is 2.1.2 according to the requirements, so let’s install ruby

rvm install ruby-2.1.2
gem install bundler

Before continuing we need to set up SSH to allow for user environments, because if we don’t we will get the following message whenever we try to do something with git.

/usr/bin/env: ruby: no such file or directory

This is because there is no user environment when doing operations with git.

Let’s edit /etc/ssh/sshd_config and add the following to the end of the file.

PermitUserEnvironment yes

Execute the following commands with root

adduser --disabled-login --gecos 'GitLab' git

I prefer MySQL over PostgreSQL for GitLab so lets install MySQL for use with GitLab

apt-get install mysql-server mysql-client libmysqlclient-dev
mysql_secure_installation

Lets generate a password to use with the system.

pwgen 10 1
iePhee2lae

And then execute the following SQL

CREATE USER 'git'@'localhost' IDENTIFIED BY 'iePhee2lae'; 
SET storage_engine=INNODB;
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 'git'@'localhost';
FLUSH PRIVILEGES;

Before we proceed lets add Git user temporarily to sudoers (/etc/sudoers)

git     ALL=(ALL) NOPASSWD: ALL

Now we need to checkout GitLab, for more up to date installation instructions

su - git
git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-0-stable gitlab
cd /home/git/gitlab
cp config/gitlab.yml.example config/gitlab.yml
cp config/unicorn.rb.example config/unicorn.rb
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
cp config/database.yml.mysql config/database.yml
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
sudo mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo chmod -R u+rwX  public/uploads
git config --global user.name "GitLab"
git config --global user.email "example@example.com"
git config --global core.autocrlf input
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/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
sudo update-rc.d gitlab defaults 21

Now lets edit the configuration files and modify them according to our needs.

Make sure to change “localhost” to the fully-qualified domain name of your host serving GitLab where necessary

editor config/gitlab.yml

Change YOUR_SERVER_FQDN to the fully-qualified domain name of your host serving GitLab.

sudo editor /etc/nginx/sites-available/gitlab

Update username/password in config/database.yml. You only need to adapt the production settings (first part).

editor config/database.yml
chmod o-rwx config/database.yml

Enable cluster mode if you expect to have a high load instance. Ex. change amount of workers to 3 for 2GB RAM server.

editor config/unicorn.rb

Now lets install gitlab shell

cd /home/git/gitlab
bundle install --deployment --without development test postgres aws
bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
bundle exec rake gitlab:setup RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production

Now let’s check if everything was installed correctly

bundle exec rake gitlab:env:info RAILS_ENV=production
bundle exec rake gitlab:check RAILS_ENV=production

Now lets start everything up

sudo service gitlab restart
sudo service nginx restart