Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How We Fixed “sonar-scanner: command not found” and Successfully Analyzed Our Project with SonarQube

Running static code analysis with SonarQube is essential for maintaining clean, quality code. Recently, while working on our Laravel microservice project mhn-doctors-ms, we hit a common yet frustrating roadblock:

bash: sonar-scanner: command not found

This error appeared when trying to run the SonarScanner CLI from Git Bash on Windows.
If you’re facing the same issue, this guide will walk you through the exact steps to fix it and get your code scanned properly in no time.


🔍 What Went Wrong?

We attempted to run:

sonar-scanner \
  -Dsonar.projectKey=mhn_doctor_ms_sonarQube_test \
  -Dsonar.sources=. \
  -Dsonar.host.url=http://127.0.0.1:9000 \
  -Dsonar.token=sqp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

But instead of running the scan, Git Bash responded with:

bash: sonar-scanner: command not found

This error simply means that:

  • SonarScanner CLI is not installed, or
  • It’s not added to your system’s PATH, so your terminal doesn’t know where to find it.

✅ Step-by-Step Fix

1️⃣ Download SonarScanner CLI for Windows

Visit the official SonarSource download page:

🔗 Download SonarScanner CLI

  • Choose the latest .zip file (e.g., sonar-scanner-cli-5.0.1.3006-windows.zip)
  • Extract it to a permanent folder. For example:
C:\sonar-scanner

Add SonarScanner to Your System PATH

To use sonar-scanner from any terminal:

  1. Press Windows + S, search for “Environment Variables”
  2. Click “Edit the system environment variables”
  3. In the System Properties window, click Environment Variables
  4. Under System Variables, find and select Path, then click Edit
  5. Click New and add:
C:\sonar-scanner\bin

Click OK → OK → Close all windows

Verify Installation

Open a new terminal window (PowerShell or CMD recommended) and run:

sonar-scanner -v

If installed correctly, you should see the version of SonarScanner printed.


4️⃣ Run SonarScanner on Your Project

Now that everything’s set, navigate to your project folder and run:

sonar-scanner \
  -Dsonar.projectKey=mhn_doctor_ms_sonarQube_test \
  -Dsonar.sources=. \
  -Dsonar.host.url=http://127.0.0.1:9000 \
  -Dsonar.token=sqp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

After a few seconds, you’ll see the analysis running and a success message with a link to your results on the SonarQube dashboard.


💡 Pro Tips

  • Use PowerShell or CMD instead of Git Bash for better Windows compatibility.
  • Always generate and use a SonarQube token for CLI authentication — no need to expose passwords.
  • Keep your SonarScanner CLI updated for the latest rules and features.

Related Posts

Fixing the “Could not find PHP executable” Error in Live Server on VS Code

this is a common issue and easy to fix! This guide will walk you through the step-by-step solution to get your PHP files running in the browser….

How to Fix the “npm.ps1 cannot be loaded” Error on Windows When Running npm start

If you’re a developer working with React or any Node.js-based projects, you may have encountered the following error when trying to run npm start in PowerShell on…

Simplify Database Migrations with kitloong/laravel-migrations-generator in Laravel

Laravel provides a powerful migration system that allows developers to easily define and manage database schema changes. However, when working with legacy databases or large projects, manually…

Understanding and Fixing the “Unable to Read Key from File” Error in Laravel Passport

Laravel Passport is a powerful package for handling OAuth2 authentication in Laravel applications. It allows you to authenticate API requests with secure access tokens. However, like any…

How to Generate a GitHub OAuth Token with Read/Write Permissions for Private Repositories

When working with GitHub, you may need to interact with private repositories. For that, GitHub uses OAuth tokens to authenticate and authorize your access to these repositories….

Laravel Error: Target class [DatabaseSeeder] does not exist – Solved for Laravel 10+

If you’re working with Laravel 10+ and run into the frustrating error: …you’re not alone. This is a common issue developers face, especially when upgrading from older…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x