# Install SonarQube  RIGHT NOW !!

## **Prerequisites**

You have a fresh Ubuntu instance (e.g., 22.04).  
  
You have sudo access as your normal user.

## **Step 1: Install required software**

`sudo apt update`

`sudo apt install openjdk-17-jdk wget unzip ntp -y`

**Why:**

* openjdk-17-jdk → Java 17, required by SonarQube.
    
* wget → to download SonarQube.
    
* unzip → to extract the .zip.
    
* ntp → keeps system clock synced (very important for token expiry, JWT, Elasticsearch timing).
    

## **Step 2: Find and confirm Java path (JAVA\_HOME)**

**Find which Java was installed:**

`update-java-alternatives -l`

Output looks like:

java-1.17.0-openjdk-amd64 1711 /usr/lib/jvm/java-1.17.0-openjdk-amd64

**Use the part /usr/lib/jvm/java-1.17.0-openjdk-amd64 as JAVA\_HOME.**

*(In most Ubuntu systems installed from apt, it usually is /usr/lib/jvm/java-17-openjdk-amd64.)*

**Verify Java works:**

`java -version`

Should show:

openjdk version "17.x.x"

## **Step 3: Create a dedicated sonar user**

`sudo useradd -m -d /opt/sonarqube -U -r -s /bin/bash sonar`

**Why:**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command/Option</strong></p></td><td colspan="1" rowspan="1"><p><strong>Meaning</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p>useradd</p></td><td colspan="1" rowspan="1"><p>create a new user</p></td></tr><tr><td colspan="1" rowspan="1"><p>-m</p></td><td colspan="1" rowspan="1"><p>create home directory</p></td></tr><tr><td colspan="1" rowspan="1"><p>-d /opt/sonarqube</p></td><td colspan="1" rowspan="1"><p>set /opt/sonarqube as home directory</p></td></tr><tr><td colspan="1" rowspan="1"><p>-U</p></td><td colspan="1" rowspan="1"><p>create a group named sonar</p></td></tr><tr><td colspan="1" rowspan="1"><p>-r</p></td><td colspan="1" rowspan="1"><p>make this a system user (non-login user usually, but we’ll give shell)</p></td></tr><tr><td colspan="1" rowspan="1"><p>-s /bin/bash</p></td><td colspan="1" rowspan="1"><p>assign Bash shell (so we can log in)</p></td></tr></tbody></table>

---

## **Step 4: Give sonar user sudo access without password**

`sudo visudo`

At the end of the file, add:

sonar ALL=(ALL) NOPASSWD:ALL

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524412166/c817f39c-2063-4616-82b0-ca2d65935847.png align="center")

**Why:**

* Allows sonar user to run **any sudo command** on any host.
    
* NOPASSWD → no password prompt.  
    *(handy in dev; risky in prod).*
    

## **Step 5: Download and extract SonarQube**

`cd /opt`

`sudo wget` [`https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.6.0.8109.zip`](https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.6.0.8109.zip)

`sudo unzip` [`sonarqube-10.6.0.8109.zip`](http://sonarqube-10.6.0.8109.zip)

`sudo mv sonarqube-10.6.0.8109/* /opt/sonarqube/`

**Why:**

* /opt is standard for optional/3rd party apps.
    
* We move everything into /opt/sonarqube so it’s clean.
    

## **Step 6: Change ownership to sonar user**

`sudo chown -R sonar:sonar /opt/sonarqube`

**Why:**

* Make sure sonar user can read/write all files.
    
* \-R → recursive.
    

## **Step 7: Configure JAVA\_HOME and PATH for sonar user**

Switch to sonar user:

`sudo su - sonar`

Edit .bashrc:

`echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' >> ~/.bashrc`

`echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc`  

Then apply immediately:

`source ~/.bashrc`

**Why:**

* SonarQube scripts use Java.
    
* sonar user must know where Java is installed.
    

**Verify:**

java -version

## **Step 8: Set kernel and system parameters (important)**

**As your main sudo user (not sonar):**

### **8.1 Increase max map count (needed by Elasticsearch inside SonarQube):**

`sudo nano /etc/sysctl.conf`

Add:

`vm.max_map_count=262144`

`fs.file-max=65536`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524467945/34b18ae7-6ade-496f-9ee6-bab2f31a0654.png align="center")

Apply:

`sudo sysctl -p`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524509005/8ac0bf7d-ee75-49b7-be20-89108a88ca32.png align="center")

### **8.2 Increase user limits (number of open files and processes):**

`sudo nano /etc/security/limits.conf`

Add:

`sonar   -   nofile   65536`

`sonar   -   nproc    4096`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524537707/7b3e90d6-be61-4956-84c3-f23d6b058bfe.png align="center")

**Why:**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Setting</strong></p></td><td colspan="1" rowspan="1"><p><strong>Why</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p>vm.max_map_count</p></td><td colspan="1" rowspan="1"><p>Elasticsearch needs it; prevents memory map errors</p></td></tr><tr><td colspan="1" rowspan="1"><p>fs.file-max</p></td><td colspan="1" rowspan="1"><p>total max open files</p></td></tr><tr><td colspan="1" rowspan="1"><p>nofile</p></td><td colspan="1" rowspan="1"><p>max open files per user</p></td></tr><tr><td colspan="1" rowspan="1"><p>nproc</p></td><td colspan="1" rowspan="1"><p>max processes per user</p></td></tr></tbody></table>

## **Step 9: Enable and start NTP (time sync)**

**Why:** Elasticsearch uses tokens with expiry; time drift can break login or cause cluster errors.

`sudo systemctl enable ntp`

`sudo systemctl start ntp`

`timedatectl status`

Make sure it says NTP synchronized: yes.(if you find some error and this line means just leave that error its due to some depreciated packages)

## **Step 10: Start SonarQube**

Switch to sonar user:

`sudo su - sonar`

Start:

`cd /opt/sonarqube/bin/linux-x86-64`

`./`[`sonar.sh`](http://sonar.sh) `start`

**Check status:**

`./`[`sonar.sh`](http://sonar.sh) `status`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524697313/46f2282d-7cb9-474e-a26b-316ee5c71873.png align="center")

## **Step 11: Access SonarQube UI**

* Open browser:
    

`http://<your-server-ip>:9000`

Default login:

* Username: admin
    
* Password: admin (you’ll be asked to change).
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524764073/13f4dfd4-89b7-4323-b634-0cabaa502887.png align="center")
    
    After Successful Login It prompts you to change the default password, Change it and you are good to go !
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751524930029/53973182-51d0-4ce1-87bc-f049a0e9ea86.png align="center")
