SonarQube Installation and Setup
This topic walks you through installing SonarQube on your local machine or a server. You will install the SonarQube server, connect it to a database, and verify that the web interface loads correctly.
System Requirements
Before installing, confirm your machine meets these requirements:
- RAM: Minimum 2 GB, recommended 4 GB or more
- CPU: 2 cores minimum
- Java: Java 17 or later (required to run SonarQube)
- Operating System: Linux, Windows, or macOS
- Database: PostgreSQL 14+ (recommended), Microsoft SQL Server, or Oracle
Installation Overview
STEP 1: Install Java 17+
|
v
STEP 2: Install PostgreSQL and create a database
|
v
STEP 3: Download SonarQube Community Edition
|
v
STEP 4: Configure sonar.properties
|
v
STEP 5: Start SonarQube
|
v
STEP 6: Open browser at http://localhost:9000
Step 1: Install Java
SonarQube runs on the Java Virtual Machine. Download Java 17 or later from adoptium.net (Temurin distribution is free and widely used).
After installation, open a terminal and verify:
java -version
You should see output like: openjdk version "17.0.x"
Step 2: Set Up PostgreSQL
SonarQube needs a relational database to store scan results and configuration. PostgreSQL is the recommended choice for most teams.
After installing PostgreSQL, create a dedicated database and user:
-- Run these commands in the PostgreSQL shell (psql) CREATE USER sonar WITH PASSWORD 'sonar_password'; CREATE DATABASE sonarqube OWNER sonar; GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonar;
Write down the username, password, and database name — you will need them in the next step.
Step 3: Download SonarQube
Visit sonarqube.org/downloads and download the Community Edition ZIP file. Extract the archive to a permanent location such as:
- Linux:
/opt/sonarqube - Windows:
C:\sonarqube
Step 4: Configure sonar.properties
Open the file at conf/sonar.properties inside the extracted folder. Find and update these three lines:
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube sonar.jdbc.username=sonar sonar.jdbc.password=sonar_password
Save the file. These settings tell SonarQube how to connect to your PostgreSQL database.
Linux-Specific: Kernel Settings
SonarQube uses Elasticsearch internally. Elasticsearch requires a specific Linux kernel setting. Add this line to /etc/sysctl.conf:
vm.max_map_count=524288
Apply the setting without rebooting:
sudo sysctl -w vm.max_map_count=524288
Windows and macOS users can skip this step.
Step 5: Start SonarQube
Navigate to the bin folder inside the SonarQube directory, then go into the folder for your operating system:
Linux: bin/linux-x86-64/sonar.sh start Windows: bin\windows-x86-64\StartSonar.bat macOS: bin/macosx-universal-64/sonar.sh start
The first startup takes 2–3 minutes as SonarQube initializes the database and indexes.
Step 6: Open the Web Interface
Open a browser and navigate to:
http://localhost:9000
Log in with the default credentials:
- Username: admin
- Password: admin
SonarQube immediately asks you to change the default password. Choose a strong password and save it.
What the First Login Looks Like
+----------------------------------------------+ | SONARQUBE 9000 | +----------------------------------------------+ | | | Welcome! Change your password first. | | | | New password: [______________] | | Confirm: [______________] | | | | [Update and Continue] | | | +----------------------------------------------+
Installing SonarQube with Docker (Alternative)
If you have Docker installed, you can run SonarQube without a manual setup. Run this single command:
docker run -d --name sonarqube \ -p 9000:9000 \ sonarqube:community
Docker automatically downloads the SonarQube image and starts it. The web interface is available at http://localhost:9000 after about 60 seconds. This method uses an embedded H2 database, which works for learning but is not suitable for team use.
Checking Logs if Something Goes Wrong
SonarQube writes logs to the logs folder. Check these files when troubleshooting:
logs/sonar.log— main startup loglogs/web.log— web server loglogs/es.log— Elasticsearch (search engine) log
Most installation failures are caused by wrong database credentials, Java not being found, or the vm.max_map_count setting missing on Linux.
Verifying the Installation
After login, the SonarQube dashboard appears with no projects yet. The status bar at the bottom of the page shows all system components as green when everything is running correctly.
STATUS BAR +--------+-----------+----------+-----------+ | DB | WebServer | Search | Compute | | GREEN | GREEN | GREEN | GREEN | +--------+-----------+----------+-----------+
If any component shows red or yellow, check the corresponding log file for the error message.
