RackNerd Billboard Banner

How to install the SonarQube code quality analyzer on Ubuntu Server 20.04

If you’re serious about code quality, SonarQube is a tool you should have in your development pipeline. It helps you catch bugs, security issues, and code smells early—before they cost you time and money.

In this guide, I’ll walk you through installing SonarQube on an Ubuntu 20.04 server. This setup is perfect for small teams, local testing, or CI integration.


Prerequisites

Make sure your server meets the following:

  • Ubuntu Server 20.04
  • At least 2 GB of RAM (4 GB recommended)
  • Java 11 (specifically OpenJDK 11)
  • PostgreSQL 12+

Let’s get to it.


Step 1: Update and Install Dependencies

sudo apt update && sudo apt upgrade -y
sudo apt install unzip wget gnupg2 -y

Step 2: Install Java 11

SonarQube requires Java 11—not newer versions.

sudo apt install openjdk-11-jdk -y
java -version

You should see something like:

openjdk version "11.0.x"

Step 3: Set Up PostgreSQL

SonarQube uses a database to store results. PostgreSQL is the recommended choice.

sudo apt install postgresql postgresql-contrib -y
sudo -u postgres psql

Inside the psql shell, run:

CREATE USER sonar WITH ENCRYPTED PASSWORD 'strongpassword';
CREATE DATABASE sonarqube OWNER sonar;
\q

Replace 'strongpassword' with something secure.


Step 4: Create a SonarQube User

sudo adduser --system --no-create-home --group --disabled-login sonarqube

Step 5: Download and Set Up SonarQube

cd /opt
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.3.0.82913.zip
sudo unzip sonarqube-10.3.0.82913.zip
sudo mv sonarqube-10.3.0.82913 sonarqube
sudo chown -R sonarqube:sonarqube /opt/sonarqube

Step 6: Configure SonarQube

Edit the config file:

sudo nano /opt/sonarqube/conf/sonar.properties

Uncomment and set the following lines:

sonar.jdbc.username=sonar
sonar.jdbc.password=strongpassword
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

Step 7: Create a Systemd Service

sudo nano /etc/systemd/system/sonarqube.service

Paste the following:

[Unit]
Description=SonarQube service
After=network.target

[Service]
Type=forking

ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop

User=sonarqube
Group=sonarqube
Restart=always

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reexec
sudo systemctl enable sonarqube
sudo systemctl start sonarqube

Step 8: Access SonarQube

Open a browser and go to:

https://your-server-ip:9000

Default credentials:

  • Username: admin
  • Password: admin

You’ll be prompted to change the password on first login.


Troubleshooting Tips

  • Make sure port 9000 is open if you’re using a firewall.
  • If SonarQube fails to start, check logs in /opt/sonarqube/logs/.

Final Thoughts

SonarQube gives you a powerful edge in maintaining high code standards. With this setup on Ubuntu 20.04, you can start integrating code analysis into your CI/CD pipelines or simply audit your codebase with more insight.

Got stuck? Drop your question in the comments or reach out—we’re here to help.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
RackNerd Billboard Banner
0
Would love your thoughts, please comment.x
()
x
Copy link