Sonarqube
Here are the steps to install SonarQube Community Edition on Ubuntu 22.04 with Nginx:
Step 1: Install Java
SonarQube runs on Java, so first, you need to install Java. You can use either OpenJDK or Oracle JDK.
Install OpenJDK 11 with the following commands:
sudo apt update
sudo apt install openjdk-17-jre -y
Step 2: Install PostgreSQL
SonarQube requires a database to store its data. In this guide, I'm using PostgreSQL. You can install PostgreSQL with these commands:
sudo apt install postgresql postgresql-contrib -y
Then, start the PostgreSQL service and set a password for the postgres
account:
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo -u postgres psql
Inside the psql session, set a password for the postgres
account:
ALTER USER postgres PASSWORD 'your_password';
\q
Step 3: Create a SonarQube Database
After setting up PostgreSQL, create a new database for SonarQube:
sudo -u postgres createdb sonarqube
Step 4: Download and Install SonarQube
Download and unzip SonarQube:
Link: https://www.sonarsource.com/products/sonarqube/downloads
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.2.1.78527.zip
unzip sonarqube-10.2.1.78527.zip
sudo mv sonarqube-10.2.1.78527 /opt/sonarqube
Step 5: Configure SonarQube
Open the SonarQube configuration file:
sudo nano /opt/sonarqube/conf/sonar.properties
Edit the following settings in the configuration file:
sonar.jdbc.username=postgres
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
sonar.javaHome=/usr/lib/jvm/java-17-openjdk-amd64
sonar.path.data=/var/sonarqube/data
sonar.path.temp=/var/sonarqube/temp
Step 6: Install and Configure Nginx
Install Nginx:
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl enable nginx
Create a Nginx configuration file for SonarQube:
sudo nano /etc/nginx/conf.d/sonarqube.conf
Insert the following content into the configuration file:
server {
listen 80;
server_name your_domain_or_server_ip;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:9000;
}
error_page 502 /502.html;
location = /502.html {
root /var/www/html;
}
}
Activate the configuration and restart Nginx:
sudo nginx -t
sudo systemctl restart nginx
Step 7: Start SonarQube
Start the SonarQube service:
sudo /opt/sonarqube/bin/linux-x86-64/sonar.sh start
Access SonarQube via a web browser by visiting http://your_domain_or_server_ip
. Log in with the default admin account (admin/admin) and then you can change the password.
Congratulations, you have successfully installed and configured SonarQube on Ubuntu 22.04 with Nginx.
Last updated
Was this helpful?