How To Install Gerrit on Ubuntu 24.04 or Newer
Welcome back to the Greenhost.cloud blog! Today, we will guide you through the process of installing Gerrit, an advanced code review tool, on Ubuntu 24.04 or newer. Gerrit is essential for teams looking to enhance their code review workflow, allowing for collaborative development and improved code quality.
What You Will Need
Before we dive into the installation, ensure you have the following:
- A server running Ubuntu 24.04 or newer.
- Sudo privileges on the server.
- Java Development Kit (JDK) installed (Gerrit requires Java 11 or newer).
- A database system (such as MySQL or PostgreSQL) if you plan to use an external database.
Step 1: Update Your System
First, it’s always a good practice to update your package list and upgrade any existing packages. Open your terminal and run:
sudo apt update && sudo apt upgrade -y
Step 2: Install Java
Gerrit requires Java to run. You can install OpenJDK 11 by running the following commands:
sudo apt install openjdk-11-jdk -y
Once the installation is complete, verify the installation by checking the Java version:
java -version
You should see output indicating that Java 11 is installed.
Step 3: Download Gerrit
Next, we need to download the latest Gerrit WAR file. Navigate to the Gerrit Downloads Page to find the latest release. You can also use wget
to download it directly. For example:
wget https://gerrit-releases.storage.googleapis.com/gerrit-3.6.0.war -O gerrit.war
(Note: Replace 3.6.0
with the latest version if a newer one is available.)
Step 4: Create a Gerrit User
For security reasons, it’s best to run Gerrit under its own user account. Create a new user by running:
sudo adduser --system --group --shell /bin/bash --home /var/gerrit gerrit
Now, change the ownership of the Gerrit WAR file:
sudo mv gerrit.war /var/gerrit/gerrit.war
sudo chown gerrit:gerrit /var/gerrit/gerrit.war
Step 5: Set Up Gerrit
To set up Gerrit, switch to the Gerrit user and run the setup command:
sudo -i -u gerrit
java -jar /var/gerrit/gerrit.war init -d /var/gerrit/gerrit_site
During the setup, you will be prompted to answer several questions regarding your instance, such as:
- The site name
- The database type
- The server ID
- The HTTP and SSH ports
Make sure to configure these settings according to your project requirements. If you’re unsure, the default settings are usually a good starting point.
Step 6: Starting Gerrit
After the setup is complete, you can start Gerrit by running:
java -jar /var/gerrit/gerrit.war daemon -d /var/gerrit/gerrit_site
This command will start the Gerrit server. You can now access the Gerrit web interface by visiting http://your-server-ip:8081
in your web browser.
Step 7: Configure Gerrit as a Service (Optional)
To ensure that Gerrit starts automatically on system boot, you can create a systemd service file. Create a new file called gerrit.service
in /etc/systemd/system/
:
sudo nano /etc/systemd/system/gerrit.service
Then, add the following content:
[Unit]
Description=Gerrit Code Review
After=network.target
[Service]
User=gerrit
ExecStart=/usr/bin/java -jar /var/gerrit/gerrit.war daemon -d /var/gerrit/gerrit_site
Restart=always
[Install]
WantedBy=multi-user.target
After saving the file, reload the systemd daemon and enable the Gerrit service:
sudo systemctl daemon-reload
sudo systemctl enable gerrit
sudo systemctl start gerrit
Conclusion
Congratulations! You have successfully installed Gerrit on Ubuntu 24.04 or newer. With Gerrit running, your team can start collaborating more effectively on code reviews, leading to better code quality and faster development cycles.