SonarQube is an open-source platform for continuous inspection of code quality. It provides detailed reports on bugs, code smells, and security vulnerabilities in your codebase. In this guide, we will walk you through the installation of SonarQube on Ubuntu 22.04. Whether you are deploying it on a local server or using a Windows VPS UK, this tutorial will cover everything you need to get started.
Step 1: Update Your System
Before installing SonarQube, ensure your system is up to date. Run the following commands:
sudo apt update && sudo apt upgrade -y
Keeping your system updated is crucial for security and performance, whether you're setting up SonarQube locally or on a VPS Windows Servers platform.
Step 2: Install Java
SonarQube requires Java to run. You can install OpenJDK 11 using the following command:
sudo apt install openjdk-11-jdk -y
After the installation, verify the Java installation by checking the version:
java -version
Step 3: Create a SonarQube User
For security reasons, it is recommended to run SonarQube as a dedicated user. Create a user for SonarQube with the following command:
sudo useradd -r -s /bin/false sonarqube
Step 4: Download SonarQube
Navigate to the SonarQube downloads page and copy the link to the latest version of SonarQube. Then, use wget to download it:
cd /opt
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.8.0.zip
After downloading, unzip the package:
sudo unzip sonarqube-9.8.0.zip
Rename the extracted directory for easier access:
sudo mv sonarqube-9.8.0 sonarqube
Step 5: Configure SonarQube
Change the ownership of the SonarQube directory to the sonarqube user:
sudo chown -R sonarqube:sonarqube /opt/sonarqube
Edit the configuration file to set the database connection and other settings. Open the configuration file:
sudo nano /opt/sonarqube/conf/sonar.properties
Uncomment and set the database connection parameters according to your database configuration. For example:
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
sonar.jdbc.username=your_db_username
sonar.jdbc.password=your_db_password
Step 6: Start SonarQube
To start SonarQube, switch to the sonarqube user and execute the startup script:
sudo -u sonarqube /opt/sonarqube/bin/linux-x86-64/sonar.sh start
You can check the logs to see if SonarQube started successfully:
sudo -u sonarqube tail -f /opt/sonarqube/logs/sonar.log
Step 7: Access SonarQube
Open your web browser and navigate to http://your-server-ip:9000
. The default login credentials are:
- Username: admin
- Password: admin
After logging in, you can change the default password and start using SonarQube to monitor your projects.
Step 8: Secure SonarQube with Let's Encrypt SSL
To secure your SonarQube instance, it's advisable to set up SSL using Let's Encrypt. Install Certbot:
sudo apt install certbot -y
Obtain and install the SSL certificate with the following command:
sudo certbot --apache -d your-domain.com
Certbot will automatically configure SSL for your SonarQube instance, ensuring secure access to the platform, whether it is on a local server or hosted on a Windows VPS hosting UK.