Installing GitBucket with PostgreSQL and Tomcat on CentOS 7


When it comes to on-premises Git hosting, GitBucket is definitely my current favorite. It has monthly updates, LDAP authentication, email notifications, forks, wikis, issues, pull requests, inline commenting, public and private repos, plugins, skins, protected branches, HTTP and SSH transports… you name it, man.

I’ve already sent a few patches to its current maintainer, Naoki Takezoe, he and his team are very responsive and helpful, too. What more could you ask for? Install it already!


In this step we add the official PostgreSQL repo to have the latest version, install it, configure authentication, then also set up a user and a database for use by GitBucket.

Find the URL for the current CentOS 7 PostgreSQL RPM, then install it. E.g.:

yum install

Then open /etc/yum.repos.d/CentOS-Base.repo and add to the base and updates sections:


Install the server:

yum install postgresql10-server

Initialize Postgres:

/usr/pgsql-10/bin/postgresql10-setup initdb

Set up authentication via /var/lib/pgsql/10/data/pg_hba.conf. Use md5 to have password authentication on the local interfaces instead of ident:

host    all             all               md5
host    all             all             ::1/128                 md5

Finally, start and enable the engine:

systemctl start postgresql-10.service
systemctl enable postgresql-10.service

Then create the gitbucket user and database:

sudo -u postgres sh -c 'createuser --username=postgres --no-createrole --no-createdb --no-inherit --encrypted --login --pwprompt --no-superuser gitbucket'
sudo -u postgres sh -c 'createdb --encoding=UTF-8 --owner=gitbucket gitbucket'

There you go, Postgres is up and running.


Now let’s install and configure Tomcat, which will be the engine hosting our GitBucket instance.

yum install tomcat
systemctl enable tomcat.service

Now speed up random number generation. This can actually save you minutes every time Tomcat is restarted. Open /etc/tomcat/tomcat.conf and add the following line:


Also edit /etc/tomcat/server.xml to have an ending similar to this:

<Context path="" docBase="gitbucket">
        <!-- Default set of monitored resources -->


Time to get GitBucket itself. Make sure to change the version number to the latest:

export GITBUCKET_VERSION='4.20.0'
cp gitbucket.war /var/lib/tomcat/webapps/gitbucket.war
chown root.tomcat /var/lib/tomcat/webapps/gitbucket.war
restorecon -v /var/lib/tomcat/webapps/gitbucket.war
ln -s /usr/share/tomcat/.gitbucket /opt/gitbucket

Make sure SELinux won’t intervene, so install the GitBucket SELinux policy module and also fix file permissions, as explained on the link.

Now test if Tomcat can start GitBucket, then if succeeded, stop Tomcat:

systemctl restart tomcat.service && sleep 2 && tail -f /var/log/tomcat/*
systemctl stop tomcat.service

Now point GitBucket to PostgreSQL, edit /opt/gitbucket/database.conf:

db {
    url = "jdbc:postgresql://localhost/gitbucket"
    user = "gitbucket"
    password = "***"

Then start Tomcat again with systemctl start tomcat, and log in with root/root. Once logged in, the settings should be self-explanatory. Cheers!

Tags: , , , ,