Posted by Peter

This is old version of my tutorial. Most recent version can be found here

GitLab is a wonderful piece of software made by these guys and I’d like to try and install it on Fedora 16 system, as it is most recent Fedora OS at the time I am writing this. I will base my tutorial on on found hereby Déja. Also on my way to successful install I’ve stumbled upon this description, so I might have gain some experience from it too.

GitLab is Ruby on Rails application and it takes some experience to get it all working because of many, many, many dependencies and packages it needs. It’s nothing like simple PHP on Apache installation. But it works and it’s worth it, I assure you :)

Let’s begin!

(by the way: I perform all as root user - again: test environment)

small edit: For people who only want this to work and not necessarily wish to know how and why, I have prepared easy installation scripts in here

  1. First of all: I am working on virtual machine with brand new and fresh Fedora 16 installed. Minimal installation, just to make sure nothing messes with GitLab. Consider this a test environment.

  2. Once you have your OS ready, update it with yum update and also install some packages you will need on the way:

    1
    
    yum install make openssh-clients gcc libxml2 libxml2-devel libxslt libxslt-devel python-devel
    
  3. Check what version of ruby is available via yum. GitLab needs at least version 1.9.2

    1
    
      yum info ruby
    

    on mine it says that the only available version for me is 1.8.7.35 so I have to get it somewhere else.

  4. Method #1

I will do as it says here. I have tried it before and it works flawlessly. With one or two catches of course ;) Mentioned catches and tips:

  • you need wget, if you don’t have it already use yum install -y wget

  • other needed packages (plus few dependencies) can be obtained by typing:

    1
    
      yum install -y readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel db4-devel byacc
    
  • if you are using virtual machine, like me, you can first make a snapshot of it, then build ruby RPM package, copy it to you host machine (or network share or whatever place outside virtual machine) and then go back in time to you snapshot. Voila! Clean system ready for further installing GitLab. All you need to do is install earlier created ruby RPM. Anyway this is what I’m gonna do today. Keep it clean.

  • last step - your RPM will end up somewhere in ~/rpmbuilds/RPMS directory. It will reside in folder named after your system architecture, in my case: i386

    And here is how:

    1
    2
    3
    4
    5
    6
    7
    8
    
        yum install -y rpm-build rpmdevtools
        rpmdev-setuptree
        cd ~/rpmbuild/SOURCES
        wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
        cd ~/rpmbuild/SPECS
        curl https://raw.github.com/imeyer/ruby-1.9.2-rpm/master/ruby19.spec > ruby19.spec
        rpmbuild -bb ruby19.spec
        rpm -Uvh ~/rpmbuild/RPMS/x86_64/ruby-1.9.2p290-2.ruby-1.9.2p290-2.i386.rpm
    

    I took my VM about 4 minutes to compile and prepare RPM. Not so bad.

    Now I go back in time in my VM and install newly created RPM with

    1
    
        rpm -Uvh ruby-1.9.2p290-2.fc16.i386.rpm
    
  1. Method #2. ( I prefer this one so far)

    EDIT: I have switched to ruby 1.9.3p0 - it works and starts a lot faster, you can use it instead of 1.9.2-p290 in this guide.

    I will use RVM, which stands for Ruby Version Manager - brilliant tool, which you can use to install and manage your Ruby with ease. Let’s check it out, shall we?

    1
    2
    3
    4
    5
    6
    7
    
    sudo bash -s stable < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
    
    source /etc/profile.d/rvm.sh
    
    rvm install ruby-1.9.2-p290
    
    rvm use ruby-1.9.2-p290 --default
    

    Done. Just like that we have operational Ruby 1.9.2-p290. No RPMs, no going back in time.. nice, huh? :)

  2. Good. Small (nice) surprise: our RPM installed ruby gems for us, so now we only have to get rails gem.

    first, just to make sure everything is up to date, execute:

    1
    
    gem update --system
    

    now install rails with:

    1
    
    gem install rails
    
  3. Now we will install apache2 as a webserver and Passenger for ruby apps deployment. I know that most GitLab tutorials use nginx but I really like apache ;)

    1
    
      yum install -y httpd
    
    1
    
      gem install passenger
    

    as I mentioned: I use apache, so I will need passenger module for it:

    first some required packages:

    1
    
      yum install gcc-c++ curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel
    

    an then use

    1
    
      passenger-install-apache2-module
    

    in order to install it.it gives you 2 information on how to proceed with apache configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
*  add following lines to ```/etc/httpd/conf/httpd.conf``` (at the very end):

  ```bash
  LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
  PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
  PassengerRuby /usr/bin/ruby
  ```

