Ryan Wersal

Installing GitLab on Ubuntu Server

UPDATE 01/23/2012: This post continues to get a large amount of traffic and, unfortunately, is very out of date! I would update this post to bring it up to date, but it turns out that is completely unnecessary. The fine folks behind GitLab have added impressive install scripts (and even more impressive documentation!) for installation of GitLab on an Ubuntu box. I recently utilized them to get a v2.0 GitLab install up and running and the experience was painless. This even included getting it running on nginx, and more importantly, port 80. I will leave the body of this post here for posterity’s sake, but it is no longer any sort of authoritative source.


Installing GitLab has turned out to be quite a chore and, as a result, I wanted to provide a solid tutorial on how to get it all functioning correctly. This post will only cover what the installation instructions do: getting it to work with the built in server. I plan to do another post on how to get it running on Apache.

Install Ruby 1.9.2, RubyGems, and Rails

The instructions for this step are pretty solid, but I was never able to get the checkinstall portion to work. Luckily, I found something that works. You will likely note the use of “aptitude” instead of “apt-get”; please use “aptitude”. It appears to have packages “apt-get” does not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#Download dependencies
sudo aptitude install git-core curl gcc libxml2-dev libxslt-dev sqlite3 \
  libsqlite3-dev libcurl4-openssl-dev libreadline5-dev libc6-dev libssl-dev \ 
  libmysql++-dev make build-essential zlib1g-dev python-setuptools

#Download tar of ruby 1.9.2
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
tar zxvf ruby-1.9.2-p290.tar.gz

#Configure, make, and install
cd ruby-1.9.2-p290
./configure
make
sudo make install

#Update RubyGems
sudo gem update --system

#Install Rails
sudo gem install rails

Install GitLab

1
2
3
4
5
6
7
8
#Clone GitLab via Git
git clone git://github.com/gitlabhq/gitlabhq.git
cd gitlabhq

#Install dependencies
sudo easy_install pygments
sudo gem install bundler
bundle

Uninitialized constant Rake::DSL?

This was an error I hit every single time I installed GitLab (it took several attempts). For whatever reason, the “rake db:setup” call yielded an error of “unititialized constant Rake::DSL”. Thanks to some Googling and a particularly useful StackOverflow question, I found a solution: open the Rakefile at the root of gitlabhq and add these two lines to the file just beneath the comments:

1
2
require 'rake/dsl_definition'
require 'rake'

Setup the database

With that issue resolved, you should be able to invoke the commands to setup the database now:

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

Install Gitosis

The user we add in this step will be the user that gitosis runs under. During the keygen step, simply accept the defaults for all fields.

1
2
3
4
5
6
7
8
9
10
sudo aptitude install gitosis

#Add git user
sudo adduser --system --shell /bin/sh --gecos 'git version control' \
  --group --disabled-password --home /home/git git

#Create ssh key and setup gitosis
ssh-keygen -t rsa
sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

Start the Server

1
rails s -e production

Test your installation

If all went well, you should be able to connect to the server at: http://localhost:3000/. The default login info is as follows:

1
2
Email:    admin@local.host
Password: 5iveL!fe

Be aware that upon creation of your first git repo or when you add your first public key, you will have to type “yes” on the server to confirm the ssh key that you made earlier.

Good luck with your new GitLab install!