How to install SonarQube on Ubuntu 22.04

SonarQube is a source code analyzer that supports many languages. It has a web interface that you can access from a modern web browser to use it.

Fortunately, SonarQube is open source and has integration with Jenkins or Azure for a more fluid DevOps process.

The source code can be integrated via GitHub or GitLab without any problem and allows developers to use it without too many limitations. However, you can purchase some of its services.

Install SonarQube on Ubuntu 22.04

Although the process is simple, there are a few steps involved. Before you start, connect via SSH and update the server.

sudo apt update
sudo apt upgrade

Then install some packages needed to complete the process.

sudo apt install wget apt-transport-https gnupg2 software-properties-common unzip

Now you can continue.

Install Java on Ubuntu 22.04

The next step is to install Java because SonarQube is created with this language. Therefore, to install Java, simply run the following command

sudo apt install openjdk-11-jdk

At the end of the process, you can check the Java version with this command:

java -version

Sample Output:

openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Install PostgreSQL on Ubuntu 22.04

SonarQube requires PostgreSQL as a database driver. So, you have to install it and create a new user and database.

First, install PostgreSQL with this command:

sudo apt install postgresql postgresql-contrib

Then, enable and start it.

sudo systemctl enable postgresql
sudo systemctl start postgresql

Avoid issues by checking if the service is running well.

sudo systemctl status postgresql

Sample Output:

● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2022-10-15 15:13:59 UTC; 13s ago
Main PID: 6023 (code=exited, status=0/SUCCESS)
CPU: 3ms
Oct 15 15:13:59 imaginelinux systemd[1]: Starting PostgreSQL RDBMS…
Oct 15 15:13:59 imaginelinux systemd[1]: Finished PostgreSQL RDBMS.

With PostgreSQL installed, the next step is to access the console, to create the new user and database.

sudo -u postgres psql

Inside the console, you can now create the user


Replace pass with a stronger password. Now create the new database and make it belong to the user you just created.

CREATE DATABASE sonarqube OWNER sonarqube;

Again, you can replace sonarqube with the database name of your choice.

Assign appropriate permissions to the new database:


You can exit now.


Install SonarQube on Ubuntu 22.04

First create a new system user for SonarQube.

sudo useradd -b /opt/sonarqube -s /bin/bash sonarqube

Then, modify some system parameters to adjust it to SonarQube

sudo nano /etc/sysctl.conf

And set these values. If they are not there, then add them at the end of the file:


Save the changes and close the editor. To apply the changes, run

sudo sysctl --system

Now download SonarQube


The command may change depending on the latest version of SonarQube. Check first before venturing.

Unzip the file:


Move the folder to the /opt/ directory where the sonarqube user’s home has been set up

sudo mv sonarqube- /opt/sonarqube

Make that folder belong to the created user.

sudo chown -R sonarqube:sonarqube /opt/sonarqube

Now it is time to configure it a little bit.

Configuring SonarQube before using it

The configuration file is /opt/sonarqube/conf/ where all SonarQube options reside.

Edit it

sudo nano /opt/sonarqube/conf/

The first thing to do is to configure the database connection. At the end of the file you can add these lines:


You have to adapt it to the values you have set.

Now with the help of your text editor, uncomment each of these lines. -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError

The nano editor has a key combination that can help you search for each directive. This combination is CTRL + W and enter the search criteria.

Save the changes and close the editor.

Then it is convenient to create a configuration file to handle SonarQube as a system service

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

And add the following content

Description=SonarQube service

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


Save the changes and to apply them, run

sudo systemctl daemon-reload

Start the service:

sudo systemctl start sonarqube.service

Enable it to start with the system:

sudo systemctl enable sonarqube.service

Verify that everything is OK:

systemctl status sonarqube.service
SonarQube Status
SonarQube Status

Access to the SonarQube web interface

Now, open your web browser and access http://yourserver:9000 and you will see this screen indicating that SonarQube is running

SonarQube web interface
SonarQube web interface

Then log in with the default credentials admin/admin.

Login page
Login page

You will be prompted to change the password, and finally, you will see the main SonarQube screen.

SonarQube running on Ubuntu 22.04
SonarQube running on Ubuntu 22.04


SonarQube is a tool with which you can audit the source code of your application. The installation is simple, although it takes a series of previous steps.

I hope you liked this post, and you can share it with all your friends.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top