How to install SonarQube on Ubuntu 20.04 LTS
How to install SonarQube on Ubuntu 20.04 LTS

How To Install SonarQube on Ubuntu 20.04 LTS

On this tutoria, we will learn how to install SonarQube Version 9.0.1 on Ubuntu 20.04 operating system.


When a developer develops an application, there will be various steps that must be passed, one of which is coding. A developer will be very happy when he finds his work error and bug free. One of the efforts to make an application free from errors and bugs is to use tools that can help analyze and provide information on where the error is if it occurs. One of the tools that can be used for this purpose is SonarQube.

SonarQube can analyze a wide range of code in different programming languages through plugins. This guide explains how to install SonarQube on Ubuntu 20.04 LTS. This guide will use SonarQube Community Edition which is free and opersource.

SonarQube Installation on Ubuntu 20.04 LTS


Before we are going to the SonarQueb installation process we have to prepare the environment first as mentioned below :

  • Ubuntu 20.04 System with updated repository with 4GB RAM and 2vCPU cores
  • root or ordinary account with sudo privilege
  • Sufficient disk space and good internet access

On this tutorial we will examine how to install SonarQube Version 9.0.1, the installation will be consist of several steps, namely :


The details of installation will be detail discussed below.

1. Install OpenJDK 11

SonarQuber requires Java to run properly. Java is one of the requirements to install and set up SonarQube on Ubuntu 2004 LTS. On this tutorial, we will install OpenJDK 11. To install OpenJDK 11 we will submit the following command line :

$ sudo apt install openjdk-11-jre-headless

Output :

mpik@app01:~$ sudo apt install openjdk-11-jre-headless
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libmecab2 libzip5 linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic
  linux-image-5.4.0-26-generic linux-modules-5.4.0-26-generic linux-modules-extra-5.4.0-26-generic mecab-ipadic
  mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  ca-certificates-java java-common
Suggested packages:
  default-jre fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
The following NEW packages will be installed:
  ca-certificates-java java-common openjdk-11-jre-headless
0 upgraded, 3 newly installed, 0 to remove and 402 not upgraded.
Need to get 37.3 MB of archives.
After this operation, 171 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 focal/main amd64 java-common all 0.72 [6,816 B]
Get:2 focal-updates/main amd64 openjdk-11-jre-headless amd64 11.0.11+9-0ubuntu2~20.04 [37.2 MB]
Get:3 focal/main amd64 ca-certificates-java all 20190405ubuntu1 [12.2 kB]                     
Fetched 37.3 MB in 3min 15s (191 kB/s)                                                                                            
Selecting previously unselected package java-common.
(Reading database ... 238658 files and directories currently installed.)
Preparing to unpack .../java-common_0.72_all.deb ...
Unpacking java-common (0.72) ...
Selecting previously unselected package openjdk-11-jre-headless:amd64.
Preparing to unpack .../openjdk-11-jre-headless_11.0.11+9-0ubuntu2~20.04_amd64.deb ...
Unpacking openjdk-11-jre-headless:amd64 (11.0.11+9-0ubuntu2~20.04) ...
Selecting previously unselected package ca-certificates-java.
Preparing to unpack .../ca-certificates-java_20190405ubuntu1_all.deb ...
Unpacking ca-certificates-java (20190405ubuntu1) ...
Setting up java-common (0.72) ...
Setting up openjdk-11-jre-headless:amd64 (11.0.11+9-0ubuntu2~20.04) ...

2. Install and Configure Database (PostgreSQL)

SonarQube requires a database system to store and manage its data. From 2016, SonarQube only supports PostgreSQL and dropped support for MySQL.

2.1 Install PostgreSQL 13 on Ubuntu 20.04 LTS

On this tutorial we will use PostgreSQL version 13 for SonarQube database. The PostgreSQL 13 installation on Ubuntu 20.04 has been discussed on How To Install PostgreSQL 13 On Ubuntu 20.04 LTS article.

