How to Install and Set Up SonarQube on Windows, Mac, and Linux: Step-by-Step Guide

SonarQube is an open-source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities. This guide will help you set up SonarQube on your local system.
1: Prerequisites
Before installing SonarQube, ensure you have the following:
- Java Development Kit (JDK) 11 or 17: SonarQube requires a compatible version of Java to run.
2: Download and Set Up SonarQube
- Download SonarQube: Visit the official SonarQube downloads page and download the Community Edition ZIP file.
- Extract SonarQube: Unzip the downloaded file to a directory of your choice (e.g., `C:\sonarqube` or `/opt/sonarqube`).
3: Start the SonarQube Server
SonarQube includes a built-in web server and a search server. For a local setup, you can use the provided startup scripts.
- Navigate to the Bin Directory: Open a terminal or command prompt and navigate to the `bin` directory corresponding to your operating system inside the SonarQube installation folder. For example, on a 64-bit Windows system, this would be `sonarqube-x.x/bin/windows-x86-64`.
- Start the Server:
On Windows:
StartSonar.bat
On Mac/Linux:
./sonar.sh start
- Access SonarQube: Once the server has started (it may take a few moments), open your web browser and go to `http://localhost:9000`.
4: Log In and Get Started
- Log In: The default administrator credentials are:
- Username: admin
- Password: admin
- Change Password: You will be prompted to change the administrator password upon your first login.
5: Conclusion
Congratulations! You have successfully installed and set up SonarQube on your system. You can now start creating projects and analyzing your code for quality and security issues.
FAQ
Q: Is the built-in database suitable for production?
A: No, the embedded H2 database is for evaluation purposes only. For production use, you should configure SonarQube to use a supported external database like PostgreSQL, Oracle, or Microsoft SQL Server.
Q: How do I stop the SonarQube server?
A: On Windows, you can press `Ctrl+C` in the console. On Mac/Linux, run `./sonar.sh stop` from the same `bin` directory.