Installing GitLab on Ubuntu Server 12.04

If you are an avid user of Git like myself, it is likely that you've used a service such as GitHub or BitBucket to share your Git repositories and collaborate with others. I recently stumbled upon GitLab. GitLab is an open source project management, code hosting, and collaboration application, very similar to GitHub, that you can install and run securely on your own server! I won't go into all the details about how awesome this is, as I'm sure if you're here, you're eager to get it up and running. I've written this blog post to work through some common issues that I've had with the installation and to provide a smooth, easy way to get it installed on your server. The following installation will be performed on a freshly installed copy on Ubuntu Server 12.04.

Requirements

The officially supported operating systems for GitLab are Ubuntu Linux and Debian/GNU Linux, although it should work on many others. I've installed this with pretty much the same results on Debian 6 and Ubuntu Server.

A processor with 4 cores is recommended, but if you won't have a lot of users, 2 cores should be sufficient.

The following are the memory requirements:

768MB is the minimal memory size and supports up to 100 users

1GB is the recommended memory size and supports up to 1,000 users

1.5GB supports up to 10,000 users

Installing Required Packages

The first step when booting up your install is to set a root password and update the machine.

You can then exit the root shell by typing exit. Next you'll want to ensure you have the proper Python installation (which comes by default with Ubuntu Server), and install the python-docutils to support reStructuredText markdown.

Setting Up the Git User

The simplest part of the installation is setting up the user to manage the application. Run the following command:

$ sudo adduser --disabled-login --gecos 'GitLab' git```
### Setting Up the Database
The next step is to set up the database. GitLab recommends using [MySQL](https://www.mysql.com/), which we will be using here.
> Note: If you'd like to use [PostgreSQL](http://www.postgresql.org/), see this [link](https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/databases.md#postgresql).
Install the database and set up the root password.
```bash
$ sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

Then login to MySQL server with your password and create the database and user.

Note: Make sure that you do not type the mysql> prompt, and that you replace the password with one of your own.

Now you'll want to configure the database. Rename the database.yml file and edit the file with the proper username and password that you created for the MySQL connection. The username should be gitlab and whatever password you specified.

Finishing Up

You should now navigate in your browser to the URL of your GitLab server. If your server does not yet have an FQDN, you can get this by running the ifconfig command on your server. If all went well, you should be greeted with the GitLab login page! You can then proceed to login with the default credentials:

Note

On each installation I've performed with GitLab I was unable to push to the remote repository via SSH. Every time I tried, the following error occurred:

$ git push -u origin master/usr/local/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT)
from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /usr/local/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /usr/local/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /usr/local/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /usr/local/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/git/gitlab-shell/lib/gitlab_net.rb:62:in `get'
from /home/git/gitlab-shell/lib/gitlab_net.rb:17:in `allowed?'
from /home/git/gitlab-shell/lib/gitlab_shell.rb:60:in `validate_access'
from /home/git/gitlab-shell/lib/gitlab_shell.rb:23:in `exec'
from /home/git/gitlab-shell/bin/gitlab-shell:16:in `main'
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

This happened when I my SSH keys were added and everything was set up properly. After much research, I finally resolved the issue by editing the /etc/hosts file and replacing the following line: