Thursday, April 16, 2020

How to install SonarQube on Ubuntu 16.0.4? Install Sonarqube on Ubuntu

SonarQube is one of the popular static code analysis tool. SonarQube is java based tool along with back end - back end can be MySQL, Oracle or PostgreSQL. We will use Postgres for set up on Ubuntu.
Please find steps for installing SonarQube on Ubuntu EC2. Make sure port 9000 is opened in security group(firewall rule).

Let us start with java install (skip java install if you already have it installed)

1. Java steps 

sudo apt-get update
sudo apt-get install default-jdk -y

Verify Java Version

java -version

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

2. Postgres Installation

sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

sudo wget -q -O - | sudo apt-key add -

sudo apt-get -y install postgresql postgresql-contrib

sudo systemctl start postgresql
sudo systemctl enable postgresql

Login as postgres user now
sudo su - postgres

Now create a user below
createuser sonar

Switch to sql shell by entering

Execute the below three lines (one by one)

ALTER USER sonar WITH ENCRYPTED password 'password';

type exit to come out of postgres user.

3. Now install SonarQube Web App
sudo wget

sudo apt-get -y install unzip
sudo unzip -d /opt

sudo mv /opt/sonarqube-6.4 /opt/sonarqube -v

Modify file
sudo vi /opt/sonarqube/conf/
uncomment the below lines by removing # and add values highlighted yellow

Next, uncomment the below line, removing #

Press escape, and enter :wq! to come out of the above screen.

Create Sonar as a service
Execute the below command:
sudo vi /etc/systemd/system/sonar.service

add the below code in green color:
Description=SonarQube service


inux-x86-64/ start
nux-x86-64/ stop



sudo systemctl enable sonar
sudo systemctl start sonar
sudo systemctl status sonar
type q now to come out of this mode.
Now execute the below command to see if Sonarqube is up and running. This may take a few minutes.

tail -f /opt/sonarqube/logs/sonar.log

Make sure you get the below message that says sonarqube is up..
Now access sonarQube UI by going to browser and enter public dns name with port 9000

Click here to learn how to integrate SonarQube with Jenkins.

Please watch above steps in myYouTube video as well:

1 comment:

  1. Thanks ... quite useful ... Though i can open the sonarqube url , on logging in using sonar , password - authentication fails. please advise