2.2 Configuring SonarQube Database

On this stage we will configure SonarQube database. We will create a new database user for SonarQube need. We will log in to PostgreSQL database and do a DML task for creating a new database user called as sonar.

mpik@app01:~$ sudo su - postgres
[sudo] password for mpik: 
postgres@app01:~$ createuser sonar
postgres@app01:~$ psql
psql (13.4 (Ubuntu 13.4-1.pgdg20.04+1))
Type "help" for help.

postgres=# ALTER USER sonar WITH ENCRYPTED password 'Sonar2021';
postgres=# CREATE DATABASE sonarqube OWNER sonar;
postgres=# GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
postgres=# \q

3. Download and Install SonarQube

3.1 Download SonarQube Distribution File

On this stage, we will download and install SonarQube on Ubuntu 22.04 operating system. We will locate the download URL from the SonarQube official download page, then download the SonarQube distribution files, by subumitting command line :

$ sudo wget

Output :

mpik@app01:~$ sudo wget
[sudo] password for mpik: 
--2021-09-17 22:29:41--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 290201762 (277M) [application/zip]
Saving to: ‘’        100%[=========================================================>] 276.76M   114KB/s    in 71m 22s 

2021-09-17 23:41:04 (66.2 KB/s) - ‘’ saved [290201762/290201762]
Download SonarQube Download
Download SonarQube Download

3.2 Unzip SonarQube Source File

By using zip command line, we will unzip the downloaded file.

$ sudo unzip

Output :

mpik@app01:~$ sudo unzip
[sudo] password for mpik: 
   creating: sonarqube-
   creating: sonarqube-
   creating: sonarqube-
  inflating: sonarqube-  
   creating: sonarqube-
  inflating: sonarqube-  
   creating: sonarqube-
  inflating: sonarqube-  
  inflating: sonarqube-  
  inflating: sonarqube-  
  inflating: sonarqube-  
   creating: sonarqube-
   creating: sonarqube-

. . .

inflating: sonarqube-  
   creating: sonarqube-
  inflating: sonarqube-  
  inflating: sonarqube-  
   creating: sonarqube-

3.3 Move Unzip File

After unzipping the source distribution file, then we will move unzipped files to /opt/sonarqube directory.

$ sudo mv sonarqube- /opt/sonarqub/

4. Add SonarQube Group and User

We need a dedicated user system and group for SonarQube, which can not run as the root user. To fulfill this requirement, we do the following tasks.

  1. Create a sonar group
  2. Create a sonar user and set /opt/sonarqube as the home directory.
  3. Grant the sonar user access to the /opt/sonarqube directory.
mpik@app01:~$ sudo groupadd sonar
[sudo] password for mpik: 
mpik@app01:~$ sudo useradd -d /opt/sonarqube -g sonar sonar
mpik@app01:~$ sudo chown sonar:sonar /opt/sonarqube -R
mpik@app01:/opt$ sudo chown sonar:sonar /opt/sonarqube -R
mpik@app01:/opt$ ls -ltr
total 4
drwxr-xr-x 11 sonar sonar 4096 Sep 20 19:45 sonarqube

5. Configure SonarQube

On this stage, we will configure SonarQube application by editing its configuration file. The file is located at /opt/sonarqube/conf/ and /opt/sonarqube/bin/linux-x86-64/

mpik@app01:/opt$ sudo vi /opt/sonarqube/conf/
# Property values can:
# - be overridden by environment variables. The name of the corresponding environment variable is the
#   upper-cased name of the property where all the dot ('.') and dash ('-') characters are replaced by
#   underscores ('_'). For example, to override 'sonar.web.systemPasscode' use 'SONAR_WEB_SYSTEMPASSCODE'.
# - be encrypted. See

