Tutorial

How To Install Gerrit on an Ubuntu Cloud Server

Published on June 18, 2013
How To Install Gerrit on an Ubuntu Cloud Server

What the highlighting Means

The lines that the user needs to enter or customize will be highlighted in this tutorial! The rest should mostly be copy-and-pastable.

About Gerrit

Gerrit is a code review tool that allows developers to push code to an authoritative repository where it can be looked over before being pushed into the production. The application is very synchronized with git. Because of its utility, there are a variety of ways to build out a strong and secure gerrit platform, including using MySQL or Postgres instead of the default H2 database, configuring gerrit behind another webserver, and customizing the authentication used to login (the default is open_id).

This tutorial will cover a simple gerrit explanation that allows you to just get gerrit up and running as quickly as possible on a cloud server.

Step One—Git

Before beginning with installing gerrit, we need to be sure that git is installed and set up on our server. If, by any chance, it is not already installed on your cloud server, you can get it quickly through apt-get:

sudo apt-get install git

Step Two—Java

In order to work, gerrit requires Java to be installed on the server.

You can check if Java is already installed easily:

java -version

If it’s not, you can install it, once again, through apt get:

sudo apt-get install default-jdk

Step Three—Installing Gerrit

Once Git and Java have been downloaded and installed on our server, we can start to set up gerrit. The program itself is hosted on the Google Code site, but the latest version is 2.7

Download the required war file:

wget https://gerrit.googlecode.com/files/gerrit-2.7-rc1.war

Once downloaded, we need to initialize gerrit. You can do so with the command below.

However, should you be content with the default settings, you can have all of them selected at once with the --batch option. Additionally, while by default, gerrit is set up within the user’s home directory, you can set up the specific directory where the files should be placed by adding a –d to the line.

java -jar gerrit-2.7-rc1.war init --batch -d ~/gerrit_example

If this process is done automatically, the canonical URL, where gerrit can be accessed, will simply be localhost

Step Four—Access Your Gerrit Installation

Once Gerrit has been set up, you can start to access it with your desired user.

Gerrit can be accessed through its canonical URL, visible in the settings and easy to find with the command:

 git config -f ~/gerrit_example/etc/gerrit.config gerrit.canonicalWebUrl

The visible result should be something along the lines of:

http://localhost:8080/

You can change the gerrit settings in the gerrit.config file.

vi  ~/gerrit_example/etc/gerrit.config

Be sure to restart gerrit after making changes:

~/gerrit_example/bin/gerrit.sh restart

If you see localhost in your canonical URL, you should be able to access gerrit through the server’s IP address.

Upon first login, the page should look like this:

With an OpenID, you should be able to create an account on the server. By default, the first account to be registered becomes the superadmin on the site.

Step Five—Create a New User

When you begin to create a new user, the screen looks like this:

There are several sections that must be filled in. These include Email, Username, and user's SSH key.

If you enter a new email (rather than the default that populates the field), you can manually add it. However, you will need to confirm it before you can register the user under that email.

There is a large field on that page for the user’s SSH key. You should check if you already have an SSH key set up, and, if so, paste in the public key. If you have an SSH key, you should not create a new one

If you do not have an SSH Key, you can follow the instructions on the site to generate one.

You can check double that your SSH key is working by logging into the gerrit through the Command Line with the username that you created. By default gerrit runs on port 29418.

ssh username@localhost -p 29418

You should see the following text after a successful login.

ssh username@localhost -p 29418
The authenticity of host '[localhost]:29418 ([cannonicalURL]:29418)' can't be established.
RSA key fingerprint is 19:73:55:9d:63:8b:c5:6f:cb:ee:4c:51:b4:e6:69:e4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ocalhost]:29418' (RSA) to the list of known hosts.

  ****    Welcome to Gerrit Code Review    ****

  Hi, you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://username @localhost:29418/REPOSITORY_NAME.git

Connection to cannonicalURL closed.
By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
5 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

fatal:Gerrit Code Review requires Java 7 or later my java of version is 1.6 why?

Very nice article. Anyway, i was wondering if you have a tutorial for Gerrit 2 but for Centos 7 server?

Thanks.

Edit: I found this good article on how to install Gerrit 2 . I hope someone will find this very useful.

okey thanks

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
September 2, 2013

@mehmetsanok: <pre>rm -r ~/gerrit_example</pre> Reboot your droplet once you run that.

how we can remove it from server ?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel