How to Install SonarQube on Ubuntu Linux




The article provides step-by-step instructions on how to install and use SonarQube on Ubuntu Linux. SonarQube is an open-source platform that allows developers to inspect and analyze code quality and implement best security practices. The guide covers the installation of dependencies like OpenJDK and PostgreSQL, creating a SonarQube database and user, downloading and configuring SonarQube,…

This article describes steps one can take to install SonarQube on Ubuntu Linux.

SonarQube helps developers write clean and better code. It is an open-source platform for inspecting and analyzing code for quality and applying security best practices.

With this platform, businesses and developers can find and fix bugs, find vulnerabilities, and maintain coding standards, removing complexity.

Below is how to install and use SonarQube on Ubuntu Linux.

How to install SonarQube on Ubuntu Linux

As mentioned above, SonarQube helps developers write clean and better code. In addition, it is an open-source platform for inspecting and analyzing code for quality and best security practices.

Below is how to install it on Ubuntu Linux.

Install OpenJDK

SonarQube is built with Jave and requires its JDK installed. However, the open-source version should be great to use with it.

Below is how to install OpenJDK on Ubuntu.

sudo apt update
sudo apt install default-jdk

For additional resources on installing OpenJDK on Ubuntu, read the post below.

How to install OpenJDK on Ubuntu Linux

Install PostgreSQL

A database server is also required with SonarQube. PostgreSQL is a database server well-suited for SonarQube.

Below is how to install PostgreSQL on Ubuntu Linux.

Run the commands below to add the PostgreSQL repository GPG key.

wget -q -O - | sudo apt-key add -

Next, create a PostgreSQL repository file.

sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

Next, update the Ubuntu package index and install PostgreSQL version 13.

sudo apt update
sudo apt install postgresql-13

For additional resources on installing PostgreSQL, read the post below.

How to install PostgreSQL on Ubuntu Linux

Create a SonarQube database and user

Now that the database server is installed, let’s go and create a database for SonarQube to use and an account for it.

Log on to the PostgreSQL command shell.

sudo -u postgres psql

Create a new database user called sonarqube.

CREATE USER sonarqube WITH PASSWORD 'type_password_here';

Create a new database called sonarqube.

CREATE DATABASE sonarqube OWNER sonarqube;

Then, grant the sonarqube user full access to the sonarqube database.




Create a SonarQube system account and download

At this point, we’re ready to begin setting up SonarQube. First, create a system account named sonarqube.

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

Install some package dependencies.

sudo apt install unzip software-properties-common wget

Download SonarQube version 9.6.1.


Unzip the downloaded file, then move the unzipped file to the SonarQube home directory.

sudo mv sonarqube- /opt/sonarqube

Make sure the sonarqube account is the owner of the content.

sudo chown -R sonarqube:sonarqube /opt/sonarqube

Configure SonarQube

With SonarQube content downloaded, go and configure its configuration file. Then, run the commands below to open its main config file.

sudo nano /opt/sonarqube/conf/

Make the highlighted lines in the file by adding the database and account names created above.


# - 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.

Also, make sure the server IP and port number are defined.

#Startup can be long if entropy source is short of entropy. Adding is an option to resolve the problem.
sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
# Same as previous property, but allows to not repeat all other settings like -Xmx
# Binding IP address. For servers with more than one IP address, this property specifies which
# address will be used for listening on the specified ports.
# By default, ports will be used on all IP addresses associated with the server.
# Web context. When set, it must start with forward slash (for example /sonarqube).
# The default value is root context (empty value).
# TCP port for incoming HTTP connections. Default value is 9000.

Save the file and exit.

Create SonarQube systemd service

Finally, run the commands below to create a systemd service file for SonarQube. This will help you control SonarQube services.

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

Copy and paste the lines below into the file and save.

Description=SonarQube service

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


Reload the systemd daemon, then start and enable the SonarQube service.

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

SonarQube should be started and running.

Access SonarQube portal

Finally, open your web browser and browse to the server hostname or IP address followed by port number 9000.


You should see SonarQube’s default login portal.

ubuntu linux install sonarqube login page
Ubuntu Linux installs the sonarqube login page.

Login with default admin and admin for both username and password.

ubuntu linux sonarqube user dashboard
ubuntu Linux sonarqube user dashboard

Use Reverse proxy with SonarQube

The most effective way to use SonarQube is to set up a reverse proxy. We have written two posts on reverse proxy for both Apache and Nginx.

Use the posts below to set up a reverse proxy with SonarQube.

That should do it!


This post showed you how to install and use SonarQube on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.

Like this:

Leave a Reply

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

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