How to Install SonarScanner CLI Client on Windows, Linux, and macOS
SonarScanner is a command-line tool that allows you to interact with SonarQube, a popular open-source platform for continuous inspection of code quality.
It enables static analysis for bugs, vulnerabilities, and code smells in your project. In this guide, we’ll cover how to install the SonarScanner CLI client on Windows, Linux, and macOS.
Prerequisites
Before you install SonarScanner, ensure you have the following:
• Java Development Kit (JDK): SonarScanner requires Java to run. You can download it from the Oracle JDK or use OpenJDK.
• SonarQube Server: Make sure you have a SonarQube server running, either locally or on a remote machine. You can set up a SonarQube instance by following the SonarQube installation guide.In this article you will connect to the server instead.
Once you’ve met these prerequisites, you can begin installing SonarScanner on your system.
Note: For downloading the Sonar scanner CLI for various OS, the URL is https://docs.sonarsource.com/sonarqube-server/10.4/analyzing-source-code/scanners/sonarscanner/
Step 1: Installing SonarScanner CLI on Windows
1.1. Download SonarScanner for Windows
- Go to the
2. Download the Windows version of SonarScanner (e.g., sonar-scanner-cli-4.6.2.2472-windows.zip).
1.2. Extract the ZIP File
1. Once the ZIP file is downloaded, extract it to a location of your choice, for example, C:\sonar-scanner.
1.3. Add SonarScanner to Your System Path
To make SonarScanner accessible from the command line:
1. Open the Start Menu and search for Environment Variables.
2. Click on Edit the system environment variables.
3. In the System Properties window, click on the Environment Variables button.
4. Under System variables, find and select Path, then click Edit.
5. Click New and add the path to your SonarScanner bin directory (e.g., C:\sonar-scanner\bin).
6. Click OK to save and exit the Environment Variables window.
1.4. Verify Installation
Open a new Command Prompt window and run:
sonar-scanner -v
You should see the version of SonarScanner that was installed.
Step 2: Installing SonarScanner CLI on Linux
2.1. Download SonarScanner for Linux
- Open your terminal.
- Get the correct Linux installer url from
3. Download the latest version of SonarScanner using wget:
for example
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.2.1.4610-linux-x64.zip
2.2. Install Unzip and Extract Files
If you don’t have unzip installed, you can install it with:
sudo apt-get install unzip
Next, extract the SonarScanner ZIP file:
unzip <the zip file name>
2.3. Move SonarScanner to a Directory of Your Choice
Move the extracted folder to a preferred location (e.g., /opt):
sudo mv <the extracted folder name> /opt/sonar-scanner
2.4. Add SonarScanner to Your PATH
Edit your .bashrc (or .zshrc for Zsh users) to add the SonarScanner bin directory to the system path:
echo 'export PATH=$PATH:/opt/sonar-scanner/bin' >> ~/.bashrc
source ~/.bashrc
2.5. Verify Installation
Verify the installation by running:
sonar-scanner -v
You should see the version of SonarScanner installed.
Step 3: Installing SonarScanner CLI on macOS
3.1. Install Homebrew (if not already installed)
Homebrew is a package manager for macOS that simplifies the installation of software. If you don’t have Homebrew installed, you can install it by running the following command in your terminal:
Get the correct mac dowloader url from
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if the url above broken check new one on
3.2. Install SonarScanner Using Homebrew
Once Homebrew is installed, you can install SonarScanner by running:
brew install sonar-scanner
3.3. Verify Installation
Check if SonarScanner was successfully installed by running:
sonar-scanner -v
You should see the SonarScanner version information.
Step 4: Configure SonarScanner
After installing SonarScanner on any platform, you need to configure it by setting the SonarQube server URL and authentication token (if required).
1. Navigate to the sonar-scanner directory (e.g., /opt/sonar-scanner on Linux or C:\sonar-scanner on Windows).
2. Open the conf/sonar-scanner.properties file in a text editor.
3. Add or update the following properties:
# Specify the URL of your SonarQube server
sonar.host.url=http://<sonarqube server IP>:9000
# Optional: Add your SonarQube token for authentication (replace with your actual token)
sonar.login=YOUR_SONARQUBE_TOKEN
4. Save the file and close the editor.
Step 5: Running a Scan with SonarScanner
Once SonarScanner is installed and configured, you can start scanning your project.
1. Open a terminal or command prompt.
2. Navigate to your project’s root directory (where your sonar-project.properties file is located).
cd /path/to/your/project
3. Run the following command to start the scan:
sonar-scanner
SonarScanner will start analyzing your project, upload the results to your SonarQube server, and you’ll be able to view the analysis results via the SonarQube dashboard.
http://<sonarqube server IP>:9000
Now that you know how to install SonarScanner CLI on Windows, Linux, and macOS, you can easily integrate it into your workflow for continuous code quality analysis. By following this guide, you can scan your projects for bugs, vulnerabilities, and code smells and improve your software development process.