*  and then create file named ```default.conf``` (or ```gitlab.conf```, or something other you fancy) in ```/etc/httpd/conf.d/``` containing these lines (remember to change to fit your environment):

  ```bash
  <VirtualHost *:80>
  ServerName www.yourhost.com
  DocumentRoot /somewhere/public
  <Directory /somewhere/public>
  AllowOverride all
  Options -MultiViews
  </Directory>
  </VirtualHost>
  ```

  (don't worry, we'll come back to this one later)
  1. Now it is time for gitolite. I won’t use gitosis because it is not actively developed any more and I found that new GitLab works better with gitolite.install it with

    1
    
      yum install -y gitolite
    

    now, wasn’t that quick? :)

  2. Now we will need to create new gitolite server configuration and in order to do that we have to generate SSH key-pair. But first things first.

    To get us started su into gitolite user with

    1
    
      su - gitolite
    

    now try to log into localhost via SSH -> it’s small thing which will make our life easier in the future.

    1
    
      ssh localhost
    

    Just make it add localhost to list of known host - no need to actually authenticate. SSH created for us ~/.ssh directory. That’s nice.SSH key generation is as easy as:

    1
    
      ssh-keygen -t rsa
    

    use default path for saving key-pair (/var/lib/gitolite/.ssh/id_rsa) and no paraphrase. Test environment. Just a reminder.as for initialization of gitolite repository:

    1
    
      gl-setup .ssh/id_rsa.pub
    

    next hit ENTER and edit will open, change value of

    1
    
      REPO_UMASK to 0007
    

    as mentioned hereLook like we are done here. Exit gitolite user shell and return to being almighty root himself ;)

  3. OK, time for next requirements: python Pip, I will go with method from original post and NOT use yum for that.

    1
    
      curl http://python-distribute.org/distribute_setup.py | python
    

    and then

    1
    
      easy_install pip
    
  4. Database. We need it. We have it already - it was installed on the way as a dependency. Just to make sure check if you have SQLite at list version 3.6 with: yum info sqlite

    I have 3.7.7.1. All we need is SQLite development package, get it with:

    1
    
        yum install sqlite-devel
    
  5. And now the main event! GitLabHQ! I like install web apps in /var/www so we will go there and git clone GitLab:

    1
    2
    3
    4
    5
    
      cd /var/www
    
      git clone git://github.com/gitlabhq/gitlabhq.git
    
      cd gitlabhq/
    

    we need to use pip to install some python dependencies:

    1
    
        pip install pygments
    

    and bundler gem so it can later on do most of the work for us:

    1
    
        gem install bundler
    

    finally (remember to be in GitLab directory):

    1
    
        bundle install
    

    (go get yourself a coffee or other treat - it takes w while)

  6. DB setup:

    EDIT: For GitLab version 2.1 install Redis - without it rake will fail.:

    1
    2
    
      yum install redis libicu-devel
      service redis start
    

    And now database setup and import:

    1
    2
    
      RAILS_ENV=production rake db:setup
      RAILS_ENV=production rake db:seed_fu
    

    TIP: if you get errors here, check if you don’t have 2 versions of rake installed (I had somehow): 0.8.7 and 0.9.2. If you do, remove older with: gem uninstall rake

    and choose appropriate version. If you still have problems try: gem install rake

    -> don’t know why, but if it installs again same version of rake, it works.

  7. Apache virtual host configuration should look something like this (I told you, we will get back to that):file: /etc/httpd/conf.d/gitlab.conf

    1
    2
    3
    4
    5
    6
    7
    8
    
      <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /var/www/gitlabhq/public
      <Directory /var/www/gitlabhq/public>
      AllowOverride all
      Options -MultiViews
      </Directory>
      </VirtualHost>
    
  8. set correct settings in /var/www/gitlabhq/config/gitlab.yml

    in my case:# Git Hosting configuration

    1
    2
    3
    4
    5
    6
    7
    
      git_host:
      system: gitolite
      admin_uri: gitolite@localhost:gitolite-admin
      base_path: /var/lib/gitolite/repositories/
      host: localhost
      git_user: gitolite
      # port: 22
    
  9. enable apache user, co you can su into this account:

    1
    
      usermod -s /bin/bash -d /var/www/ apache
    

    also give him permissions to his own home directory with:

    1
    
      chown -R apache:apache /var/www/
    

    (I know this kinda overrides last chown command…)

  10. do: su - apache && ssh localhost(same thing as in step 8. with knowhosts file. ) exit apache’s shell and as root copy idrsa private key from /var/lib/gitolite/.ssh/ to /var/www/.ssh/ and make apache it’s owner with:

    1
    
        cp -f /var/lib/gitolite/.ssh/id_rsa /var/www/.ssh/ && chown apache:apache /var/www/.ssh/id_rsa && chmod 600 /var/www/.ssh/id_rsa
    
  11. add apache user to gitolite group with:

    1
    
      usermod -a -G gitolite apache
    
  12. check if repositories directory has correct permissions, it should be 770. You can set it with chmod 770 /var/lib/gitolite/repositories/

  13. double check your firewall (for example iptables) if it allows connections on port 80 to your server.

  14. start apache server with: service httpd start

  15. Now it all should work. Fingers crossed.. go to http://www.yourhost.com

  16. Now you should be able to log in using these credentials:

    user: [email protected]

    pass: 5iveL!fe

    and you’re in :) It wasn’t so hard, wasn’t it? ;)

Troubleshooting

  1. I get error 500 when I enter particular project and try to get into it’s “Admin” section. Don’t know how to fix it yet.To fix it, check if repositories directory has correct permissions, it should be 770. You can set it with

    1
    
      chmod 770 /var/lib/gitolite/repositories/
    
  2. If Passenger insists, that we don’t have or he can’t see grit library (gem actually, as far as I know) even though we have it.

    https://github.com/gitlabhq/grit.git (at master) is not checked out. Please run bundle install (Bundler::GitError)

    I didn’t have gem grit installed, do:

    1
    
    gem install grit
    

    also it won’t hurt to update all gems with:

    1
    
    gem update
    

    Only resolution to this problem I have found is to run bundle again as a user who runs apache server: apache.Su into apache account with su - apache

    and try: gem install grit

    you’ll get error: You don't have write permissions into the /usr/lib/ruby/gems/1.9.1 directory.

    As root change it’s ownership to apache user with:

    1
    
    chown apache:root -R /usr/lib/ruby/gems
    

    I know that is not great resolution but it worked for me. If you’ll happen to know better way - please let me know, so I can update this tutorial and my knowledge of course ;)

    Edit

    I found another solution (instead of changing permissions): after first

    bundle install

    edit Gemfile and in lines containing “git:” remove everything after first comma, for example:

    gem "grit", :git => "https://github.com/gitlabhq/grit.git"

    should be

    1
    
      gem "grit"
    

    then do again

    bundle install

    and now passenger shouldn’t complain any more.