{"id":3067,"date":"2025-04-21T07:24:26","date_gmt":"2025-04-21T07:24:26","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=3067"},"modified":"2025-04-21T07:24:28","modified_gmt":"2025-04-21T07:24:28","slug":"how-we-fixed-sonar-scanner-command-not-found-and-successfully-analyzed-our-project-with-sonarqube","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/how-we-fixed-sonar-scanner-command-not-found-and-successfully-analyzed-our-project-with-sonarqube\/","title":{"rendered":"How We Fixed \u201csonar-scanner: command not found\u201d and Successfully Analyzed Our Project with SonarQube"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"612\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-8.png\" alt=\"\" class=\"wp-image-3068\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-8.png 942w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-8-300x195.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-8-768x499.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p>Running static code analysis with <strong>SonarQube<\/strong> is essential for maintaining clean, quality code. Recently, while working on our Laravel microservice project <code>mhn-doctors-ms<\/code>, we hit a common yet frustrating roadblock:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u274c <code>bash: sonar-scanner: command not found<\/code><\/p>\n<\/blockquote>\n\n\n\n<p>This error appeared when trying to run the SonarScanner CLI from Git Bash on Windows.<br>If you\u2019re facing the same issue, this guide will walk you through the <strong>exact steps to fix it<\/strong> and get your code scanned properly in no time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d What Went Wrong?<\/h2>\n\n\n\n<p>We attempted to run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sonar-scanner \\\n  -Dsonar.projectKey=mhn_doctor_ms_sonarQube_test \\\n  -Dsonar.sources=. \\\n  -Dsonar.host.url=http:\/\/127.0.0.1:9000 \\\n  -Dsonar.token=sqp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n<\/code><\/pre>\n\n\n\n<p>But instead of running the scan, Git Bash responded with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash: sonar-scanner: command not found\n<\/code><\/pre>\n\n\n\n<p>This error simply means that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SonarScanner CLI is not installed<\/strong>, or<\/li>\n\n\n\n<li>It&#8217;s <strong>not added to your system\u2019s PATH<\/strong>, so your terminal doesn\u2019t know where to find it.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Step-by-Step Fix<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 Download SonarScanner CLI for Windows<\/h3>\n\n\n\n<p>Visit the official SonarSource download page:<\/p>\n\n\n\n<p>\ud83d\udd17 <a class=\"\">Download SonarScanner CLI<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose the latest <code>.zip<\/code> file (e.g., <code>sonar-scanner-cli-5.0.1.3006-windows.zip<\/code>)<\/li>\n\n\n\n<li>Extract it to a permanent folder. For example:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\sonar-scanner\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add SonarScanner to Your System PATH<\/h3>\n\n\n\n<p>To use <code>sonar-scanner<\/code> from any terminal:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Press <code>Windows + S<\/code>, search for <strong>&#8220;Environment Variables&#8221;<\/strong><\/li>\n\n\n\n<li>Click <strong>&#8220;Edit the system environment variables&#8221;<\/strong><\/li>\n\n\n\n<li>In the <strong>System Properties<\/strong> window, click <strong>Environment Variables<\/strong><\/li>\n\n\n\n<li>Under <strong>System Variables<\/strong>, find and select <code>Path<\/code>, then click <strong>Edit<\/strong><\/li>\n\n\n\n<li>Click <strong>New<\/strong> and add:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\sonar-scanner\\bin\n<\/code><\/pre>\n\n\n\n<p>Click OK \u2192 OK \u2192 Close all windows<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verify Installation<\/h3>\n\n\n\n<p>Open a new terminal window (PowerShell or CMD recommended) and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sonar-scanner -v\n<\/code><\/pre>\n\n\n\n<p>If installed correctly, you should see the version of SonarScanner printed.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4\ufe0f\u20e3 Run SonarScanner on Your Project<\/h3>\n\n\n\n<p>Now that everything\u2019s set, navigate to your project folder and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sonar-scanner \\\n  -Dsonar.projectKey=mhn_doctor_ms_sonarQube_test \\\n  -Dsonar.sources=. \\\n  -Dsonar.host.url=http:\/\/127.0.0.1:9000 \\\n  -Dsonar.token=sqp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n<\/code><\/pre>\n\n\n\n<p>After a few seconds, you\u2019ll see the analysis running and a success message with a link to your results on the SonarQube dashboard.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Pro Tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use PowerShell or CMD<\/strong> instead of Git Bash for better Windows compatibility.<\/li>\n\n\n\n<li>Always generate and use a <strong>SonarQube token<\/strong> for CLI authentication \u2014 no need to expose passwords.<\/li>\n\n\n\n<li>Keep your SonarScanner CLI updated for the latest rules and features.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3067","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3067"}],"version-history":[{"count":2,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3067\/revisions"}],"predecessor-version":[{"id":3070,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3067\/revisions\/3070"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}