SonarQube is an open-source platform for continuous code quality inspection, detecting bugs, vulnerabilities, and code smells. This guide installs SonarQube on Ubuntu 24.04 LTS with PostgreSQL 16.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Minimum 2 GB RAM (4 GB recommended)
  • Java 21 installed
  • PostgreSQL 16 installed
  • A user with sudo privileges

Step 1 – Configure System Parameters

SonarQube requires specific kernel settings:

sudo sysctl -w vm.max_map_count=524288
sudo sysctl -w fs.file-max=131072
echo 'vm.max_map_count=524288
fs.file-max=131072' | sudo tee -a /etc/sysctl.conf

Increase file descriptor limits:

echo '* soft nofile 131072
* hard nofile 131072' | sudo tee -a /etc/security/limits.conf

Step 2 – Create a PostgreSQL Database

Create the SonarQube database:

sudo -u postgres psql
CREATE USER sonar WITH ENCRYPTED PASSWORD 'SonarPass123!';
CREATE DATABASE sonarqube OWNER sonar;
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonar;
q

Step 3 – Download SonarQube

Download and extract:

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

Step 4 – Create a SonarQube User

SonarQube cannot run as root:

sudo useradd -r -s /bin/false sonarqube
sudo chown -R sonarqube:sonarqube /opt/sonarqube

Step 5 – Configure SonarQube

Edit the properties file:

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

Set database credentials:

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

Step 6 – Create a systemd Service

Create the service file:

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

Add:

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

[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:

sudo systemctl enable sonarqube
sudo systemctl start sonarqube

Step 7 – Access SonarQube

Visit http://your_server_ip:9000. Default credentials are admin/admin — change them immediately.

Conclusion

SonarQube is now running on Ubuntu 24.04 LTS. Integrate it with your Jenkins or GitLab CI pipeline using the SonarScanner to automatically analyse code quality on every commit.