Ask Your Question

How can I install SonarQube on Ubuntu?

asked 2023-10-21 19:36:21 +0000

wagner gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-10-21 19:39:52 +0000

wagner gravatar image

updated 2023-10-21 20:27:29 +0000

Steps - works for Ubuntu 18.04 but also should work for newer Ubuntu Versions:

  1. Initial SonarQube Installation:

    • Downloaded and extracted SonarQube to /opt/sonarqube.
  2. Java Version Correction:

    • SonarQube failed to start due to a Java version mismatch.
    • Installed Java 17 since SonarQube expected it (class file version 61.0 relates to Java 17).
    • Set Java 17 as the default version.
  3. Elasticsearch Root Issue:

    • Elasticsearch, a component of SonarQube, was failing to start because it cannot run as the root user.
  4. User Configuration for SonarQube:

    • Created a dedicated system user named sonar.
    • Changed ownership of the SonarQube installation directory to the sonar user and group.
    • Modified the SonarQube systemd service file to run the service as the sonar user and group.
    • Reloaded systemd to apply the changes to the service file.
  5. Starting SonarQube:

    • Successfully started SonarQube using systemctl start sonar.service.

By addressing the Java version discrepancy and ensuring that Elasticsearch does not run as the root user, SonarQube was able to start up and operate correctly on the system.

  1. Initial SonarQube Installation:

    Assuming you've downloaded and extracted SonarQube:

    wget <SonarQube download link>
    tar -xzvf <SonarQube archive>
    mv <SonarQube extracted folder> /opt/sonarqube
  2. Java Version Correction:

    SonarQube requires Java 17. You installed it and set it as default:

    sudo apt install openjdk-17-jdk
    sudo update-alternatives --config java

    You chose Java 17 from the list to set it as default.

  3. Elasticsearch Root Issue:

    Elasticsearch should not be run as root. This means SonarQube shouldn't be run as root either.

  4. User Configuration for SonarQube:

    • Create a dedicated system user named sonar:

      sudo adduser --system --no-create-home --group sonar
    • Change ownership of the SonarQube directory:

      sudo chown -R sonar:sonar /opt/sonarqube
    • Modify the SonarQube systemd service file:

      Open the file:

      sudo nano /etc/systemd/system/sonar.service

      Add/modify the User and Group directives:

      ```bash [Unit] Description=SonarQube service

[Service] Type=simple User=sonar Group=sonar LimitNOFILE=65536 ExecStart=/opt/sonarqube/bin/linux-x86-64/ console ExecStop=/opt/sonarqube/bin/linux-x86-64/ stop Restart=always


  • Reload systemd:

    bash sudo systemctl daemon-reload

  1. Starting SonarQube:

    sudo systemctl start sonar.service
  2. Access Sonar:

The server will available at localhost, port 9000.

The user/password for the first login admin/admin

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools

1 follower


Asked: 2023-10-21 19:36:21 +0000

Seen: 24 times

Last updated: Oct 21 '23