# - The embedded H2 database is used by default. It is recommended for tests but not for
#   production use. Supported databases are Oracle, PostgreSQL and Microsoft SQLServer.
# - Changes to database connection URL (sonar.jdbc.url) can affect SonarSource licensed products.

# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.

#----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092

#----- Oracle 12c/18c/19c
# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.
# Only the thin client is supported, and we recommend using the latest Oracle JDBC driver. See
# for more details.
# If you need to set the schema, please refer to

#----- PostgreSQL 9.6 or greater
# By default the schema named "public" is used. It can be overridden with the parameter "currentSchema".
mpik@app01:/opt$ sudo vi /opt/sonarqube/bin/linux-x86-64/
# NOTE - This will set the user which is used to run the Wrapper as well as
#  the JVM and is not useful in situations where a privileged resource or
#  port needs to be allocated prior to the user being changed.
We will create a systemd service file to start SonarQube at system boot

6. Creating SystemD Service

6.1 Create SystemD Service File

On this stage, we will create a systemd service file to start SonarQube appliction at system boot. In this tutorial we will create a new file and named it as otosonar.service (the file name is depend on our need) and location will be at /etc/systemd/system directory.

$ sudo vi /etc/systemd/system/otosonar.service
Description=SonarQube service


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




6.2 Enable, Start and Monitor SonarQube Service Status

On this stage, we will manage SonarQube service. We will enable, start and monitor SonarQube service by submitting command line.

$ sudo systemctl enable otosonar
$ sudo systemctl start otosonar
$ sudo systemctl status otosonar

Output :

mpik@app01:/opt$ sudo systemctl enable otosonar
Created symlink /etc/systemd/system/ → /etc/systemd/system/otosonar.service.
mpik@app01:/opt$ sudo systemctl start otosonar
mpik@app01:/opt$ sudo systemctl status otosonar
● otosonar.service - SonarQube service
     Loaded: loaded (/etc/systemd/system/otosonar.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-09-20 19:57:53 PDT; 5s ago
    Process: 5409 ExecStart=/opt/sonarqube/bin/linux-x86-64/ start (code=exited, status=0/SUCCESS)
   Main PID: 5461 (wrapper)
      Tasks: 50 (limit: 9436)
     Memory: 736.3M
     CGroup: /system.slice/otosonar.service
             ├─5461 /opt/sonarqube/bin/linux-x86-64/./wrapper /opt/sonarqube/bin/linux-x86-64/../../conf/wrapper.conf>
             ├─5474 java -Dsonar.wrapped=true -Djava.awt.headless=true -Xms8m -Xmx32m -Djava.library.path=./lib -clas>
             └─5573 /usr/lib/jvm/java-11-openjdk-amd64/bin/java -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFra>

Sep 20 19:57:52 systemd[1]: Starting SonarQube service...
Sep 20 19:57:52[5409]: Starting SonarQube...
Sep 20 19:57:53[5409]: Started SonarQube.
Sep 20 19:57:53 systemd[1]: Started SonarQube service.
SonarQube Service
SonarQube Service

7. Modify Kernel System Limits

To ensure SonarQube runs smoothly, we need some parameters to adjust. These parameters are located at /etc/sysctl.conf file. We will add the following lines.

# SonarQube parameters
ulimit -n 65536
ulimit -u 4096

8. Access SonarQube Web Portal

We could access SonarQube application by using web browser. We will use server’s IP address or hostname on port 9000. In this tutorial we will use hostname (

SonarQube Login page
SonarQube Login page
Update Password for SonarQube web interface
Update Password for SonarQube web interface
SonarQube Main Page
SonarQube Main Page

Until this step, we have come to the end of the tutorial. The SonarQube application has been successfully installed on the Ubuntu 20.04 LTS operating system.


In this tutorial we have discussed how to install SonarQube on Ubuntu 20.04 LTS operating system. I hope this tutorila will be helpful.

(Visited 586 times, 1 visits today)


No comments yet. Why don’t you start the discussion?

Leave a Reply

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