Skip to content

Instantly share code, notes, and snippets.

@dmancloud
Last active November 12, 2024 05:14
Show Gist options
  • Save dmancloud/0abf6ad0cb16e1bce2e907f457c8fce9 to your computer and use it in GitHub Desktop.
Save dmancloud/0abf6ad0cb16e1bce2e907f457c8fce9 to your computer and use it in GitHub Desktop.
How to Install SonarQube in Linux

How to Install Sonarqube in Ubuntu Linux

Prerequsites

Virtual Machine running Ubuntu 22.04 or newer

Install Postgresql 15

sudo apt update
sudo apt upgrade

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null

sudo apt update
sudo apt-get -y install postgresql postgresql-contrib
sudo systemctl enable postgresql

Create Database for Sonarqube

sudo passwd postgres
su - postgres

createuser sonar
psql 
ALTER USER sonar WITH ENCRYPTED password 'sonar';
CREATE DATABASE sonarqube OWNER sonar;
grant all privileges on DATABASE sonarqube to sonar;
\q

exit

Install Java 17

sudo bash

apt install -y wget apt-transport-https
mkdir -p /etc/apt/keyrings

wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc

echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list

apt update
apt install temurin-17-jdk
update-alternatives --config java
/usr/bin/java --version

exit 

Increase Limits

sudo vim /etc/security/limits.conf

Paste the below values at the bottom of the file

sonarqube   -   nofile   65536
sonarqube   -   nproc    4096
sudo vim /etc/sysctl.conf

Paste the below values at the bottom of the file

vm.max_map_count = 262144

Reboot to set the new limits

sudo reboot

Install Sonarqube

sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip
sudo apt install unzip
sudo unzip sonarqube-9.9.0.65466.zip -d /opt
sudo mv /opt/sonarqube-9.9.0.65466 /opt/sonarqube
sudo groupadd sonar
sudo useradd -c "user to run SonarQube" -d /opt/sonarqube -g sonar sonar
sudo chown sonar:sonar /opt/sonarqube -R

Update Sonarqube properties with DB credentials

sudo vim /opt/sonarqube/conf/sonar.properties

Find and replace the below values, you might need to add the sonar.jdbc.url

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

Create service for Sonarqube

sudo vim /etc/systemd/system/sonar.service

Paste the below into the file

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=forking

ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop

User=sonar
Group=sonar
Restart=always

LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target

Start Sonarqube and Enable service

sudo systemctl start sonar
sudo systemctl enable sonar
sudo systemctl status sonar
sudo tail -f /opt/sonarqube/logs/sonar.log

Access the Sonarqube UI

http://<IP>:9000
@Imanelo
Copy link

Imanelo commented Aug 14, 2023

Thank you , it was clear :)

@ZouhairCharef
Copy link

thanks a lot

@oriolakolawole
Copy link

thanks a lot

@huornlmj
Copy link

You should create the database and user with the following command instead:

$ sudo -u postgres psql

@kambogi
Copy link

kambogi commented Feb 6, 2024

Thank you!

@ligiasalzano
Copy link

Thanks a lot!

@SrKocmoc
Copy link

Very nice bro! Tks♥

@KryCool
Copy link

KryCool commented Feb 26, 2024

Thank you so much

@HammerHam
Copy link

Thank you

@poojagopal1988
Copy link

I have jdk11 and jdk17 on my RHEL8 server. How do I force sonarqube 9.9 to use jdk17? Without changing java version what system is pointing to?

@Harvesh045
Copy link

authentication failed while login

@geersann
Copy link

Thanks a lot mate!

@Rahul7600
Copy link

thank you so much

@Ishfak00
Copy link

Works perfectly. hope newer version also !

@Sumit01kr
Copy link

Thank you so much

@Fokines
Copy link

Fokines commented Jun 21, 2024

amazing! thanks

@Zoo30
Copy link

Zoo30 commented Jul 14, 2024

authentificator failed

@Zoo30
Copy link

Zoo30 commented Jul 14, 2024

please whto is the login and password

@Rahul7600
Copy link

By Default password Sonarqube
username - admin
Password - admin

@Zoo30
Copy link

Zoo30 commented Jul 14, 2024

By Default password Sonarqube username - admin Password - admin

thank you

@rajithrajsl
Copy link

superb...its worked

@Seun-Github
Copy link

Great Stuff.... Brief and apt. thanks

@DarrylNnon
Copy link

big thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment