How To Install SonarQube on Ubuntu 22.04

By Jennifer Mathew

Updated on May 24, 2024

In this tutorial, we'll discuss about how to  install SonarQube on Ubuntu 22.04. SonarQube, an open-source platform for continuous inspection of code quality.

SonarQube is an open-source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities. This tutorial will guide you through the steps to install and configure SonarQube Community Edition on a Linux system.

Install SonarQube on Ubuntu Community Edition


  • A fresh Ubuntu 22.04 dedicated server
  • A user with sudo privileges
  • Java 11 or 17 installed (SonarQube requires a specific version of Java)

For this tutorial, we have used cloud server with the configuration of 2vCPU, 4GB RAM, 80GB SSD. It should have at least 2GB of RAM 1 CPU core and 30GB free space.

Step 1: Update the System

First, ensure your system is up-to-date:

sudo apt update
sudo apt upgrade -y

Step 2: Install Java

SonarQube requires Java 11 or 17. We will install OpenJDK 17.

sudo apt install openjdk-17-jdk -y

Verify the installation:

java -version

Step 3: Install PostgreSQL

SonarQube uses PostgreSQL as its database. Install PostgreSQL 15. Execute set of following commands:

sudo apt install curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/ --fail
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/] $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Update and install PostgreSQL 15

sudo apt update
sudo apt install postgresql-15 -y

Now, let's configure PostgreSQL

Switch to the PostgreSQL user:

sudo -i -u postgres

Create a new user and database for SonarQube:

createuser sonar
createdb sonar -O sonar

Inside the PostgreSQL shell, set a password for the sonar user:


Exit the PostgreSQL user:


Step 4: Install SonarQube

Download the latest SonarQube version:


Extract the SonarQube package:

sudo mv sonarqube- /opt/sonarqube

Create a SonarQube user:

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

Change ownership of the SonarQube directory:

sudo chown -R sonarqube:sonarqube /opt/sonarqube

Now, let's configure SonarQube

Edit the SonarQube configuration file:

sudo nano /opt/sonarqube/conf/

Uncomment and set the following properties:


Step 5: Create a Systemd Service File

Create a new service file for SonarQube:

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

Add the following content:

Description=SonarQube service


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




Reload the systemd daemon and start SonarQube:

sudo systemctl daemon-reload
sudo systemctl start sonarqube
sudo systemctl enable sonarqube

Step 6: File Descriptors

Check the current limit:

ulimit -n

It should be at least 65536. To increase it, add the following to /etc/security/limits.conf:

sudo nano /etc/security/limits.conf

Add the following lines:

sonarqube   -   nofile   65536
sonarqube   -   nproc    4096

Check and set the virtual memory limit:

sudo sysctl -w vm.max_map_count=262144

To make this change permanent, add it to /etc/sysctl.conf:

sudo nano /etc/sysctl.conf

Add the following line:


Apply the changes:

sudo sysctl -p

Step 7: Configure Firewall

We need to add ports in firewall.

ufw allow 9000/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload

Step 8: Install and Configure Nginx

Install Nginx:

sudo apt install nginx -y

Create a new Nginx configuration file for SonarQube:

sudo nano /etc/nginx/sites-available/

Note: Replace with your domain name.

Add the following content:

server {
    listen 80;

    access_log /var/log/nginx/sonarqube.access.log;
    error_log /var/log/nginx/sonarqube.error.log;

    location / {
        proxy_pass http://localhost:9000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

Note: Replace with your domain name.

Enable the new configuration:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart Nginx:

sudo nginx -t
sudo systemctl restart nginx

Step 8: Configure HTTPS

For added security, consider configuring HTTPS for your Grafana instance. You'll need an SSL certificate for your domain. You can obtain a free SSL certificate from Let's Encrypt using Certbot.

sudo apt install certbot python3-certbot-nginx -y

Then run the following command to obtain and install the SSL certificate:

sudo certbot --nginx -d

Note: Replace with your domain name.

Follow the prompts to configure HTTPS with Certbot.

Step 9: Access SonarQube

Open your web browser and go to https://your_domain_or_ip. You should see the SonarQube login page. The default credentials are:

Username: admin
Password: admin

Upon first login, you will be prompted to change the default password.


In this tutorial, we have seen how to  install SonarQube on Ubuntu 22.04 with PostgreSQL 15, Nginx, secured with Let's Encrypt SSL certificate. SonarQube is now ready to analyze the code quality of your projects. Make sure to secure your SonarQube instance and regularly back up your PostgreSQL database.