
SonarQube is an open-source web-based tool for code quality analysis. It supports analyzing a wide range of programming languages through various plugins. This guide will explains how to install SonarQube on Ubuntu 20.04 LTS to help you identify bugs, vulnerabilities, and code smells in your projects effectively.
Installing OpenJDK 11 is necessary for SonarQube because it serves as the Java Runtime Environment (JRE) required for SonarQube to operate properly.
SSH to your Ubuntu server as a non-root user with sudo access.
Install OpenJDK 11.
Add the PostgreSQL repository.
Add the PostgreSQL signing key.
Install PostgreSQL.
Enable the database server to start automatically on reboot.
Start the database server.
Change the default PostgreSQL password.
Switch to the postgres user.
Create a user named sonar.
Log in to PostgreSQL.
Set a password for the sonar user. Use a strong password in place of my_strong_password.
Create a sonarqube database and set the owner to sonar.
Grant all the privileges on the sonarqube database to the sonar user.
Exit PostgreSQL.
Return to your non-root sudo user account.
Install the zip utility, which is needed to unzip the SonarQube files.
Locate the latest download URL from the SonarQube official download page.
Download the SonarQube distribution files.
Unzip the downloaded file.
Move the unzipped files to /opt/sonarqube directory
Create a dedicated user and group for SonarQube, which can not run as the root user.
Create a sonar group.
Create a sonar user and set /opt/sonarqube as the home directory.
Grant the sonar user access to the /opt/sonarqube directory.
Edit the SonarQube configuration file.
Find the following lines:
Uncomment the lines, and add the database user and password you created in Step 2.
Below those two lines, add the sonar.jdbc.url.
Save and exit the file.
Edit the sonar script file.
About 50 lines down, locate this line:
Uncomment the line and change it to:
Save and exit the file.
Create a systemd service file to start SonarQube at system boot.
Paste the following lines to the file.
Save and exit the file.
Enable the SonarQube service to run at system startup.
Start the SonarQube service.
Check the service status.
SonarQube uses Elasticsearch to store its indices in an MMap FS directory. It requires some changes to the system defaults.
Edit the sysctl configuration file.
Add the following lines.
Save and exit the file.
Reboot the system to apply the changes.
Access SonarQube in a web browser at your server's IP address on port 9000. For example:
Log in with username admin and password admin. SonarQube will prompt you to change your password.
See the SonarQube documentation for more information.
0 Comments
Be the first to comment and share your perspective with the community.