How to Install SonarQube on an AWS EC2 Instance (Step-by-Step Guide)

Sravya BollaSravya Bolla
2 min read

Set up SonarQube 10.4+ on a Ubuntu-based EC2 instance for local code quality analysis and Jenkins integration.

Prerequisites

✅ Ubuntu EC2 instance (t2.medium or higher recommended)
✅ Open ports: 9000 (SonarQube), 22 (SSH)
✅ Java 17+ installed
✅ Internet access on the EC2 instance

Step-by-Step Installation


Step 1: Connect to EC2 Instance

ssh -i <your-key>.pem ubuntu@<your-ec2-public-ip>

Step 2: Install Java (if not already)

sudo apt update
sudo apt install openjdk-17-jdk -y
java -version

Step 3: Create a Dedicated SonarQube User

sudo adduser sonarqube

Follow the prompts and set a password.


Step 4: Create SonarQube Directory

sudo mkdir -p /opt/sonarqube
sudo chown -R sonarqube:sonarqube /opt/sonarqube
sudo chmod -R 775 /opt/sonarqube

Step 5: Switch to SonarQube User & Download SonarQube

su - sonarqube
cd /opt/sonarqube
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.4.1.88267.zip

Step 6: Unzip the SonarQube Archive

unzip sonarqube-10.4.1.88267.zip

If You Get an Unzip Error:

Exit the user and install unzip as root:

exit
sudo apt install unzip -y
su - sonarqube
cd /opt/sonarqube
unzip sonarqube-10.4.1.88267.zip

Step 7: Start SonarQube Server

cd /opt/sonarqube/sonarqube-10.4.1.88267/bin/linux-x86-64
./sonar.sh start

To check the status:

./sonar.sh status

Step 8: Access SonarQube in Your Browser

Open your browser and go to:

http://<your-ec2-public-ip>:9000

Login Credentials:

Username: admin
Password: admin

You’ll be prompted to change the password.


Common Issues & Fixes


Error 1: Directory Not Found

cd: /opt/sonarqube/sonarqube-10.4.1.88267/bin/linux-x86-64: No such file or directory

Fix: You likely didn't unzip the SonarQube file yet. Run:

cd /opt/sonarqube
ls -l
unzip sonarqube-10.4.1.88267.zip
cd /opt/sonarqube/sonarqube-10.4.1.88267/bin/linux-x86-64

Error 2: Java Not Found

Java not found. Please make sure that the environmental variable SONAR_JAVA_PATH points to a Java executable

Fix: Set the Java path for the SonarQube user.


Step 1: Find Java Location

which java

Example output:

/usr/lib/jvm/java-17-openjdk-amd64/bin/java

Step 2: Set Java Path

su - sonarqube
export SONAR_JAVA_PATH=/usr/lib/jvm/java-17-openjdk-amd64/bin/java
cd /opt/sonarqube/sonarqube-10.4.1.88267/bin/linux-x86-64
./sonar.sh start

Make Java Path Permanent

echo 'export SONAR_JAVA_PATH=/usr/lib/jvm/java-17-openjdk-amd64/bin/java' >> ~/.bashrc
source ~/.bashrc

SonarQube Successfully Installed!

You are now running SonarQube on your EC2 instance!

You can:

Perform code quality checks
Run static code analysis
Integrate with Jenkins for CI/CD pipelines


Optional: Clean Up / Uninstall SonarQube

sudo deluser --remove-home sonarqube
sudo rm -rf /opt/sonarqube
0
Subscribe to my newsletter

Read articles from Sravya Bolla directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sravya Bolla
Sravya Bolla