How to Install SonarQube in Ubuntu 20.04 LTS

Introduction

      SonarQube is an open source web based tool to manage code quality and code analysis. It is most widely used in continuous code inspection which performs reviews of code to detect bugs, code smells and vulnerability issues of programming languages such as PHP, C#, JavaScript, C/C++ and Java, also tracks statistics and creates charts that enable developers to quickly identify problems in their code.
 

Prerequisites

  • Ubuntu 20.04 LTS with minimum 2GB RAM and 1 CPU.
  • PostgreSQL Version 9.3 or higher.
  • Apache Tomcat.
  • SSH access with root privileges.
  • Firewall Port: 9000.

Install Java & Configure Java
  • $ sudo apt-get update

  • $ sudo apt install openjdk-11-jdk
    Java Installation

  • $ java -version
    Java Version


  • $ sudo gedit /etc/profile
            Note: add the below 2 line on end of the profile file
      
            export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
            export PATH=$JAVA_HOME/bin:$PATH
JAVA Home


  • $source /etc/profile or source ~/.bashrc
  • $echo $JAVA_HOME
    Bashrc


Configure VM Map count & Security limit

  •  $ sudo sysctl -w vm.max_map_count=262144
  •  $ sudo sysctl -w fs.file-max=65536
    Vm Map

  •  $ sudo vi /etc/security/limits.conf 

         #Add the below line end of the line and save the file.
          sonarqube   -   nofile   65536
          sonarqube   -   nproc    4096



Install and Setup PostgreSQL 10 Database for SonarQube

  • Create the file “/etc/apt/sources.list.d/pgdg.list” and add the corresponding line for the repository in it:

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

  • Import the repository signing key and update the package lists:

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –

  • added the PostgreSQL official repository to our system

                      $ sudo apt-get update

  • To install PostgreSQL on Ubuntu, use the apt-get (or other apt-driving) command:

                     $ sudo apt-get -y install postgresql

Postersql

  •   Update Postgres account Password

                    $ sudo passwd postgres

Postersql Password set


                    $ su – postgres

                

Postgres Login



  • Create a user and database for Sonarqube

            postgres@manikandan-VirtualBox: $ createuser sonar

             postgres@manikandan-VirtualBox:~$ psql

PSQL

 

            postgres=# ALTER USER sonar WITH ENCRYPTED password 'sonar123';

Alter User

 

            postgres=# CREATE DATABASE sonarqube OWNER sonar;

Create DB

           postgres=# grant all privileges on DATABASE sonarqube to sonar;

Grant Access


           postgres=# exit

           postgres@manikandan-VirtualBox:~$ exit

Exit Psql


Install and configure SonarQube

  • $ sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.1.44547.zip
    Download SonarQube

  • $ sudo unzip sonarqube-8.9.1.44547.zip
    unzip sonarqube

  • $ sudo mv sonarqube-8.9.1.44547 /opt
  • $ cd /opt
  • $ cd sonarqube-8.9.1.44547/
    Move Files

  • $ sudo gedit sonar.properties

           Remove the # symbol on the below line in sonar.properties

             sonar.jdbc.username=sonar

             sonar.jdbc.password=sonar123

             sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

             sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError

             sonar.web.host=0.0.0.0

             sonar.web.port=9000

             sonar.web.javaAdditionalOpts=-server

             sonar.path.logs=logs

             sonar.log.level=INFO 

  • $ ./sonarqube-8.9.1.44547/bin/linux-x86-64/sonar.sh status
    Check status

  • $ sudo ./sonarqube-8.9.1.44547/bin/linux-x86-64/sonar.sh start
    Start service

  • Open http://localhost:9000 on web browser

       Note: if the connection not established, check the Apache tomcat running status.

     Default Login:

                UserName : admin

                Password : admin


Portal


PDF for Document available to Download

 

Happy learning and provide the valuable feedback as comments

Comments

Popular posts from this blog

System Administrator

Get Free Microsoft Certification Exams Vouchers