SonarQube helps developers write clean and better code. It is an open-source platform used for inspecting and analyzing code for quality and applying security best practices. With this platform, businesses and developers can use it to find and fix bugs in their code, find vulnerabilities and maintain coding standards removing the complexity. Below is how to install and use SonarQube on Ubuntu Linux.

How to install SonarQube on Ubuntu Linux

As mentioned above, SonarQube helps developers write clean and better code. It is an open-source platform used for inspecting and analyzing code for quality and security best practices. Below is how to install it on Ubuntu Linux.

Install OpenJDK

SonarQube is built with Jave and requires its JDK installed. The open-source version should be great to use with it. Below is how to install OpenJDK on Ubuntu. For additional resources on installing OpenJDK on Ubuntu, read the post below. How to install OpenJDK on Ubuntu Linux

Install PostgreSQL

A database server is also required with SonarQube. PostgreSQL is a database server well-suited for SonarQube. Below is how to install PostgreSQL on Ubuntu Linux. Run the commands below to add the PostgreSQL repository GPG key. Next, create a PostgreSQL repository file. Next, update the Ubuntu package index and install PostgreSQL version 13. For additional resources on installing PostgreSQL, read the post below. How to install PostgreSQL on Ubuntu Linux

Create a SonarQube database and user

Now that the database server is installed, let’s go and create a database for SonarQube to use and an account for it. Log on to the PostgreSQL command shell. Create a new database user called sonarqube. Create a new database called sonarqube. Then grant the sonarqube user full access to the sonarqube database. Exit.

Create a SonarQube system account and download

At this point, we’re ready to begin setting up SonarQube. First, create a system account named sonarqube. Install some package dependencies. Download SonarQube version 9.6.1. Unzip the downloaded file, then move the unzipped file to the SonarQube home directory. Make sure sonarqube account is the owner of the content.

Configure SonarQube

With SonarQube content downloaded, go and configure its configuration file. Run the commands below to open its main config file. Make the highlighted lines in the file by adding the database name and account name created above. Also, make sure the server IP and port number are defined. Save the file and exit.

Create SonarQube systemd service

Finally, run the commands below to create a systemd service file for SonarQube. This will help you control SonarQube services. Copy and paste the lines below into the file and save. Reload the systemd daemon, then start and enable the SonarQube service. SonarQube should be started and running.

Access SonarQube portal

Finally, open your web browser, and browse to the server hostname or IP address followed by port number 9000. You should see SonarQube’s default login portal. Login with default admin and admin for both username and password.

Use Reverse proxy with SonarQube

The most effective way to use SonarQube is to set up a reverse proxy. We have written two posts on reverse proxy for both Apache and Nginx. Use the posts below to set up reverse proxy with SonarQube.

How to set up reverse proxy with Apache How to set up reverse proxy with Nginx

That should do it! Conclusion: This post showed you how to install and use SonarQube on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.