Introduction
SonarQube is an open-source platform designed to help developers in writing better-quality code. It provides a range of tools and features for code analysis, quality assurance, continuous inspection, maintainability, and reliability of software development projects.
This article will explain how to install SonarQube on Debian 11|10.
Install Java
-
Update the system and install the required tools.
$ sudo apt -y update
$ sudo apt install net-tools wget unzip ufw -
Edit the file
/etc/sysctl.conf
to fit the necessary SonarQube requirements.$ sudo nano /etc/sysctl.conf
-
Add the following lines at the end of the file.
$ vm.max_map_count=262144
$ fs.file-max=65536 -
Reload the system configurations.
$ sudo sysctl --system
-
Install Java 11 using the following command.
$ sudo apt -y install openjdk-11-jdk
Install PostgreSQL
-
Add PostgreSQL repository.
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
-
Install PostgreSQL using the following command.
This will install PostgreSQL along with some additional contributed packages.$ sudo apt -y update
$ sudo apt -y install postgresql postgresql-contrib -
Enable and start PostgreSQL.
$ sudo systemctl start postgresql
$sudo systemctl enable postgresql
-
Now that we have installed PostgreSQL, we need to create a database and a user for SonarQube.
$ sudo su postgres
$ psql -
Create a Database and user for Sonarqube.
These commands will create a new PostgreSQL user named "sonar", a database named "sonarqube", and grant all privileges to the "sonar" user on the "sonarqube" database.CREATE USER sonarqube WITH PASSWORD 'password';
CREATE DATABASE sonarqube OWNER sonarqube;
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonarqube;
exit -
Return to your non-root account
$ exit
Download and install SonarQube
-
Download SonarQube using the following command.
$ wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.2.2.50622.zip
-
Once the download is complete, unzip the package using the following command.
$ sudo unzip sonarqube-*.zip
$ sudo mv sonarqube-*/ /opt/sonarqube -
Create a System User account for SonarQube.
$ sudo useradd -M -d /opt/sonarqube/ -r -s /bin/bash sonarqube
-
Change the ownership of the installation directory
$ sudo chown -R sonarqube: /opt/sonarqube
Configure SonarQube
-
Open the "/opt/sonarqube/conf/sonar.properties" file using your preferred text editor.
$ sudo nano /opt/sonarqube/conf/sonar.properties
-
Find and Update the following properties in the file.
sonar.jdbc.username=sonarqube
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
sonar.web.host=<your-ip-address>
sonar.web.port=9000 - Create a SonarQube Systemd Service File.
Add the below lines in the file and then save and close it.$ sudo nano /etc/systemd/system/sonarqube.service
Save and close the file.[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=sonarqube
Group=sonarqube
Restart=always
LimitNOFILE=65536
LimitNPROC=4096
[Install]
WantedBy=multi-user.target -
Start and enable the SonarQube service.
$ sudo systemctl daemon-reload
$ sudo systemctl start sonarqube
$ sudo systemctl enable sonarqube -
Allow port 9000 through the firewall.
$ sudo ufw allow 9000
- Once SonarQube is up and running, you can access it by opening a web browser and navigating to http://your_server_ip:9000. use the username ‘admin‘ and password as ‘admin‘.