SonarQube is an open-source platform for continuous inspection of code quality. It provides developers with a way to identify and fix code issues, vulnerabilities, and bugs before they are deployed into production. In this article, we will show you how to install and set up SonarQube on a Debian 11 system.
Before we begin, make sure that you have a working Debian 11 system and a user with sudo privileges. You can check the version of your system by running the following command:
lsb_release -a
The output should look something like this:
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Now that we have confirmed that our system is running Debian 11, we can proceed with the installation of SonarQube.
Install Java
SonarQube requires Java to be installed on your system. If you don’t have Java installed, you can install it by running the following commands:
sudo apt update
sudo apt install openjdk-11-jre-headless
After the installation is complete, you can verify the installation by running the following command:
java -version
The output should look something like this:
openjdk version "11.0.8" 2021-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Debian-1deb10u1, mixed mode, sharing)
Install and Configure PostgreSQL
SonarQube uses a relational database to store its data. In this tutorial, we will use PostgreSQL as the database. If you don’t have PostgreSQL installed on your system, you can install it by running the following commands:
sudo apt install postgresql postgresql-contrib
After the installation is complete, you need to create a database and a user for SonarQube. To do that, log in to the PostgreSQL shell as the postgres user by running the following command:
sudo -u postgres psql
Once you are in the PostgreSQL shell, run the following commands to create a new database and a new user:
CREATE DATABASE sonarqube;
CREATE USER sonarqube WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonarqube;
Replace your_password
with a strong password of your choice.
After creating the database and the user, exit the PostgreSQL shell by running the \\q
command.
Install and Configure SonarQube
Now that we have installed Java and PostgreSQL, we can proceed with the installation of SonarQube.
First, download the latest version of SonarQube by running the following command:
wget <https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.5.zip>
This will download the sonarqube-7.9.5.zip file in the current directory.
After the download is complete, unzip the downloaded file by running the following command:
unzip sonarqube-7.9.5.zip
This will extract the contents of the zip file into a directory called sonarqube-7.9.5
.
Next, we need to create a configuration file for SonarQube. To do that, copy the sonar.properties.example
file to sonar.properties
by running the following command:
cp sonarqube-7.9.5/conf/sonar.properties.example sonarqube-7.9.5/conf/sonar.properties
Now, open the sonar.properties
file in a text editor and set the values for the following properties:
sonar.jdbc.username=sonarqube
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
Replace your_password
with the password that you set for the sonarqube
user in PostgreSQL.
Save the changes and close the file.
Start SonarQube
To start SonarQube, run the following command:
sonarqube-7.9.5/bin/linux-x86-64/sonar.sh start
This will start the SonarQube server in the background. To verify that the server has started successfully, run the following command:
sonarqube-7.9.5/bin/linux-x86-64/sonar.sh status
The output should look something like this:
SonarQube is running (pid 9999).
To access the SonarQube web interface, open a web browser and go to the following URL:
<http://localhost:9000>
You should see the SonarQube login page. Use the default username and password (admin
and admin
) to log in.
Once you are logged in, you can change the default password and start using SonarQube to inspect your code quality.
Conclusion
In this article, we showed you how to install and set up SonarQube on a Debian 11 system. We also covered how to install and configure the required dependencies (Java and PostgreSQL) and how to start the SonarQube server. Now you have a working SonarQube installation that you can use to improve the quality of your code.