Hamsa K
11 min read | 4 months ago

How to Install Sonarqube on Ubuntu 20 04

How to Install Sonarqube on Ubuntu 20.04

sonarqube is an automatic code review tool to detect bugs, vulnerabilities, and code smells in your code and integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests.

In this tutorial, we will explain how to install sonarqube on ubuntu 20.04

Step 1: setup kernel parameters

First we will set few kernel system limits in systl.conf file with beloe command.

sudo nano /etc/sysctl.conf

Add below content to above file.

ulimit -n 65536
ulimit -u 4096

save and exit the file and also edit limits.conf file

nano /etc/security/limits.conf

Add below content to above file.

sonarqube   -   nofile   65536
sonarqube   -   nproc    4096

save and close the file and reboot the system to take changes effect.

Also Read -> How to Install Vagrant on Ubuntu 20 04

Step 2: Install Java

now we will install java 11 in your ubuntu 20.04 system.

sudo apt install openjdk-11-jdk

once java is installed, check the version with the following command.

java -version


openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

Also Read -> How to Install Wine on Ubuntu 20 04

Step 3: Install postgresql

we will install postgresql 12 database before installing sonarqube and run the following command to install postgresql db.

sudo apt install postgresql postgresql-contrib

once it is installed, start and enable postgresql service to start on boot and also check the status.

sudo systemctl start  postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql

Step 4: create database

we will create database, user and password and set privileges. so first we will set password for the Postgresql user( system user) with the command.

sudo passwd postgres

it prompts to set password for postgres admin user.

Now switch to postgres user

su - postgres

create new user by typing below.

createuser sonar

now switch to the postgresql shell


create database,set privileges to user and set the password to user sonar.

postgres=# CREATE DATABASE sonarqube OWNER sonar;
postgres=# GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;

now exit from postgres console and also from postgres user.

postgres=# \q
postgres@ubuntu20:~$ exit

Also Read -> How to Install Apache Maven on Ubuntu 20 04

Step 5: download sonarqube

you can download sonarqube from official download page.you can download latest version as below.

wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-

install zip command and unzip the file

sudo apt install zip
unzip sonarqube-

move and rename the file to opt directory.

sudo mv sonarqube- /opt/sonarqube

Step 6: create sonarqube group and user

create the user and add it to the group with the following commands.

sudo groupadd sonar
sudo useradd -c "SonarQube user" -d /opt/sonarqube/ -g sonar sonar

also set ownership to /opt/sonarqube directory.

sudo chown -R sonar:sonar /opt/sonarqube/

Also Read -> How to Install CouchDB on Ubuntu 20 04

Step 7: configure sonarqube

open configuration file using below command.

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

and search below lines and changes as below.

sonar.search.javaOpts=-Xmx512m -Xms512m -XX:+HeapDumpOnOutOf
sonar.search.javaOpts=-Xmx512m -Xms512m -XX:+HeapDumpOnOutOfMemoryError

enter the password as you created for the sonar Postgresql user and save the file and close.

Step 8: create systemd file

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

Add below lines to above file

Description=SonarQube service
After=syslog.target network.target
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop

now start and enable sonarqube service.

sudo systemctl start sonarqube
sudo systemctl enable sonarqube

Also Read -> How to Install Apache Tomcat 9 on Ubuntu 20 04

Step 9: Install nginx

install nginx web service using apt with following command.

sudo apt install nginx

once it is installed, start and enable the service

sudo systemctl start nginx
sudo systemctl enable nginx

create nginx configuration file as below

sudo nano /etc/nginx/sites-enabled/sonarqube.conf

Add below content to above file

    listen      80;
    server_name sonarqube.lamp.com;
    access_log  /var/log/nginx/sonar.access.log;
    error_log   /var/log/nginx/sonar.error.log;
    proxy_buffers 16 64k;
    proxy_buffer_size 128k;
    location / {
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        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 http;

you can nginx syntax errors using below command.

nginx -t

then enable nginx website using link file

ln -s /etc/nginx/sites-available/sonarqube.conf /etc/nginx/sites-enabled/

save and close the file and restart nginx service.

sudo systemctl restart nginx

Step 10: Access sonarqube

Now open your favorite browser to access SonarQube using the address http://ip_address or Host address. you can login with default username and password as admin.once you are loggedin you can reset password and use.

That's it. Now you have successfully installed sonarqube on ubuntu 20.04 system.

Also Read -> How to Install Atom Text Editor on Ubuntu 20 04

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy