sudo apt update
sudo apt install openjdk-17-jre postgresql postgresql-contrib
Download from SonarQube Downloads SonarQube 9.9 LTS:
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.3.79811.zip
unzip sonarqube-9.9.3.79811.zip
sudo mv sonarqube-9.9.3.79811 /opt/sonarqube
Check other versions at Multi Branch Plugin
wget https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/1.14.0/sonarqube-community-branch-plugin-1.14.0.jar
sudo mv sonarqube-community-branch-plugin-1.14.0.jar /opt/sonarqube/extensions/plugins/
sudo adduser sonarqube
sudo chown -R sonarqube:sonarqube /opt/sonarqube
sudo chmod -R 775 /opt/sonarqube
Login to PostgreSQL:
sudo -u postgres psql
Create a new database user (e.g., sonar
):
CREATE USER sonar WITH ENCRYPTED PASSWORD 'your_password';
CREATE DATABASE sonarqube OWNER sonar;
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonar;
\q
Navigate to the SonarQube configuration directory:
cd /opt/sonarqube/conf/
Edit sonar.properties
:
sudo nano sonar.properties
Uncomment and update the PostgreSQL configuration lines:
sonar.jdbc.username=sonar
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
For multi-branch plugin:
sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=web
sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=ce
wget xarp.pt/sonarqube/
Create and edit sonarqube.service
:
sudo nano /etc/systemd/system/sonarqube.service
Add the following configuration:
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
User=sonarqube
Group=sonarqube
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
Restart=on-failure
LimitNOFILE=65536
LimitNPROC=4096
TimeoutStartSec=5min
[Install]
WantedBy=multi-user.target
sudo systemctl start sonarqube
sudo systemctl enable sonarqube
Edit /etc/sysctl.conf
and /etc/security/limits.conf
to set system limits:
sudo nano /etc/sysctl.conf
Add:
vm.max_map_count=262144
Then:
sudo nano /etc/security/limits.conf
Add:
sonarqube - nofile 65536
sonarqube - nproc 4096
Apply changes:
sudo sysctl -p
sudo reboot
Open a browser and navigate to:
http://<your_server_ip>:9000
For SSH tunneling, use:
ssh -L 9000:127.0.0.1:9000 <user>@<your_server_ip>
Then access via:
http://127.0.0.1:9000
When you first access SonarQube, use the default administrator credentials:
Username: admin
Password: admin
Check if it's working on the vm
url http://127.0.0.1:9000
Status:
sudo systemctl status sonarqube
The process above relies on a system service. One option to debug if the service keeps failing on start is to run the process manually:
sudo -u sonarqube /opt/sonarqube/bin/linux-x86-64/sonar.sh console