Installing SonarQube on Ubuntu

Prerequisites

Java JRE
DBMS (MySQL in my case)

Create SonarQube database and user

First run MySQL through terminal:

mysql -u root -p

Then create the database and a user:

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;

Download and unzip SonarQube distribution

Visit the SonarQube official site for the current version.

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

unzip sonarqube-5.6.4.zip
mv sonarqube-5.6.4 /opt/sonar

Edit sonar.properties

Open /opt/sonar/conf/sonar.properties with your favourite text editor, and modify it.
MySQL settings
Uncomment the user credentials and the MySQL related settings:

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Web Server settings
The following settings allow you to run the server on page http://localhost:9000/sonar

sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000

Implement SonarQube server as a service [optional]

Copy sonar.sh to etc/init.d/sonar and modify it according to your platform.

sudo cp /opt/sonar/bin/linux-x86-64/sonar.sh /etc/init.d/sonar
sudo gedit /etc/init.d/sonar

Insert two new lines:

SONAR_HOME=/opt/sonar
PLATFORM=linux-x86-64

Modify the following lines:

WRAPPER_CMD="${SONAR_HOME}/bin/${PLATFORM}/wrapper"
WRAPPER_CONF="${SONAR_HOME}/conf/wrapper.conf"
...
PIDDIR="/var/run"

Register as a Linux service:

sudo update-rc.d -f sonar remove
sudo chmod 755 /etc/init.d/sonar
sudo update-rc.d sonar defaults

Create Desktop icons [optional]

Install gnome-panel if missing:

sudo apt-get install gnome-panel --no-install-recommends

Open Dialog for creating new item for starting SonarQube:

sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

Create launcher for starting SonarQube

Copy the item to the Desktop:

sudo cp /usr/share/applications/SonarQube\ Start.desktop /home/user/Desktop/

Open Dialog for creating new item for stopping SonarQube:

sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

Create launcher for stopping SonarQube

Copy the item to the Desktop:

sudo cp /usr/share/applications/SonarQube\ Stop.desktop /home/user/Desktop/

Run SonarQube server

Start SonarQube server either by typing the direct command:

sudo /opt/sonar/bin/linux-x86-64/sonar.sh start

or by typing the service command:

sudo /etc/init.d/sonar start

or by clicking on the SonarQube Start icon which was created before (with password).

Visit SonarQube web page at http://localhost:9000/sonar

Stop SonarQube server either by typing the direct command:

sudo /opt/sonar/bin/linux-x86-64/sonar.sh stop

or by typing the service command:

sudo /etc/init.d/sonar stop

or by clicking on the SonarQube Stop icon which was created before (with password).

REFERENCES

docs.sonarqube.org/display/SONAR/Installing+the+Server
weblogs.java.net/blog/johnsmart/archive/2009/06/installing_sona.html
Giant Geek Blog » Install SonarQube for Continous Inspection

13 thoughts on “Installing SonarQube on Ubuntu”

  1. Hi,

    I have Sonar Server installed on Linux box but I need to do analysis of .NET code available on windows server.

    I am not sure how to approach it.

    Can you please help me with this?

  2. I get the following error when trying to start:

    ~$ sudo /etc/init.d/sonar start
    Starting SonarQube…
    /opt/sonar/bin/linux-x86-64/wrapper: 1: /opt/sonar/bin/linux-x86-64/wrapper: Syntax error: “(” unexpected
    Failed to start SonarQube.

Leave a Reply

Your email address will not be published. Required fields are marked *