In this tutorial, we will show you how to install SonarQube on Ubuntu 20.04 LTS. For those of you who didn’t know, SonarQube is an open-source web-based tool to manage code quality and code analysis. SonarQube includes features like bug and vulnerability detection and code tracking. SonarQube can integrate into GitHub, Azure DevOps, Bitbucket, GitLab, and Docker. If you happen to have an on-premise Linux server, or a cloud account with the likes of AWS, Google Cloud, or Azure, handy, you can deploy the community edition of SonarQube for free.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the SonarQube on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, and any other Debian-based distribution like Linux Mint or elementary OS.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install SonarQube on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following
apt commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Configure Kernel.
Now modify the kernel system limits. For this we must set the following:
- vm.max_map_count must be greater than or equal to 524288
- fs.file-max must be greater than or equal to 131072
- The SonarQube user must be able to open at least 131072 file descriptors
- The SonarQube user must be able to open at least 8192 threads
sudo nano /etc/sysctl.conf
Add the following lines to the bottom of that file:
vm.max_map_count=262144 fs.file-max=65536 ulimit -n 65536 ulimit -u 4096
Next, open the limits.conf file with the command:
sudo nano /etc/security/limits.conf
At the end of this file, add the following:
sonarqube - nofile 65536 sonarqube - nproc 4096
Then, reboot your system so the changes will take effect.:
Step 3. Installing Java.
Run the following command to install OpenJDK and JRE 11:
sudo apt install openjdk-11-jdk sudo apt install openjdk-11-jre
Step 4. Installing PostgreSQL.
SonarQube only works with PostgreSQL. Now we running the command below to install it:
sudo apt install postgresql postgresql-contrib
Once done, start and enable the database service with the commands:
sudo systemctl enable postgresql sudo systemctl start postgresql
Now we must set a password for the PostgreSQL user with the command:
sudo passwd postgres
Login as a PostgreSQL superuser and Create SonarQube PostgreSQL Database and Database user:
sudo -Hiu postgres createuser sonaradmin createdb -O sonaradmin sonarqubedb psql ALTER USER sonaradmin WITH ENCRYPTED password 'changeme'; \q exit
Step 5. Installing SonarQube on Ubuntu 20.04.
Now download the latest version of the SonarQube installer from the official website:
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-188.8.131.52547.zip sudo unzip sonarqube-184.108.40.206547.zip -d /opt
Move extracted setup to
sudo mv /opt/sonarqube-220.127.116.11547 /opt/sonarqube
Step 5. Configure SonarQube.
Now we create a group as sonar:
sudo groupadd sonar sudo useradd -c "user to run SonarQube" -d /opt/sonarqube -g sonar sonar sudo chown sonar:sonar /opt/sonarqube -R
Next, open the SonarQube configuration file using your favorite text editor:
Find the following lines:
Uncomment and Type the PostgreSQL Database username and password which we have created in the above steps and add the Postgres connection string:
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
Next, edit the sonar script file and set
Now to start SonarQube:
sudo su sonar cd /opt/sonarqube/bin/linux-x86-64/
Next, run the script to start SonarQube:
To check if SonarQube is running enter the below command:
Step 6. Configure Systemd service.
Let’s now create a
systemd file, so the SonarQube service can be controlled. Create the file with the command:
sudo nano /etc/systemd/system/sonar.service
Add the following line:
[Unit] Description=SonarQube service After=syslog.target network.target [Service] Type=forking ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop User=sonar Group=sonar Restart=always LimitNOFILE=65536 LimitNPROC=4096 [Install] WantedBy=multi-user.target
Save and close the file, you can now start and enable the SonarQube service with the following two commands:
sudo systemctl start sonarqube sudo systemctl enable sonarqube
Step 7. Accessing SonarQube Web Interface.
Once successfully installed, access the SonarQube using browser-type server IP followed by port 9000:
You should eventually see a login screen, where you’ll use the default credentials of admin/admin. Upon successful authentication, you’ll be required to change the default password. Once you’ve taken care of that, you’ll find yourself at the SonarQube main page:
Congratulations! You have successfully installed SonarQube. Thanks for using this tutorial for installing the SonarQube on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official SonarQube website.