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.

If you want to know the Jenkins and SonarQube installation process and configuration then refer to my previous blog:

Why SonarQube is important for IT projects ? 

Configure Jenkins for Automated Code Deployment
Install Jenkins on Ubuntu  
Configure SonarQube Scanner with Jenkins

Analyze your project with SonarQube


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


About Author

Anurag Srivastava

Author | Blogger | Tech Lead | Elastic Stack | Innovator |

View Profile

Comments (16)

  • 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
    Ravi Geetha Vandana
    Mar 25, 2019, 1:02:33 PM

    i have an issue with login in sonarquebe could you please help me

  • user image
    Anurag Srivastava
    Mar 25, 2019, 3:30:39 PM

    @Ravi Geetha Vandana: You can ask your query here.

  • user image
    krishna priya
    Mar 28, 2019, 1:30:18 PM

    in my terminal sonarqube was started but using localhost:9000 it is not opening in browser

  • user image
    Anurag Srivastava
    Mar 28, 2019, 3:49:34 PM

    @krishna: Can you check if your 9000 port is available?

  • user image
    Anurag Srivastava
    Mar 28, 2019, 6:31:11 PM

    @krishna: Can you check if your 9000 port is available?

  • user image
    krishna priya
    Mar 29, 2019, 1:27:35 PM

    9000 port is in closed state how to change it's state

  • user image
    Anurag Srivastava
    Mar 29, 2019, 7:37:30 PM

    @Krishna: Try to change the port using sonar.web.port setting in your sonar.properties file. After that restart the sonar service and try to access. Let me know if this works for you.

  • user image
    ravi chandra
    Apr 24, 2019, 7:07:59 AM

    http://localhost:9000 I'm able to access from the terminal, But not able to access from the browser. (http://privateip:9000 not able to access) Please help on it

  • user image
    ravi chandra
    Apr 24, 2019, 7:59:29 AM

    Anurag Srivastava your post helped me a lot thank you I have fixed by restarting sonarqube

  • user image
    Anurag Srivastava
    Apr 24, 2019, 8:02:51 AM

    Ravi: Thanks for the update. Good to know that this blog has helped you to configure SonarQube.

  • user image
    Rajasekhar Reddy
    Aug 28, 2019, 7:21:11 AM

    https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.1.zip When i hit the above URL getting the error message as "Repository path missing or not specified." HTTP request sent, awaiting response... 404 Not Found 2019-08-28 07:19:57 ERROR 404: Not Found. Please help me to get download in ubuntu 16.04

  • user image
    Anurag Srivastava
    Sep 3, 2019, 2:06:36 PM

    Hi Rajasekhar, you can download the latest one from the following link: https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.1.zip

Leave a comment

Related Blogs

Snapshot and Restore Elasticsearch Indices

Sep 16, 2019, 5:55:06 AM | Anurag Srivastava

htop: An Interactive Process Viewer

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

Configure Logstash to push MySQL data into Elasticsearch

Feb 9, 2019, 12:06:18 PM | Anurag Srivastava

Configure Logstash to send MongoDB data into Elasticsearch

Mar 9, 2019, 8:20:38 AM | Anurag Srivastava

How to create Elasticsearch Cluster

Apr 6, 2019, 8:41:41 PM | Anurag Srivastava

Introduction to Elasticsearch

Apr 14, 2018, 1:18:05 PM | Anurag Srivastava

Log analysis with Elastic stack

Jan 31, 2018, 6:11:29 AM | Anurag Srivastava

Load csv Data into Elasticsearch

Feb 9, 2019, 6:34:22 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

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

Why SonarQube is important for IT projects ?

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

Top Blogs

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

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

Elasticsearch Rest API

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava

Analyze your project with SonarQube

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

Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

Install Jenkins on Ubuntu

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