Install SonarQube on Ubuntu 24.04 LTS

In this article, we are going to cover How to install SonarQube on Ubuntu 24.04 LTS.

SonarQube is an open-source platform widely used for continuous inspection of code quality. It provides detailed static code analysis to detect bugs, code smells, and security vulnerabilities in over 20 programming languages. This article walks you through installing the latest version of SonarQube (v25.6) on Ubuntu 24.04, setting up PostgreSQL as its backend database, and configuring it to run as a service. By the end, you’ll have a production-ready code quality analysis tool running

Prerequisites

  • AWS Account with Ubuntu 24.04 LTS EC2 Instance.
  • At least 2 CPU cores and 4 GB of RAM for smooth performance.

Step #1:Set Up Ubuntu EC2 Instance

Update Package Index.

sudo apt update
Install SonarQube on Ubuntu 24.04 LTS 1

Install Java Development Kit version 17, which is the minimum required version for SonarQube 25+.

sudo apt install openjdk-17-jdk -y
Install SonarQube on Ubuntu 24.04 LTS 2

Confirm that Java is installed and displays the current version.

java -version
Install SonarQube on Ubuntu 24.04 LTS 3

Step #2:Configure System Limits

SonarQube uses Elasticsearch, which requires increased system limits. Edit /etc/sysctl.conf.

sudo nano /etc/sysctl.conf
Install SonarQube on Ubuntu 24.04 LTS 4

Add the following at the end.

vm.max_map_count=262144
fs.file-max=65536

These values ensure SonarQube has enough memory and file descriptors.

Install SonarQube on Ubuntu 24.04 LTS 5

Apply the changes.

sudo sysctl --system
Install SonarQube on Ubuntu 24.04 LTS 6

Step #3:Configure Limits for the User

Edit the security limits configuration.

sudo nano /etc/security/limits.conf
Install SonarQube on Ubuntu 24.04 LTS 7

Add these lines at the end.

sonarqube - nofile 65536
sonarqube - nproc 4096

These limits define the maximum number of open files and processes for the SonarQube user.

Install SonarQube on Ubuntu 24.04 LTS 8

Step #4:Install PostgreSQL and Configure the Database

Install PostgreSQL Database.

sudo apt install postgresql postgresql-contrib -y
Install SonarQube on Ubuntu 24.04 LTS 9

Start and enable the PostgreSQL service.

sudo systemctl start postgresql
sudo systemctl enable postgresql
Install SonarQube on Ubuntu 24.04 LTS 10

Verify if its running.

sudo systemctl status postgresql
Install SonarQube on Ubuntu 24.04 LTS 11

Switch to PostgreSQL user.

sudo -i -u postgres
Install SonarQube on Ubuntu 24.04 LTS 12

Open the PostgreSQL shell.

psql
Install SonarQube on Ubuntu 24.04 LTS 13

Now, execute these SQL commands one by one in the psql prompt.

Create a new PostgreSQL user named sonarqube and sets its password to sonar123.

CREATE USER sonarqube WITH ENCRYPTED PASSWORD 'sonar123';

Create a new database named sonarqube and assigns its ownership to the sonarqube user we just created.

CREATE DATABASE sonarqube OWNER sonarqube;

Grant all available privileges on the sonarqube database to the sonarqube user.

GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonarqube;

Revoke all default permissions on the public schema from the public role.

REVOKE ALL ON SCHEMA public FROM public;

Grant the sonarqube user ALL privileges on the public schema within the sonarqube database.

GRANT ALL ON SCHEMA public TO sonarqube;

Connect to the newly created sonarqube database

\c sonarqube;

Set default privileges for any future tables, sequences, and functions created by the sonarqube user within the public schema.

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO sonarqube;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO sonarqube;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO sonarqube;

Exit the PostgreSQL command-line client.

\q
Install SonarQube on Ubuntu 24.04 LTS 14

Exit the postgres user shell, returning to regular Ubuntu user.

exit
Install SonarQube on Ubuntu 24.04 LTS 15

Step #5:Install and Configure SonarQube

Now, we’ll download and configure the SonarQube application itself. Create a new system user and group named sonarqube.

sudo adduser --system --no-create-home --group sonarqube
Install SonarQube on Ubuntu 24.04 LTS 16

Download the latest SonarQube package.

wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-25.6.0.109173.zip
Install SonarQube on Ubuntu 24.04 LTS 17

Install the unzip utility, which is necessary to extract the SonarQube .zip archive.

sudo apt install unzip -y
Install SonarQube on Ubuntu 24.04 LTS 18

Unzip the downloaded SonarQube archive into the /opt/ directory.

sudo unzip sonarqube-25.6.0.109173.zip -d /opt/
Install SonarQube on Ubuntu 24.04 LTS 19

Rename the extracted SonarQube directory from sonarqube-25.6.0.109173 to a simpler /opt/sonarqube.

sudo mv /opt/sonarqube-25.6.0.109173 /opt/sonarqube
Install SonarQube on Ubuntu 24.04 LTS 20

changes the ownership of the /opt/sonarqube directory and all its contents recursively (-R) to the sonarqube user and sonarqube group.

sudo chown -R sonarqube:sonarqube /opt/sonarqube
Install SonarQube on Ubuntu 24.04 LTS 21

Edit the configuration file.

sudo nano /opt/SonarQube/conf/sonar.properties
Install SonarQube on Ubuntu 24.04 LTS 22

Uncomment and set these properties. This connects SonarQube to PostgreSQL and makes it accessible from any IP.

#--- DATABASE
sonar.jdbc.username=sonarqube
sonar.jdbc.password=sonar123

#--- PostgreSQL 13 or greater
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

#--- WEB SERVER
sonar.web.host=0.0.0.0
sonar.web.port=9000
Install SonarQube on Ubuntu 24.04 LTS 23
Install SonarQube on Ubuntu 24.04 LTS 24

Create a new systemd service file.

sudo nano /etc/systemd/system/sonarqube.service
Install SonarQube on Ubuntu 24.04 LTS 25

Paste the following code in it.

[Unit]
Description=SonarQube service
Documentation=https://docs.sonarqube.org/latest/
Requires=postgresql.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=on-failure
LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target
Install SonarQube on Ubuntu 24.04 LTS 26

Reload systemd. Start and enable the service.

sudo systemctl daemon-reload
sudo systemctl enable sonarqube
sudo systemctl start sonarqube
Install SonarQube on Ubuntu 24.04 LTS 27

Verify if its running or not.

sudo systemctl status sonarqube
Install SonarQube on Ubuntu 24.04 LTS 28

Step #6:Access SonarQube Web Interface

Open your browser and go to,

http://<Your-EC2-Public-IP>:9000
Install SonarQube on Ubuntu 24.04 LTS 29

You should be presented with the SonarQube login page. The default administrator credentials are:

  • Username: admin
  • Password: admin
Install SonarQube on Ubuntu 24.04 LTS 30

You will be prompted to change the password on your first login.

Install SonarQube on Ubuntu 24.04 LTS 31

After changing password you will see the SonarQube Home page.

Install SonarQube on Ubuntu 24.04 LTS 32

Conclusion:

You’ve now successfully installed and configured the latest SonarQube on Ubuntu 24.04 with PostgreSQL and systemd support. This setup is optimized for production with proper system tuning, a secure database backend, and managed service control. SonarQube is now ready to help your team continuously analyze and improve code quality. You can now start integrating your projects and setting up quality gates and dashboards

Related Articles:

Automate S3 File Processing with Python and Lambda

Reference:

SonarQube Official Page

Prasad Hole

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap