Blog Detail

preview image DevOps
by Anurag Srivastava, May 12, 2018, 4:47:07 PM | 4 minutes

SonarQube installation on Ubuntu

If you have not read my previous blog on SonarQube then please click here to access it.

My previous blog: Why SonarQube is important for IT projects ?

In my previous blog on SonarQube, I had explained why it is important for IT projects and what are the benefits of using SonarQube. Now I will explain the installation process of SonarQube on Ubuntu operating system.

System Requirement:

For installing SonarQube we have following prerequisites:

  • Ubuntu operating system (tested on 16.04).
  • 4 GB of RAM.
  • Non-root user with sudo privileges.

Whenever we are going to install any software it is recommended to update the base system with latest version. We can do it by running:

sudo apt-get update
sudo apt-get -y upgrade


Install Java:

Install Java if it is not installed on your machine. To install it we have to run following commands:
Add Oracle Java repository

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

After that we can install Java 8

sudo apt install oracle-java8-installer

We can verify the Java version

java -version


Install MySQL:

We need MySQL setup to run SonarQube. We can install MySQL through following command:

sudo apt install mysql-server mysql-client

Once MySQL is installed successfully we can login to MySQL server:

mysql -u root -p

After logging into MySQL server we need to create the database sonarqube:

create database sonar;

Now as we have installed Java and MySQL and created the sonarqube database, lets install SonarQube.


Install SonarQube:
Download the latest version of SonarQube from their official website:

wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.1.zip

Unzip the downloaded file.

sudo unzip sonarqube-7.1.zip -d /opt

Rename the directory sonarqube-7.1.zip to sonar

cd /opt
sudo mv sonarqube-7.1 sonar

Now we need to edit the SonarQube configuration file.

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

After opening the file make following changes:

sonar.jdbc.username=your_user
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

These are the three main changes which is required in order to connect it through the MySQL database. Save the file and close.


Issue with SonarQube 7.1:

Now we are set with SonarQube installation but there is an issue in version 7.1 as we can not run this with root user and after starting it stops automatically. I have faced the issue and done lot of back and forth to solve the problem and finally got the solution.

We need to create a user and group and then change the installation directory rights.

First of all create a group as sonar

sudo groupadd sonar

Now add the user with directory access

sudo useradd -c "user to run SonarQube" -d /opt/sonar -g sonar sonar 
sudo chown sonar:sonar /opt/sonar -R
Edit the sonar script file and set RUN_AS_USER
sudo vim  /opt/sonar/bin/linux-x86-64/sonar.sh
RUN_AS_USER=sonar

Save and close the file.


Start SonarQube:

Now to start SonarQube we need to do following:
Switch to sonar user

sudo su sonar

Move to the script directory

cd /opt/sonar/bin/linux-x86-64/

Run the script to start SonarQube

./sonar.sh start

We can also add this in service and can run as a service.

Access SonarQube:
You can access the SonarQube by opening the browser and typing:

http://localhost:9000

Please have some patience as it will take 1-2 minute to start so wait and refresh.

So here I have covered the complete process to install SonarQube on Ubuntu operating system. In my next blog I would like to cover the functionality of SonarQube and how can we setup the project and scan them for the analysis.

In case you face any difficulty in installing SonarQube please leave a comment, I will reply.

In my next blog I have explained the project setup with SonarQube. Please click on below link to read the blog:
Analyze your project with SonarQube

In case of any suggestion or query please leave the comment.

About Author

Anurag Srivastava

Author | Blogger | Tech Lead | Data Scientist | Innovator |

View Profile

Comments (5)

  • user image
    Sarita Yadav
    May 12, 2018, 5:24:25 PM

    great

  • user image
    Anurag Srivastava
    May 13, 2018, 1:54:54 PM

    Thanks. :)

  • user image
    Rocky Paul
    May 13, 2018, 5:14:25 PM

    Nice blog.

  • user image
    Anurag Srivastava
    May 15, 2018, 5:21:21 PM

    Thanks :)

  • user image
    jitender yadav
    Jun 19, 2018, 10:54:20 AM

    nice

Leave a comment

Related Blogs

Load csv Data into Elasticsearch

Oct 15, 2018, 6:25:43 PM | Anurag Srivastava

htop: An Interactive Process Viewer

Oct 13, 2018, 8:49:59 PM | Anurag Srivastava

Configure Logstash to push MySQL data into Elasticsearch

Jul 7, 2018, 8:51:30 AM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Build and deploy Angular code using Python

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava

Why SonarQube is important for IT projects ?

Apr 24, 2018, 2:52:28 PM | Anurag Srivastava

Install Kafka on Ubuntu

Jul 12, 2018, 7:40:51 PM | Anurag Srivastava

Analyze your project with SonarQube

Jun 2, 2018, 10:49:54 AM | Anurag Srivastava

Top Blogs

Build and deploy Angular code using Python

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Configure Logstash to push MySQL data into Elasticsearch

Jul 7, 2018, 8:51:30 AM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

SonarQube installation on Ubuntu

May 12, 2018, 4:47:07 PM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Why SonarQube is important for IT projects ?

Apr 24, 2018, 2:52:28 PM | Anurag Srivastava

Install Jenkins on Ubuntu

May 26, 2018, 6:42:02 PM | Anurag Srivastava

Analyze your project with SonarQube

Jun 2, 2018, 10:49:54 AM | Anurag Srivastava

Install Kafka on Ubuntu

Jul 12, 2018, 7:40:51 PM | Anurag Srivastava